How to install Laravel 5.6 on Ubuntu 18.04

The latest Long Term Service (LTS) of ubuntu was released on the 26th April 2018, so I thought I would take the opportunity to install Laravel on Ubuntu 18.04 to check if the process is any different to installing on Ubuntu 16.04.

I did find a few differences and thought I would document them to help others.

Ubuntu 16.04 -> install Laravel on ubuntu 16.04

Installing PHP 7 is not essential if you are going to make use of Homestead environment. However it is always useful to have PHP installed on your development machine or laptop. In my case I often use it quickly develop utility scripts. I may also have several other PHP software development frameworks installed.

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 do this open a terminal window ctrl + alt + t

If you already have PHP installed you can skip to the next step.

Install PHP 7.2

In ubuntu 18.04, the latest release of PHP 7.2 is now available in the default repositories so you no longer need to additional repositories.

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

We can now go ahead and install PHP7.2 with all the additional components we need to install Laravel.

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

 

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 127.0.0.1:8000 -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

To do simply open your ~/.bashrc

Towards the bottom of the file just paste the following line

If you would prefer to do this all in one line without manually editing your ~/.bashrc you can do so by

We have edited your ~/.bashrc so we will need to refresh your current terminal window with those change. To do so simply

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

Laravel is now up and running and you can continue to develop using just this, however to really enjoy the benefits of developing with Laravel I recommend installing Homestead.

install VirtualBox

VirtualBox is a cross-platform virtualization application. Enabling you to extend the capabilities of your computer so that it can run multiple operating systems (inside multiple virtual machines) at the same time.

Using VirtualBox is a great way to test new versions of operating systems before upgrading your main machine.

For software developers, VirtualBox allows you to mimic your production platform. No more headaches because some software feature which worked great on your Mac isn’t working in production. Simply do your development within the virtual machine.

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 is a software for creating a full development environment within minutes. 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.

It’s Open SOurce and free to use.

Once vagrant has finished installing we can now install the Homestead box

This should take a few minutes to complete, depending on your machine & internet connection. It has taken as long as 20 minutes, but it only ever has to be done once.

SSH Key Generation

If you’re already using Github and have previously generated you SSH keys you don’t to do this step. If not go ahead and create SSH keys



Install Homestead

There are two ways you can use Homestead i.e. Global or Per Project.

I will guide you through using on a per project basis. To do this we change into our project folder and install homestead using composer

We now need to execute vendor/bin/homestead make which create out homestead.yaml and Vagrantfile

This will create a homestead.yaml in the Homestead directory which will contain all your homestead configuration details.

Lets go head and edit this details using a text Editor

I always store all my code and projects in a directory in home drive called code, in my case I have created a project called sourcelink which I would like to continue developing. I will configure homestead to run and synchronise this project.

You homestead.yaml will look similar too

Edit Host file

We need to edit the host file to ensure that it points to the directory for the url http://sourcelink.test

To edit the hosts file we’ll use gedit sudo gedit /etc/hosts and add our mapping of 192.168.10.10 sourcelink.test

Summary

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: