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 out any upgrades
sudo apt update
sudo apt upgrade -y
We can now go ahead and install PHP7.2 with all the additional components we need to install Laravel.
sudo apt install php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring php7.2-zip php7.2-fpm php7.2-xml -y
To ensure we have everything installed and PHP is working lets quickly check the version using
You can install whichever database server you wish but in my case I needed to use mysql
sudo apt install mysql-server
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.
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.
sudo apt install curl
The Laravel uses the composer to manage your dependencies, so the next step is install
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Change permissions on
composer so youu can run it without
sudo chown -R $USER ~/.composer/
laravel leverages another PHP framework, Symfony, quite intensively so it worth while installing symfony on your development machine too.
Composer to install the Skeleton and create a testproj
composer create-project symfony/skeleton testproj
Afer installing and creating the test projects lets run it to check we have everything working as expected.
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
We should see the test page which confirms all is up and running
We’re now ready to install Laravel using
composer global require "laravel/installer"
All that is left to do now is ensure Laravel is added to you
To do simply open your
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
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
We have edited your
~/.bashrc so we will need to refresh your current terminal window with those change. To do so simply
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.
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.
composer create-project --prefer-dist laravel/laravel notepad
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 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.
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.
sudo apt install virtualbox
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)
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.
sudo apt install vagrant
Once vagrant has finished installing we can now install the Homestead box
vagrant box add laravel/homestead
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
ssh-keygen -t rsa -C "use your email address here"
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
composer require laravel/homestead --dev
We now need to execute
vendor/bin/homestead make which create out
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.
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
To edit the hosts file we’ll use gedit
sudo gedit /etc/hosts and add our mapping of
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.
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.
Latest posts by Gary Woodfine (see all)
- 8 Plugins you need for your WordPress Website 2018 - July 1, 2018
- SEO For Dummies - June 25, 2018
- Why We Buy – The science of shopping - May 15, 2018