Install Laravel on Ubuntu, Lubuntu, & Elementary OS
- Article
- Comment
Install Laravel on Ubuntu, Lubuntu, Kubuntu and Elementary OS (Luna, Freya, Loki). Installing Laravel 5 needs php 5. 6. If your php is more than 5. 6 no problem. Otherwise you have to upgrade your php with help of this tutorial. And you need Composer to install it. If you already installed composer than no problem. And If you want to install Composer click here to read about it.
Now with the help of Composer we can install laravel. You need active internet connection as well. To install Laravel, move to the public html directory on your system. Since we are on Ubuntu and using Apache, we would install it in /var/www/html
directory.
cd /var/www/html sudo composer create-project laravel/laravel your-project --prefer-dist
The above command will create a your-project directory with laravel installation in it. Composer uses git to download and install all the packages and modules that Laravel requires for functioning.
Configuring Apache
Now that we have installed Laravel, we move on to the step of configuring Apache webserver. Next step is to give proper permissions to the project directory. For this we need to enable access to it from the www-data group and to give it writing permissions to the storage directory.
sudo chgrp -R www-data /var/www/html/project sudo chmod -R 775 /var/www/html/project/storage
Now go to the /etc/apache2/sites-available
directory and use the following command to create a configuration file for our laravel install.
cd /etc/apache2/sites-available sudo nano laravel.conf
Now add the following content to the file and close it after saving.
<VirtualHost *:80> ServerName localhost ServerAdmin webmaster@localhost DocumentRoot /var/www/html/project/public <Directory /var/www/html/project> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Now we have to enable this newly created .conf file and disable the default .conf file that is installed with the default Apache install. Also we need to enable mod_rewrite so that permalinks can function properly.
sudo a2dissite 000-default.conf sudo a2ensite laravel.conf sudo a2enmod rewrite sudo service apache2 restart
After restarting Apache, It will work fine. If you like my tutorials, follow me on social medias below.