Working with PHP for the past 10 years or so has taken me through quite a ride. Starting with rookie mistakes like not being able to find a semicolon to trying to build my own framework for building sites (do not do this), I finally arrived at something great when I learned object-oriented PHP.
Almost all CMS systems use it, including Joomla, Drupal and WordPress, and of course many frameworks like CakePHP use it as well. I arrived at Laravel in early 2014 and I was instantly hooked. It not only uses OOP, it requires it! I have to admit, this was a challenge, but I learned so much thanks to it, and it has made the code I write for other systems a lot better too!
In this article I’ll show you how to get started with Laravel by installing everything that’s needed to run the system, showing you how to use Laravel Homestead—a great virtual machine—and finally, how to install Laravel itself.
It may seem like a mouthful, but I wanted to make sure that everyone can install it, whether they’re on Windows, Linux or Mac, and even if they have few of the prerequisites. Don’t worry, you only need to do most of this stuff once, and even if you need to do it again, it will be much simpler the next time.
What Is Laravel?
Laravel is a PHP Framework created by Taylor Otwell as a more advanced take on the CodeIgniter framework. The first beta was released in mid-2009. As of June 2015, Laravel is at version 5.1, which is the first version to receive LTS (Long Term Support), putting Laravel into the mix when searching for a viable platform for large-scale work.
Laravel is designed to help you work in a standardized, elegant and rapid fashion. This is achieved through strict guidelines and third-party systems.
Laravel has a strict Model-View-Controller (MVC) structure and a natural way of working with object-oriented code. These two features almost force a certain way of writing code on developers—which is a good thing.
As far as style and methodology goes, Laravel applications will be similar, so other developers can come in and work with an instantly familiar mindset.
Laravel’s elegance stems from the same OOP nature and MVC mindset and the routing methodology used. A few simple characteristics of the engine as a whole conspire to make you write code which is visually pleasing, organized, and as self-documenting as possible.
Self-documentation is a wonderful byproduct of well-written object-oriented code. You can achieve almost readable sentences by naming your classes, functions and variables properly, adding up to highly browsable code.
More importantly, all this translates to predictable and testable code which produces consistent, easy-to-foresee results every time.
The speed at which you can build an application is astonishing. If you are new to OOP, Composer and using the terminal, this may not be apparent at first, but once you get the hang of things you will be astonished at what you can accomplish.
Laravel is set up to work well with third-party packages from Composer, which means that adding full support for the Facebook API, or the MailChimp API, Loggers, Profilers and other tools takes a few keystrokes—not minutes or hours.
You can install Laravel on most servers, or create your own using a virtual machine. The basic requirements are:
PHP >= 5.5.9
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
I’m using Laravel Homestead to run Laravel locally. Homestead is a Vagrant box which you can grab for free. The link above has complete installation instructions if you need them, but I’ll outline the main steps below.