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 added the PPA ondrej/php
to meet Kirby’s requirements):
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install network-manager libnss3-tools jq xsel php7.4-{cli,curl,fpm,gd,mbstring,mysql,pgsql,sqlite3,xml,zip}
Then, I downloaded and verified Composer, a dependency manager for PHP, and prerequisite for running Valet-linux (Note that the SHA hash key may change over time, it can be checked from Composer’s download page):
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { 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 as the last line in ~/.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
.
Works for Wordpress as well
Running Wordpress projects using this same setup is possible as well, but will require installation of a MySQL/MariaDB database on the system:
sudo apt install mariadb-client-core-10.1
After installation, it needs to be armored against external access:
sudo mysql_secure_installation
In recent versions of MariaDB, logging in as root user only works with admin rights (sudo); the default MySQL password is empty:
sudo mysql -u root -p
To use a database, create a dedicated user with full rights:
CREATE DATABASE `wordpress`;
CREATE USER 'myusename'@localhost IDENTIFIED BY 'password';
GRANT ALL privileges ON `wordpress`.* TO 'myusername'@localhost;
FLUSH PRIVILEGES;
After entering these credentials into its config file, a Wordpress instance, for example installed to folder ~/projects/kirbysites/wordpress
, works like any Kirby site in those other folders.