Building a Laravel Development Environment with Docker, Vessel and… LaraPrep!

Once upon a time…

… I used to develop my applications in a Vagrant/Homestead development environment. It worked pretty well, I remember using it for a lot of projects, but soon performances decreased, especially in large projects/codebases.

Sure, I was able to make some optimizations and tweaks here and there, but it was mostly a palliative. I knew I needed something different.

Then, Docker arrived. So I started my research of a cool Laravel application development environment. 

I loved the way Docker made everything easier regarding development environment organization. Sure, it has a very steep learning curve (especially at the beginning), but it was worth it.

The next step was quite obvious: find a set of scripts to make the provisioning of a new dev environment as easier as possible.

Why? Simple: I like to try/test new packages and techniques on Laravel. Well, to be more specific, I have to say that I want to explore them in a new, fresh Laravel application.

So, I discovered Laravel Vessel, an exciting project you can find here. What I love about Vessel is the minimalism of its footprint and provisioning. It just has the very basics:

  • PHP 7.2
  • MySQL 5.7
  • Redis;
  • NodeJS with NPM, Yarn, & Gulp;

However, I wanted to find a way to use it without having PHP installed locally. The dedicated documentation page helped me with a specific script. Everything worked so I asked myself: what if I try to automate it in a simple shell script?

Something that I can call with something like “myscript myproject” and:

  • creates a new Laravel project in the myfolder folder;
  • adds a new record to the hosts file, to reach my project with http://myfolder.test;

WITHOUT the need for anything on my local machine. Only exception: Docker and Docker Compose.

So, after a couple of hours on it, I finally made it! I put it on Github.

Here’s the code:

Nothing special, after all. This shell script defines a docker_prep function that:

  • initializes some variables with the user id and name;
  • echoes a new line into the hosts file, to add a new .test record in it (with the same project name we chose);
  • creates a new project using Docker and the shippingdocker dedicated image;
  • adds Vessel as a dependency;
  • calls the artisan vendor:publish Artisan command, passing the Vessel provider;
  • initializes the development environment;

With a one-line instruction like

you can now prepare the perfect development environment for your next application.

Enjoy it! You can find LaraPrep here on Github.

Note: if you have any feedback to improve this script, feel free to comment below or make a PR on Github 😉


Da quando vivo a Roma (da qualche giorno prima, a voler essere precisi) tengo un diario personale in cui riporto un po’ di tutto.

Il format è sempre lo stesso. Per cominciare, numero della pagina in alto a sinistra. Subito sotto la data. A destra, invece, una parola significativa per quel momento. Dopo aver concluso, in fondo, il titolo della canzone che sto ascoltando oppure il rumore che sento in sottofondo in quel momento.

Una domenica al Colosseo, con mio fratello (che fa la foto).

A volte è un resoconto della giornata, altre volte è qualcosa che mi ha segnato talmente tanto da volerla imprimere sulla carta per paura di scordarlo. Altre volte ancora una citazione, una foto, una poesia o un’idea. L’elenco potrebbe continuare all’infinito, tale è la varietà delle cose che ci butto dentro.

Il punto però è un altro: sto per raggiungere la pagina quattrocento. La prima è del 30 Agosto 2013. L’ultima, al momento, è del 9 Febbraio 2018.

“Ammazza bravo, sai scrivere. Vuoi un applauso?”

No, aspetta, fammi arrivare al nocciolo della questione.

Continue reading