Install Laravel on Ubuntu 16.04

laravel on ubuntu 16.04

Laravel is a PHP web application framework which is intended for the development of web applications following the model–view–controller (MVC) architectural pattern. It has an expressive, elegant syntax and provides tools needed for large, robust applications.

A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.

In this article we will install the latest version of Laravel on a Ubuntu 16.04 VPS.

We will be using our SSD 1 Linux VPS hosting plan for this tutorial.


# ssh root@server_ip

You can check whether you have the proper Ubuntu version installed on your server with the following command:

# lsb_release -a

You should get this output:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial


Make sure your server is fully up to date using:

# apt update && apt upgrade

Then install some much needed dependencies:

# apt install php-mcrypt php-gd php-mbstring

Install Composer which is a tool for dependency management in PHP.

# curl -sS | php

Once Composer is installed, you need to move it so that Composer can be available within your machine path:

# mv composer.phar /usr/local/bin/composer

Make it executable:

# chmod +x /usr/local/bin/composer

Now create a directory where Laravel will be downloaded.

# mkdir /var/www/html/your_website

Of course replace your_website with your actual domain name or any name for that matter.

Now enter the newly created directory and download the latest Laravel version.

# cd /var/www/html/your_website

# git clone

Move the files and directories from the Github Laravel clone into your current working directory (/var/www/html/your_website/)

# mv laravel/* .

# mv laravel/.* .

Now delete the unnecessary laravel dir:

# rmdir laravel/

Start the Laravel installation using Composer:

# composer install

Once the installation is finished, assign the proper ownership over the Laravel files and directories:

# chown www-data: -R /var/www/html/your_website/

Next, set the encryption key needed:

# php artisan key:generate

You will notice the below error when running the command.

  file_get_contents(/var/www/html/your_website/.env): failed to open stream: No such file or directory

To solve this you should rename the .env.example file into .env:

# mv .env.example .env

Generate the encryption key again:

# php artisan key:generate

You should get the following output:

Application key [base64:ULQsledeS17HxCAsssA/06qN+aQGbXBPPpXVeZvdRWE=] set successfully.

Of course the key will be different in your case. Now edit the app.php file and configure the encryption key. Open the file with your favorite text editor. We are using nano.

# nano config/app.php

Locate the ‘key’ => env(‘APP_KEY’ line and add the key next to it. After you are done the directive should look like this:

'key' => env('APP_KEY', 'base64:7fO0S9TxZu8M2NwBWVEQsjPGRi+D1t6Ws8i0Y2yW/vE='),

    'cipher' => 'AES-256-CBC',

Save and close the file.

Stuck somewhere? Get a VPS from us and we’ll do all of this for you, free of charge!

Create an Apache virtual host file so your domain can serve Laravel. Open a file, for example your_website.conf:

# nano /etc/apache2/sites-available/your_website.conf

Paste the following:

<VirtualHost *:80>
DocumentRoot /var/www/html/your_website/public/
<Directory /var/www/html/your_website/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/apache2/
CustomLog /var/log/apache2/ common

Enable the site:

# a2ensite your_website.conf

Restart Apache so the changes can take effect:

# service apache2 reload

Now open your favorite web browser and navigate to where you will be welcomed by a page as shown in the image below:


Congratulations, you have successfully installed Laravel on your Ubuntu 16.04 VPS. For more information about Laravel, you should check their official documentation.

Of course you don’t have to do any of this if you use one of our Laravel VPS Hosting services, in which case you can simply ask our expert Linux admins to install Laravel for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Tips and Tricks
How to set up system locale on CentOS 7
Install WordPress on Debian VPS
How to install Koken on an Ubuntu VPS
  • Ahmad Afian


    Got Laravel installed quickly with your tutorial. I managed to get it running on VirtualBox. The official Laravel doc is ok but needs a lot of reading for something so simple.

    Thank you.

  • John Nicholes

    Best simple install I have read.


  • Rouhollah Mazarei

    Thank you for this complete tutorial. Just one question: is there any need to edit /etc/hosts file?
    For example adding a line like this:

    • admin


      Author Reply

      No need to edit the /etc/hosts file. If you have a domain name you can point it to your server IP address and add it to your Apache virtual host file.


  • sumit


    Author Reply

    Please help:
    I did this: service apache2 reload
    and got below error:
    Job for apache2.service failed because the control process exited with error code. See “systemctl status apache2.service” and “journalctl -xe” for details.

    • admin


      Author Reply

      There is an error in your Apache configuration and you can use systemctl status apache2.service or journalctl -xe to get more details about the problem.


  • Guillermo


    Author Reply

    I opened my favorite web browser and navigateed to, but nothing happened. Am i doing something wrong? I did everything written in this post.

    • admin


      Author Reply

      You should replace `` with your actual domain name.