Install Laravel PHP Framework on Ubuntu 18.04 LTS

Install Laravel In Ubuntu Operating System

Tutorial: Install Laravel PHP Framework on Ubuntu 18.04 LTS

Laravel is one of the very popular open source PHP framework. It is one of the mostly used framework these days. In this tutorial post, we will show you the step by step process to install  and run Laravel on Ubuntu 18.04 LTS. We will be using Apache in these Laravel guide tutorial.

Install Laravel PHP Framework on Ubuntu 18.04 LTS

Let’s jump into the installation procedure. Meanwhile, there are various modules or application that you need to install before running or installing Laravel framework in your system.

Step 1: Install Apache Webserver

Laravel  or any other framework requires a webserver to run. In this tutorial, we will be installing laravel using Apache webserver. Hence, run the following command in your terminal to install Apache2 on Ubuntu:
sudo apt install apache2
Laravel is based on PHP. so you need to install it. To install PHP, run the commands below:

sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip 

After install PHP, run the commands below to open PHP-FPM default file.

sudo nano /etc/php/7.1/apache2/php.ini           # Ubuntu 17.10
sudo nano /etc/php/7.0/apache2/php.ini           # Ubuntu 17.04

Step 4: Install Composer to Download Laravel

Run the commands below to install composer package and install. Before installing Composer you must have curl package installed in your system.

Install Curl with command below:
sudo apt install curl

Now, Install composer:

curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

Move to the directory where you want to install Laravel and run the commands below to download and install Laravel. You need to name the project name too. For example Myunowp

cd /var/www/html sudo composer create-project laravel/laravel Myunowp --prefer-dist 

Now, its time for some permission work. Run the commands below to set the required permissions for that directory.

sudo chown -R www-data:www-data /var/www/html/Myunowp/ sudo chmod -R 755 /var/www/html/Myunowp/

Now Configure Apache webserver

You need to configure Apahce webserver for Laravel. Run the commands below to create a new file called laravel.conf.

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

You need to copy and paste the following content into the laravel.conf file and save it.

Note: Replace the highlighted line (red colored) with your own domain name.

<VirtualHost *:80>   
     DocumentRoot /var/www/html/Myunowp/public

     <Directory /var/www/html/Myunowp/public>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

Save the file and exit.

 Now, It’s time to enable the rewrite module and laravel.

Run the commands below:

sudo a2ensite laravel.conf
sudo a2enmod rewrite

Before working on Laravel, you need to restart  the Apache webserver:

sudo systemctl restart apache2.service

Open your regular browser and run the domain name which you have mentioned above

You will see the default laravel home page.

Leave a Reply

Notify of

You may also like