How To Install And Configure Laravel On Ubuntu

Laravel is a PHP web application framework with expressive, elegant syntax.  It is designed for the faster development of MVC web applications in PHP. In this article, we will install laravel 5 php framework on Ubuntu 19.04, 18.04 LTS, 16.04 LTS, 14.04 LTS operating systems. Please follow the steps below.

you will need to make sure your server meets the following requirements:

  • PHP >= 7.1.3
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Step 1 – Install LAMP :

Skip this step if LAMP is already installed. Otherwise , setup it using below Link https://linuxworld.info/how-to-install-apache2-mysql-php-stack-on-ubuntu-18-04-step-by-step/

Step 2 – Install Composer

Skip this step if composer is already installed. Otherwise , setup it using below Link https://linuxworld.info/how-to-install-composer-on-ubuntu-step-by-step/

Step 3  — Install Laravel

  We need to install latest version of Laravel from the official git repository.

Command :

 

$ cd /var/www

$ git clone https://github.com/laravel/laravel.git
$ cd /var/www/laravel
$ sudo composer install

 

 

 

It may take some time to install dependencies. After above command completion we set the permissions on below files.

 

$ sudo chown -R www-data.www-data /var/www/laravel
$ sudo chmod -R 755 /var/www/laravel
$ sudo chmod -R 777 /var/www/laravel/storage

 

 

 

Step 4 –  Encryption key setup :

                        Rename the file .env.example to .env  in the project main directory.

Command :

 

  • $ mv .env.example .env

     

 

 Now we generate base64 random number encryption key, which used by the Illuminate encrypter service.

Command :

$ sudo php artisan key:generate

 

 

 

Application key set successfully.

make sure APP_KEY is properly set as generated in above command. To check this open .env file and see the app key as below :

APP_KEY=base64:HFdS7c9rhDp+AeHu7kc2OLBPuxHqq2BQ/1gfFWEpoAk=

It may be different in your machine.

Step 5 – Create Database for Laravel

You need to have database to connect with your Laravel application. So we create a MySQL database and user.

Command:

mysql> CREATE DATABASE laravel;
mysql> GRANT ALL ON laravel.* to 'laravel'@'localhost' IDENTIFIED BY 'linuxworld';
mysql> FLUSH PRIVILEGES;
mysql> quit 

Now edit the .env file and update database settings.

                                                    .env

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=laravel 
DB_USERNAME=laravel 
DB_PASSWORD=linuxworld

Step 6 – Apache Configuration

Finally, configure Apahce2 site configuration file for Laravel application. Run the commands below to create a new configuration file called laravel.conf and open using this command

$sudo nano /etc/apache2/sites-available/laravel.conf

Then copy and paste the content below into the file and save it.

                       /etc/apache2/sites-available/laravel.conf

 <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName example.com
        DocumentRoot /var/www/laravel/public
       <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>
       ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the file and exit

Step 6: Enable the Laravel and Rewrite Module

After configuring the VirtualHost above, enable it by running the commands below :

Command :

$ sudo a2ensite laravel.conf
$ sudo a2enmod rewrite

Reload Apache configuration changes by restarting service using below command

$ sudo service apache2 restart

Step 7 – Access Laravel Application

Congrats, Now LARAVEL 5 PHP framework has been configured on your system. Open the URL example.com in your favourite browser. You will get  laravel default page on the browser.

Laravel

 

All Done Enjoy 🙂

 

 

2 thoughts on “How To Install And Configure Laravel On Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *