Installing Laravel with Composer on Ubuntu

Logo of Laravel

You may wonder why I need a Laravel installation on my machine, being basically a front-end developer (with full-stack skills). Well, I see that PHP is yet required by employers to date and this framework is so hot right now — as it used to be Symfony some years ago. It could be integrated with WordPress and includes Bootstrap to easily create web publishing platforms… so I decided to give it a try. This reminds me when PHP-Nuke was still a thing. It also seems to work well with client-side JavaScript frameworks and libraries.

If you read my previous story, then you already know that I’m involved in WordPress development and I mainly work with Ubuntu. Starting to understand Laravel isn’t hard on all the available platforms: you may get it running everywhere, as long as you can install Composer. It’s a so-called dependency manager for PHP to make package installations easier just like npm for Node.js. Of course, you need a web server such as Apache or NGINX too; I chose the first, because it has a great built-in support for the language.

$ sudo apt-get update
$ sudo apt-get install apache2 php libapache2-mod-php

This is a basic setup of PHP, but (although it can run Composer yet) isn’t enough to get Laravel working. Yes, because the framework needs lots of extensions to enable its featues: Ubuntu 19.10 has them all on the official repositories. Keep in mind that you have to get several dependencies to start, including the already mentioned Symfony. Then you can go on playing with Artisan — the framework integrated CLI. I chose to install the latest version of PHP and its extensions that to date is 7.3, but you can have a newer release.

$ sudo apt-get install php-bcmath php-cli php-curl php-gd php-imap php-intl php-mbstring php-mysql php-zip php-xml

So, now you have all the pre-requisites to install both Composer and Laravel. I want to highlight that you won’t get the framework itself ready to a global scope as you may be used with npm packages, but a working project managed by Artisan: Laravel comes on demand to bootstrap a new app (a blog, in particular). You can’t call it wherever you desire, because the CLI resides in the project you’ll create below. There will be no scripts in your path. I’m still unsure this is a great deal, but that’s it; I couldn’t find a way to get it globally.

$ curl -sS -o composer-installer.php
$ sudo php composer-installer.php --install-dir=/usr/local/bin --filename=composer
$ composer create-project --prefer-dist laravel/laravel foo

This will install Composer, then initialize a new Laravel project in a foo directory. It doesn’t matter how you name the downloaded installer, neither the folder to be created: just focus on the listed commands. I was surprised when I called the next and latest one, since I found something familiar… yes, because Artisan includes Webpack and works more or less the same way it does. The created project provides a Sass sub-folder ready to be used as long as Bootstrap and even axios I met using Vue.js in the past. It’s so cool, isn’t it?

$ cd foo/
$ php artisan serve

Now you have a web server running on http://localhost:8000 which just shows a default welcome page. Time to open an editor and start understanding how Laravel do things. That’s what I’ll do next, planning to integrate it with WordPress for future projects. Here I wanted to share how I installed the framework via Composer and some thought on what it includes. I’m new to this, so I can’t suggest anything more interesting to you yet: let me say I wasn’t disappointed at all. I found a new awesome web tool to play with.

As I said, Laravel seems to be easy to be understood by front-end developers, but it’s not only a boilerplate to create PHP websites. It includes tools to change the way you develop a project too like other libraries and this is just the beginning. I’m interested in the WordPress integration, because I still use to create dynamic solutions with it: I’ll come back with more on this as soon as I have something to show. On the web there are plenty of tutorials to get started and maybe I’ll succeed in getting both work under a Docker container. That’s my plan for the very next future, since it makes even more sense to me.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store