Installing Laravel PHP Framework on Ubuntu 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 allow you to run Laravel on a Ubuntu 15.10 based Apache server. 


Before proceeding with the installation, its always a good idea to make sure your sources and existing softwares are all 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 PHP5

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

sudo add-apt-respository ppa:ondrej/php5
sudo apt-get update
sudo apt-get install php5 php5-mcrypt php5-gd
sudo php5enmod mcrypt

Even though Ubuntu's own repository has PHP, its 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 Apache

Its time to install Apache server now. We would also need to install libapache2-mod-php5 package to hook up Apache with PHP.

sudo apt-get install apache2 libapache2-mod-php5

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 Laravel framework. To install Composer, issue the following commands.

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

First command downloads composer.phar package to your 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 would install it in /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 writing permissions to the storage directory.

sudo chgrp -R www-data /var/www/html/project
sudo chmod -R 775 /var/www/html/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.

<VirtualHost *:80>
    ServerName localhost

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

    <Directory /var/www/html/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 http://serverip or http://localhost to access your Laravel installation. If successful you should see the following screen.

Share this page:

21 Comment(s)

Add comment


From: Danny at: 2016-03-28 16:44:08

You got me with this:

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

So after we have to do:

sudo chgrp -R www-data /var/www/html/your-projectsudo chmod -R 775 /var/www/html/your-project/storage

(where is your-project is some project name)

Also here:

<VirtualHost *:80>    ServerName localhost    ServerAdmin [email protected]  DocumentRoot /var/www/html/your-project/public    <Directory /var/www/html/your-project>        AllowOverride All    </Directory>    ErrorLog ${APACHE_LOG_DIR}/error.log    CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>Because project will never start...But any way, thank you guys for great tutorial ;)

From: Áquila Freitas at: 2016-04-20 23:26:22

Best tutorial so far. Congrats!

From: jinngala at: 2016-04-24 04:09:41

very useful. Thanks.

From: Pytho* at: 2016-04-27 11:42:25

 Best explanation I've ever encountered! Thnx,

From: ahmed at: 2016-05-13 08:58:05

thanks , very simple and useful.

From: kamboj at: 2016-06-09 20:01:03

perfect!!! everything has been in order !!! thanks

i've been trying to install for last 2 days. 

From: Dakota at: 2016-06-19 04:43:59

This is the only tutorial I've been able to use to install laravel succcessfully. Thanks a lot!

From: vishnu at: 2016-07-11 07:31:49

Very usefull...Thanks

From: Andrew Pearson at: 2016-07-16 21:51:59

Your configure apache section worked perfectly to solve my problem.

From: Nkeng Newton at: 2016-07-16 23:48:57

Everything worked like cham!!. Great post and Thanks

From: Sooraj Kv at: 2016-08-22 07:47:08

Awesome tutorial

From: anna at: 2016-08-24 03:09:18

after running

sudo apt-get install apache2 libapache2-mod-php5

this shows up:

The following packages have unmet dependencies:

libapache2-mod-php5: Depends: apache2-api-20120211 but it is not installable

Depends: apache2(>= 2.4)

E: Unable to correct problems, you have held broken packages.

I really dont know how to move forward from this

From: till at: 2016-08-24 06:27:03



apt-get update


and then try the failed command again.

From: Nuno Coelho at: 2016-08-31 20:38:00

 hi people,

after i follow this tutorial, in the end give me on error

 * Restarting web server apache2                                         [fail]  * The apache2 configtest failed.Output of config test was:AH00526: Syntax error on line 2 of /etc/apache2/sites-enabled/laravel.conf:Invalid command '\xc2\xa0\xc2\xa0', perhaps misspelled or defined by a module not included in the server configurationAction 'configtest' failed.

i do this

sudo chgrp -R www-data /var/www/html/extremesudo chmod -R 775 /var/www/html/extreme/storage


this is i have in laravel.conf

<VirtualHost *:80>     ServerName localhost     ServerAdmin [email protected]     DocumentRoot /var/www/html/extreme/public     <Directory /var/www/html/extreme>         AllowOverride All     </Directory>     ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>



what i do wrong?

From: MaxDp at: 2016-09-10 14:46:13

Really clear and detailed instructions.Can't thank you enough ! :D

From: Bill at: 2016-09-17 23:46:09

Followed all instructions but hit one problem at the end. /localhost/index creates a Laravel routes error but /localhost/index.php runs fine.

I'm running Ubuntu 16.04 LTS and php7. Laravel version is 5.3.9.

The biggest problems with Laravel are the subtle changes from release to release which means each release requires a different installation stragety. :/

From: Federico at: 2016-09-18 13:24:33

Best tutorial. It works like a charm!

From: Vincent at: 2016-09-29 09:05:36

Hi! I have tried to install the laravel..but when I type this command "sudo composer create-project laravel/laravel your-project --prefer-dist" I get the following error:  [Composer\Downloader\TransportException]                                       The "" file could not be downloaded: fai    led to open stream: Connection timed out    ......Somebody help...I will so much appreciate thanks

From: dharsan at: 2016-09-29 15:32:00

How to install laravel 5.3 on ubuntu ?

From: Ahmed Aatef at: 2016-10-08 19:02:12

Thank you!

From: BluePen Labs at: 2016-10-26 12:39:59

Versions of php and Apache are no more supported in Ubuntu.

Solution : 

sudo apt install apache2 php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext