Setting up Linux Mint for developing Kirby websites locally with Valet-linux

A few months back, I finally got around to set up a convenient environment for developing Kirby websites on my Linux laptop.

After migrating all my webwork from Wordpress to Kirby during 2019, I was still stuck with a dev environment I had originally set up with Varying Vagrant Vagrants (VVV). It is a very convenient solution for Wordpress development, but always felt way too heavy for the straightforward and lightweight CMS that is Kirby. Essentially, I wanted to get away from having to fire up a virtual machine every time I had to fix a line of code in a website.

NB. Paths, file names and other variables may vary between different Linux distributions.Since the Mac crowd was raving about Valet, I chose the Linux fork Valet-linux for my setup. I was surprised how easy it was to convert my system, a rather fresh Linux Mint 19.3 Cinnamon install, into a frictionless development server.

Installing PHP and Composer

The Nginx web server is already pre-installed on Linux Mint, but PHP is not. Hence, I first installed PHP (most recent version in the Mint 19.3 repository is 7.2, so I lazily went with that):

sudo apt-get install network-manager libnss3-tools jq xsel php7.2-cli php7.2-curl php7.2-mbstring php7.2-xml php7.2-zip php7.2-sqlite3 php7.2-mysql php7.2-pgsql php7.2-gd

Then, I downloaded and verified Composer (a dependency manager for PHP, and prerequisite for running Valet-linux):

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;

Next, I ran the installer and subsequently deleted the setup script:

php composer-setup.php
php -r "unlink('composer-setup.php');"

Moving composer.phar to /usr/local/bin required admin rights:

sudo mv composer.phar /usr/local/bin/composer

Adding Composer to the PATH variable is an important step. The location of the setup file may vary by Linux distro, and there are several ways to do this, but on my Linux Mint 19.3 adding the following line to ~/.bashrc did the trick:

export PATH=$PATH:$HOME/.config/composer/vendor/bin

Installing and setting up Valet-linux

Once the PATH variable was set up, I installed valet-linux via Composer:

composer global require cpriego/valet-linux
valet install

Finally, I navigated to my projects folder that will host my Kirby sites and set it up so that every subfolder would be reachable as a local domain (e.g. folder ~/projects/kirbysites/mysite would turn into the root folder of domain http://mysite.test).

cd ~/projects/kirbysites
valet park

From my experience, and to my great suprise, everything worked immediately after executing the steps above. Valet-linux has slightly less functionalities than its Mac counterpart, but it comes with an impressive range of tools for getting new websites up and running with ease.

Compared to the complexity of my old VVV setup from the Wordpress times, I especially enjoy the fact that all my local dev sites are always available as soon as my machine is running (with no significant overhead). Plus, starting a new project or running a few tests has become incredibly straightforward, as it requires no more than creating a new folder under ~/projects/kirbysites.