How to install Laravel 5.6 on Ubuntu 16.04

Detailed how to instructions to install Laravel 5.6 on a Ubuntu 16.04 desktop computer, in order to quickly start developing PHP Web Applications using Laravel 5.6 quickly

Ubuntu 18.04 -> install Laravel on ubuntu 18.04

We are going to install Laravel and all the associated components making use of the Terminal commands. If you would like to gain a better understanding of all the commands we use throughout this tutorial or would just like a handy cheat sheet you can refer to, too help remember all the commands and their uses check out our Linux & Ubuntu Terminal Command Cheat sheets

In order to proceed with the installation process open a terminal window ctrl + alt + t

Install PHP 7.2

The first requirement is the PHP and and a few additional PHP components. If you are going to only want to leverage the convenience of Homestead, you can skip this step, as Homestead comes with PHP and all the required components already installed. However, as a PHP developer you will probably want PHP on your development machine for convenience sake and the ability test and develop other PHP based solutions.

It’s always good practice to update you repositories and carry carry out any upgrades.

At the time of writing this post is PHP 7.2, is not included in the default Official Ubuntu repositories for Ubuntu 16.04. However, PHP 7.2 will be included in Ubuntu 17.10 & 18.04. Check out our guide to installing PHP 7.2 and Laravel on Ubuntu 18.04

To install PHP 7.2 on ubuntu 16.04 we will need to add a link to an alternate repository to gain access to the installation files.

First in order to do so we will also need to install a package that will allow you to easily manage your distribution and independent software vendor sources.

Once installed we can add a link to the new repository and update

We can now go ahead and install PHP 7.2 with all the additional components we need.

To ensure we have everything installed and PHP is working lets quickly check the version using php -v

php version check

Install MySQL

You can install whichever database server you wish but in my case I needed to use mysql

Once installed just you’ll want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users.

Install curl

Typically on fresh installs of ubuntu cURL is not installed. cURL is a computer software project providing a library and command-line tool for transferring data using various protocols.

Install composer

The Laravel uses the composer to manage your dependencies, so the next step is install Composer.

Change permissions on composer so youu can run it without sudo

Install Symfony

laravel leverages another PHP framework, Symfony, quite intensively so it worth while installing symfony on your development machine too.

We’ll use Composer to install the Skeleton and create a testproj

Afer installing and creating the test projects lets run it to check we have everything working as expected.

Symfony install

Lets quickly run the project to test all is working. Change into the directory cd testproj and execute php -S -t public

We can now open our browser and navigate to http://localhost:8000/ .

We should see the test page which confirms all is up and running
Symfony test page

Install Laravel

We’re now ready to install Laravel using composer

All that is left to do now is ensure Laravel is added to you PATH. You can open your ~/.bashrc and paste the line below

or if you’re feeling ambitious and you have backed up your ~/.bashrc you can attempt this line to do it all in one line

All we now need to do is refresh the bash profile because we have made changes

Start project

We’re all set now to create project using Laravel. We can use either method of starting a project i.e. using Laravel commands of composer based. For the purpose of this guide we’ll be using Laravel.

To start a new project create a directory you would like to store your projects i.e. mkdir projects

change in to the directory cd projects and then we can use the Laravel command to create a new project which in this instance is a simple To Do List web application we’ll name notepad, but you can name it whatever you choose.

Once the application is generated we can cd notepad the php artisan serve and the we then open a browser and visit http://localhost:8000 we’ll see the laravel sample page

Laravel Test Page

Install Homestead

At this stage we have the laravel framework installed and we are able to generate projects. However, to truly enjoy the benefits of Laravel we should install the Homestead environment.

What is Homestead

Laravel Homestead is a pre-packaged virtual machine that provides development environment without requiring you to install PHP, a web server, and any other server software on your local machine. You don’t have to worry about about messing up your operating system!

Homestead makes use of Technology called Vagrant, that enables users to create and configure lightweight, reproducible, and portable development environments. Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!

In order to make use of Vagrant we need to install both Virtual Box and Vagrant.

Install VirtualBox

VirtualBox is a cross-platform virtualization application. What does that mean? For one thing, it installs on your existing Intel or AMD-based computers, whether they are running Windows, Mac, Linux or Solaris operating systems.

It’s free and available from Oracle VM VirtualBox

Don’t install Virtual box from the Default 16.04 Repositories as this isa nout of date version of Virtual box and Virtual box 5.2 is the latest.

To install virtual box and the Virtual box extension pack which adds useful new features to this popular virtualisation package.

At the time of writing this post, there seemed to be an issue with installing the virtual box extension pack via the terminal, so I needed use a work-around.

Download Virtual Box Extension pack 5.2.10 and manually install it.

Once download is complete Open virtual box and install the extension pack:
File -> Preferences -> Extensions -> Adds new package (“+” Button)

Install Vagrant

Vagrant provides a simple and easy to use command-line client for managing these environments, and an interpreter for the text-based definitions of what each environment looks like, called Vagrantfiles.

Don’t install the version of Vagrant available in the default repositories for Ubuntu 16.04 because it is an old version and will not work with the latest release of homestrad

Once vagrant is installed we can add the laravel/homestead box. This process usually takes about 13-20 minutes depending on your internet connection and spec of your machine.

You will only ever need to do this one when setting up your machine initially.

You will be asked which provider you would like to use choose VirtualBox and proceed. Once this is complete we are now ready to configure homestead on a per project basis.

Configure Homestead Per Project

Homestead is configured using a YAML file, which contains configuration information regarding sites & files on your computer, databases to create etc. When you start a new project, you have to add an entry to this file and re-provision.

When using Homestead on a per-project basis, you keep this file with your project and it contains only that project’s settings. Enabling you to quickly clone a project if it’s under source control, and quickly boot a Homestead instance for that project.

This is especially helpful when setting an existing project up on a new computer, as you don’t need to manually set up Homestead and configure it for your project.

To create a Homestead.yaml for your project, first we need to add Laravel/Homestead development dependency to our project.

To do this cd into your project directory then execute

Once complete we can now use this pacakge to initialise files Homestead will require and create the Homestead.yaml

If you check your directory now you will notice the Homestead.yaml has been created.

We are now almost ready to run our project, all we need to do now is add an entry to our Host file for the website.

Then we add an entry for our new website and save the file

if you’re confident enough you can also do the above using the following command

We can now just execute vagrant up and browse to out site http://sourcelink.test


I have to admit that it is porbably not the most friction free experience I have had configuring the various software development frameworks, but Laravel more than makes up for it as you start working with it.

Hope this guide helps you on your way to becoming an efficient Laravel developer and save you time and frustration on your journey.

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me
%d bloggers like this: