Install Laravel PHP Framework on Ubuntu 16.04 | 17.10 | 18.04 with Apache2 and PHP 7.2 Support

Laravel is a flexible opensource PHP framework for web artisans. It can be used as an alternative to CodeIgniter framework. Laravel is designed for ease of use to allow developers create great applications.

If you’re looking for a simple and straightforward PHP framework to design your next application, you’ll find Laravel to be useful. This brief tutorial is going to show students and new users how to install Laravel PHP framework on Ubuntu 16.04 | 17.10 | 18.04 with Apache2 and PHP 7.2 support.

To get started with installing Laravel, follow the steps below:

Step 1: Install Apache2

For this tutorial, we’re going to be installing Apache2 web server. to do that, run the commands below.l

sudo apt update
sudo apt install apache2

After installing, the commads below can be used to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 2: Install PHP 7.2 and Related Modules

Laravel is based on PHP. so you’ll need to install it. To install PHP and related modules run the commands below

sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip

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

sudo nano /etc/php/7.2/apache2/php.ini

Then make the change the following lines below in the file and save.

memory_limit = 256M
upload_max_filesize = 64M

Step 3: Install Composer to Download Laravel

Run the commands below to install composer package and install. you must have curl package installed for the commands to work. if not, just run sudo apt install curl to install it.

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

Change into Laravel directory and run the commands below to download and install Laravel for th e project you want to create. name the project whatever you want. for this post, we’re calling it MyProject.

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

After running the commands above, a new project directory will be created. Run the commands below to set the correct permissions for that directory.

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

Step 5: Configure Apache2

Finally, configure Apahce2 site configuration file for Laravel. This file will control how users access Laravel content. Run the commands below to create a new configuration file called laravel.conf

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

Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.

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

     <Directory /var/www/html/MyProject/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.

Step 5: Enable the Laravel and Rewrite Module

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

sudo a2ensite laravel.conf
sudo a2enmod rewrite

Step 6: Restart Apache2

To load all the settings above, restart Apache2 by running the commands below.

sudo systemctl restart apache2.service

Then open your browser and browse to the server domain name. You should see Laravel page.

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

laravel ubuntu install

That’s it!

You may also like the post below:


  1. Good day, I tried these steps but somehow I’m unable to properly access my laravel. I have used these additional steps:
    1. In step 5 I added ‘sudo composer install’ followed by ‘sudo php artisan key:generate’.
    2. I modified config/app.php and added the the key generated above to ‘key’ => env(”).
    3. Refreshed the site and it’s working.

    1. ‘key’ => env(‘APP_KEY’, ‘key_generated’)

  2. Great article

  3. You are the one I find a long time 😀
    You are perfectly !! So thanks a lot.

  4. Save my life! Thanks

  5. How do I find the domain name and directory root location for a local Ubuntu server? Your article says, “Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.”

  6. Nice tutorial for install laravel on ubuntu

  7. Just a small thing that someone might need. You should also not forget to add in /etc/hosts this new site e.g

    1. My install wouldn’t show until I followed Valdimir’s note about adding the url to the /etc/hosts file…. Now it works well.

      Great article, btw!

    2. Exactly!

  8. Francisco Salas

    excellent!! go on that it!

  9. Great article, definitely got me most of the way. One small thing I needed to do was
    In Step 5: Enable the Laravel Rewrite Module I had to add
    sudo a2dissite 000-default.conf

  10. The above example not working .here It will show error

  11. Mwalima Peltenburg


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.