Installing Laravel with Composer on Ubuntu
How-to install Laravel with Composer on Ubuntu to get started with Artisan
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 https://getcomposer.org/installer -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.