Laravel Local Development

Laravel Local Development

These days, containerization and virtual machines are more than a buzzword, it's a way of systematically organizing various structures that power a website or app. We can better allocate resources such as memory and disk space when we utilize containers, and the benefit of that, is that we waste no unused RAM (for example).

Containers allow us to operate within our own "realm" so to speak, so when something fails, crashes, or is otherwise unavailable, the other things still work. If you have 5 apps running in their own container, they'll utilize their own libraries and packages. App A may need PHP version 8, the newest MySQL and some heavy PDF library. App B can use PHP 7, doesn't need the newest MySQL server, and has no special requirements. In the standard setup you'd need to configure a way for two versions of PHP to run without causing issues. In the container environment, you can simply have this setup without much or any consideration of other code bases.

With that bit out of the way, it's time to take a dive into your options for developing Laravel based projects on your local machine!

Options

We certainly have many options when it comes to developing locally. From a range of VM's, to native PHP servers, to the lovely container ecosystem. Luckily for Laravel devs, there are many specific options directed at Laravel and it's ecosystem which is a nice perk.

XAMPP / MAMP

MAMP or XAMP, keeping it old school and simple!

As someone who used to upload files manually via FTP and develop using Notepad++ with zero syntax highlighting, using a system like this is somewhat familiar and nice. It requires nearly zero configuration from you, and it simply just works. They handle the installation and setup of PHP (and it's dependencies), MySQL, PhpMyAdmin, and Apache/Nginx. You're responsible for the basic task of telling the software where to look for the files on your machine. Hit up localhost and you've got yourself a basic LA/EMP stack.

I actually use MAMP for local small projects that require a DB. Especially for when running php artisan serve doesn't provide me with everything.

Pros & Cons

Pros

  • Simple and easy setup.
  • It's free (MAMP does offer a Pro version which is really nice).
  • Each software is designed to work with your OS.
  • They handle the 'server' aspect for you, no need to build out your server stack.

Cons

  • Basic features.
  • Doesn't teach you CLI skills for interfacing with a server.
  • May not much your server / production-level setup.

Docker

Containerize with Docker!

Development with Docker is very different from relying on a software to handle your setup. With Docker, you are in charge and control over every fine detail. Server OS, PHP version, RAM usage, library dependencies and more! Docker is something you'll find common amongst teams these days since its documentation and community is so mature and provides plenty of resources for problems, new approaches, and fixes for bugs.

Pros & Cons

Pros

  • It's the modern way of doing things.
  • You have absolute control over the 'server'.
  • Gains you CLI skills with interfacing with a server.
  • Can control the OS of your server.
  • Can ensure your server matches your production environment (and other developers).
  • Can spin up entire databases and infrastructure and trash them when you're done; less system resource usage.

Cons

  • The learning curve can be semi-steep.
  • Getting a functioning 'server' will take longer at first.
  • Many OS's report sluggish speeds (it's known to be resource intense)
  • May be too complex for basic or simple projects.

Note: some of these suggestions rely on docker

Laradock

Laradock, powered by Docker

This is an absolute mammoth of a setup built to cover a large range of situations. It's a Docker image, so you literally turn on Docker, clone the Laradock repo, and wait. It installs so many dependencies and utilities aimed at covering nearly any type of project setup you could imagine. Afterwards, you simple set up your projects in it's directory structure and carry on with development. Laradock, if configure properly to reduce the number of dependencies, can be an amazing asset. Any system that sets up PhpMyAdmin, GitLab, Redis, Grafana, or Confluence definitely earns it's position as a very useful tool to have.

Pros & Cons

Pros

  • Automatically sets up tons of development related needs.
  • A simple git clone command and you're on your way.

Cons

  • The codebase powering it is MASSIVE.
  • The configuration file is large and editing it may break things.
  • May install things you do not need.
  • Requires optimization for iOS machines to run efficiently.

Laravel Sail

Combine the power of Laravel and Docker

We like official things, right? Laravel Sail is Laravel's native way of handling a Docker image. It takes care of your expected server setup with a few simple commands and does all the heavy lifting for you. It's a great middle for those looking to avoid complex setups or basic/featureless offerings. It can be expanded on, so you're able to grow your project as the needs increase.

Pros & Cons

Pros

  • It's an official Laravel tooling asset.
  • It's fairly simple in it's configuration approach.
  • It's designed specifical for Laravel.

Cons

  • Needs special setup for Windows OS.
  • Abstracts Docker concepts, the knowledge may not carry over.
  • Artisan commands will be different when working inside the Sail container.

Laravel Homestead

Laravel and Vagrant, a unique VM setup

This was one of the original ways to utilize a virtual machine when developing with Laravel. It's another offering within the Laravel ecosystem, so you know it's geared towards the framework. However, what sets Homestead apart from the other options is that it utilizes Vagrant; a virtual machine platform that arrived well before Docker was a thing. I actually was introduced to Vagrant some years ago as something different than using the old school local LAMP stacks.

Pros & Cons

Pros

  • It's Laravel specific.
  • It's a little easier to understand and setup than Docker based environments.
  • Allows you to configure your VM any way you want.
  • Allows you to easily dispose of the virtual resources created (files, cache, database, etc...) when you shut down the VM.

Cons

  • It requires two additional softwares: Virtual Box/Parallels and Vagrant.
  • May require more configuration that a typical Docker image.

Is that it?!?

But. aren't there other options? Yes, absolutely! This article only covers the top / mainstream approaches. But that doesn't mean there aren't other options to handle your needs, or that they are less effective or bad. For example:

Get my E-Book

Pay what you want, $0 or $100 - Freelancer's Guide Book