We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

Install Laravel on Ubuntu 16.04 With Apache2

Laravel is the most popular and open-source PHP framework used across the world to build web applications ranging from small apps to enormous projects. Laravel follows an MVC (Model View Controller) structure, making it easier to understand and rapidly prototype web applications. Laravel provides built-in features like template-engine, Eloquent ORM, Security, Libraries & Modulars, Authentication, Mail, Routing, Sessions, etc, which enable the developer to work very quickly and easily.

In this blog, I’ll explain to you step by step how you can install Laravel 6.x on Ubuntu 16.04 or a larger version with apache2.

Server Prerequisites:
  • PHP >= 7.2.0 Or Greater
  • Apache Webserver.
  • PHP Extensions - OpenSSL, BCMath, PDO, Mbstring, Tokenizer, XML, Ctype and JSON.
  • Composer – an application-level package manager for the PHP.
Step 1 - Install PHP 7.2:

Run the following command to install PHP and all required PHP Extensions:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip php7.2-json php7.2-tokenizer
Step 2 -Install Composer:

Laravel uses composer to manage dependencies, Follow the below steps to install composer on your machine.

sudo apt-get install curl
sudo apt-get update
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

After Installing the composer can run composer from anywhere.

Step 3 - Install Apache:

If you do not already have Apache installed, you can do so now by issuing the following command in your terminal:

sudo apt-get install apache2 libapache2-mod-php7.2
Step 4 - Install Laravel:

You can install Laravel by issuing the Composer create-project commands in your terminal:

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

After running the commands above, the output will be displayed…Now run the commands below to set the correct permissions for that project directory.

sudo chown -R www-data:www-data /var/www/html/DemoProject/
sudo chmod -R 755 /var/www/html/DemoProject/
Step 5 - Configure Apache Virtual Hosts:

Finally, configure the Apahce2 site file for Laravel. This file will control how you can access your website content. Run the commands below to create a new configuration file called demo.mylaravel.com.conf

cd /etc/apache2/sites-available
sudo nano demo.mylaravel.com.conf

Now you can add the bellow content into the created file and save the file. Replace the highlighted data with your server admin and directory root location.

<VirtualHost *:80>
  ServerAdmin [email protected]
     DocumentRoot /var/www/html/DemoProject/public
     ServerName demo.mylaravel.com
     <Directory /var/www/html/DemoProject/public>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

Now we have to enable this newly created demo.mylaravel.com.conf file. Also, we need to enable the mod_rewrite module of apache.

sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart

Now browse to the URL. You will see the Laravel page as the below screenshot.


You should then see the Laravel default home screen, and you’re ready to begin building your apps based on the Laravel.

Take a sip of your coffee and stay tuned for more blogs like this!!!

contact-us Request a callback WhatsApp