How to install Laravel on Ubuntu

1. Install curl if not already installed

sudo apt-get install curl

2. install composer if not already installed

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

3. Now run blow command to install laravel

composer global require "laravel/installer=~1.1"

4. Add laravel to PATH to make it available everywhere

export PATH="~/.composer/vendor/bin:$PATH"

5. Create your Laravel app

Now that Laravel is added to path, now all sudoers can create laravel apps using below command

laravel new app-name

if you are not a sudoer, above command will show below error

laravel: command not found

You can create a link in /usr/local/bin to solve this problem

sudo ln -s /root/.composer/vendor/bin/laravel /usr/local/bin/laravel

Now non sudoers can create laravel apps like

sudo laravel new app-name

6.Install mod_rewrite if not already installed

sudo a2enmod rewrite
service apache2 restart

You can confirm if its enabled using below command

sudo apache2ctl -M

if you created your app inside web server root directory (/var/www/html/) then you can access it like


Creating VHOST for Laravel application

1. Create vhost file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
sudo nano /etc/apache2/sites-available/

The file will look something like this (I’ve removed the comments here to make the file more approachable):

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

First, we need to change the ServerAdmin directive to an email that the site administrator can receive emails through.


Then ServerName and ServerAlias


The only other thing we need to change for a basic virtual host file is the location of the document root for this domain. We already created the directory we need, so we just need to alter the DocumentRoot directive to reflect the directory we created:

DocumentRoot /var/www/app-name

In total, our virtualhost file should look like this:

<VirtualHost *:80>
    DocumentRoot /var/www/html/app-name/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

save and close the file.

2. Enable the Virtual Host File

sudo a2ensite

When you are finished, you need to restart Apache to make these changes take effect:

sudo service apache2 restart

3. Set Up Local Hosts File (Optional)

sudo nano /etc/hosts

hosts file will look something like this   localhost

For the domain that I used in this guide, assuming that my VPS IP address is, if you are creating vhost locally, you can replace with

Now that you have your virtual hosts configured, you can test your laravel app easily by going to the domain that you configured in your web browser: