There is a new version of this tutorial available for Ubuntu 22.04 (Jammy Jellyfish).

Installing Laravel PHP Framework on Ubuntu 18.04 LTS for Apache

Laravel is a very popular open-source PHP framework aimed at easy development of applications. If you are looking for a new PHP framework to try, you should give Laravel a try.

The following guide will show you how to install and run Laravel on an Ubuntu 18.04 LTS based Apache server. This tutorial works for Ubuntu 17.x as well. But for servers, you should prefer to use an Ubuntu LTS release like the current Ubuntu 18.04 LTS.


Before proceeding with the installation, it's always a good idea to make sure your sources and existing software are updated. 

sudo apt-get update 
sudo apt-get upgrade

For this guide, we will assume that you have a basic server based on Ubuntu running. Before Laravel, we need to install other components that are essential.

Installing Apache and PHP 7.2

Next step is to install PHP along with several extra packages that would prove useful if you are going to work with Laravel. 

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install apache2 libapache2-mod-php7.2 php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring

Even though Ubuntu's own repository has PHP, it's better to add a 3rd party repository here because it gets more frequently updated. You can skip that step and stick to Ubuntu's version if that's what you prefer.

Installing Laravel

Before we finally delve into it, we also need Git version control to be installed. If you have it installed, you can skip the following step. If you don't have, then you can follow our guide to set it up first.

To install Laravel, we need to install Composer first. It is a tool for dependency management in PHP that allows you to package all the required libraries associated with a package as one. To install Laravel and all its dependencies, Composer is required. It will download and install everything that is required to run the Laravel framework. To install Composer, issue the following commands.

cd /tmp
curl -sS | php
sudo mv composer.phar /usr/local/bin/composer

The curl command downloads composer.phar package to your /tmp directory. But we would want composer to run globally hence we need to move it to /usr/local/bin/ directory under the name 'composer'. Now we can run composer from anywhere.

To install Laravel, move to the public html directory on your system. Since we are on Ubuntu and using Apache, we will install it in the /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 write permissions to the storage directory.

sudo chgrp -R www-data /var/www/html/your-project
sudo chmod -R 775 /var/www/html/your-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. Replace yourdomain.tld with the domain name of your website inside the file.

<VirtualHost *:80>
    ServerName yourdomain.tld

    ServerAdmin [email protected]
    DocumentRoot /var/www/html/your-project/public

    <Directory /var/www/html/your-project>
        AllowOverride All

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

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

Your Laravel installation is now complete. Visit the IP address or domain name of your server with a web browser (in my case You will see the Laravel default page.

Laravel installed on Ubuntu 18.04 LTS

Laravel Framework successfully installed on Ubuntu 18.04 LTS.

Virtual machine download of this tutorial

This tutorial is available as ready to use virtual machine image in ovf/ova format that is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:

SSH / Shell Login

Username: administrator
Password: howtoforge

To become root user, run: sudo -s
Password: howtoforge

The IP of the VM is, it can be changed in the file /etc/netplan/01-netcfg.yaml. Please change all the above passwords to secure the virtual machine. 

Share this page:

31 Comment(s)

Add comment

Please register in our forum first to comment.


By: Markus

But you know that composer and PHP7.2 is in Ubuntu 18.04? And PHP packages are considered as especially important in terms of security and get updated often?

Ondrej Repository was important for 16.04 because there were so much changes, but 18.04 is fine.

By: Joao

where is the blink to download the ova file?

By: till

In the menu at the right side of the page, near the top, right below the big red download icon.

By: Abdou DIOUCK

How to deploy laravel in vps with ispconfig



By: Michael William


I followed the step you stage out to the end including "Configuring Apache", I did not want the result came out.. I know that that "Configuring Apache" step is to write permissions and give access to www-data group... My problem is I did not want to give access to www-data group and how can I go back to default setting......


By: Luke

You just need too change the user and folder permissions back to what it was before.

Check out this thread.

By: Rajan

Last Task:

systemctl reload apache2


By: hakim

 How to know your IP address and paste in the browser?

By: Oluwadamilare

I had to run `Chmod -r 777` on my storage folder to get the permission error out of the way

By: David G

The instructions were spot on with the exception of having to add the zip package with apt-get.  After wasting a lot of time trying to install it on the AWS dist I ended up finding an AMI images with AWS image locator and created and Ubuntu server 18.04 and then simply followed these instructions.  Thanks so much.

By: Mark Shook

"sudo composer create-project laravel/laravel your-project --prefer-dist"


When I run this I get the following message:


"Do not run Composer as root/super user! See for details"

By: Tobias

followed this tutorial, but its not working :(

By: till

The installation worked fine for me. Which error did you get? If you don't post your error message, then we can't help you to solve the problem on your system.

By: Jake

Worked perfectly. Thank you very much.

By: Chris

My browser wont connect to the URL? It recognises its a URL but wont load :(

By: rainbow

I have closely readen this tutorial.

I am very happy.

It is correct solution.


By: jukk

Thanks, worked nicely! 

By: Awby

Thank you my dude

By: ed

I'd like to download the VM you reference, but I don't see it anywhere on your page. (??)

By: till

The link is below the big red download icon in the navigation bar on the right side. If you don't see it, turn off the ad blocker. Some ad blockers remove the whole right menu bar on howtoforge.

By: Mischa

This was by far the best documentation of SOMETHING I've ever read. Thanks man, worked perfectly!

By: Jesus Erwin Suarez

I write this because I want to give thanks! This article really helps me to solve the proble. Thanks a lot! 




By: Robert Phillips-Legge

I've downloaded your OVA file for this. Everything is going fine right up to the point where I find MySQL isn't on the build. Do you use a different database? If not do you think you could include it in a future version? or os there another OVA that includes LAMP and Laravel?


By: till

The VM image contains the content of the above tutorial and this does not install MySQL or MariaDB, that#s why MySQL is not installed. You can install MariaDB /which is commonly used as MySQL compatible database) easily with these commands in the vm:


apt-get install mariadb-server mariadb-client

By: Kay

Hi, i can`t restart the apache2 server. The Terminal gives me the follwing message: [....] Starting apache2 (via systemctl): apache2.serviceJob for apache2.service failed becaues the control process exited with error code.

See "systemctl status apache2.service" and "journalctl -xe" for details.

Whats wrong?

By: Kay

@Edit - you can delete OR post the last comment with this solution:

i had to correct the laravel.conf file in /etc/apache2/sites-enabled - because when you modified the normal laravel.conf that is NOT the file in this /etc/apache2/sites-enabled/ folder ;)

 now i can restart the apache2 server :D

Thank you for your great tutorial !

By: Doks

This is totally a life saver guide...thank you so much!

It works on my Ubuntu-bionic using VM.  on my windows10.


By: shiro

run composer with 'sudo'? really?

By: mk

Thanks for the tutorial. It's working as expected for me. Now my question, how do I use a windows editor to work on my laravel project. Do i need to share that project with Windows? If so, how please?

Thanks in advance for any feedback

By: mikia

I need this manual too. Do you found it?

By: hassan

thanks for shareing this  artical