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:

Suggested articles

31 Comment(s)

Add comment


From: Danny

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

Best tutorial so far. Congrats!

From: jinngala

very useful. Thanks.

From: Pytho*

 Best explanation I've ever encountered! Thnx,

From: ahmed

thanks , very simple and useful.

From: kamboj

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

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

From: Dakota

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

From: vishnu

Very usefull...Thanks

From: Andrew Pearson

Your configure apache section worked perfectly to solve my problem.

From: Nkeng Newton

Everything worked like cham!!. Great post and Thanks

From: Sooraj Kv

Awesome tutorial

From: anna

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



apt-get update


and then try the failed command again.

From: Nuno Coelho

 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

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

From: Bill

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

Best tutorial. It works like a charm!

From: Vincent

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

How to install laravel 5.3 on ubuntu ?

From: Ahmed Aatef

Thank you!

From: BluePen Labs

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

From: mayank

 I got all the things done accordding to this tutorial and without any error but going to localhost, it shows completely blank screen. so, i don't know whether laravel is working fine or not.

I  am new to laravel. Can anyone suggest me what to do?

Any help will be highly apprecciated.

From: Raj

How can I run two websites (main domain website in HTML, ). How can I make sure that both websites are running after disabling default config? How to take care of that?

Thanks in advance!

From: Bishwarup

Step: 'composer install' is missing

From: Bachi

Thank you. Worked like a charm

From: Apadana

sudo add-apt-respository ppa:ondrej/php5  ---> sudo add-apt-repository ppa:ondrej/php5

From: ali

after run :

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


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

what could go wrong ?



From: Vikas Sharma

sudo add-apt-repository ppa:ondrej/php5'This PPA does not support trusty'Cannot add PPA: ''This PPA does not support trusty''.

Please help me..


From: Ludhiana

how to restart server after closing system and using that again.

From: Dmitriy

Thanks! This works great! :)

From: Alfredo

Thanks, this tutorial really works.