PHP on Alpine Linux

Tagged as: , , , ,

I’d never been comfortable doing development on Mac OSX. There are always rough edges, missing packages or libraries, out of date XCode etc. It much easier to just ssh into Digital Ocean droplet running Ubuntu and do your development there. But lately, my internet connection has becoming worse and I don’t have much option that do local development again.

I’ve try Docker but Docker on OSX is not that straightforward. It need to run inside Docker Machine, which is a vm running under virtualbox. Given my macbook air only has 4GB RAM, I need something lightweight. The new Docker for Mac and Windows Beta mentioned about the use of xhyve vm instead of virtualbox. It look interesting so I gave it a try.

Compiling xhyve is very straightforward. Just git clone from Github and run make. It come with a test vm that will boot tinylinux. Seeing it working, I decided to try running Alpine Linux. There’s one catch, to have networking inside xhyve, you have to run it as root.

To have Alpine on xhyve, I just followed this gist snippet. With the exception of the shown Alpine version (3.3.1) failed to have networking with DHCP, it work as expected. You need to use Alpine 3.3.3 instead.

Once you get Alpine running, you can start adding the required packages using Alpine package manager apk:-

apk add php php-json php-phar php-openssl php-curl php-xml php-dom php-pdo php-mbcrypt php-pdo_mysql php-ctype
apk add php-iconv
apk add mysql
apk add mysql-client
apk add nodejs

Setting Up Mariadb:-

/etc/init.d/mariadb setup
service mariadb start
/usr/bin/mysqladmin -u root -h alpine password 'new-password'
Please note that this is not for production setup. It just for testing and development.

So for a test drive, I decided to try to run InvoiceNinja app.

git clone
cd invoiceninja

Create the required database:-

mysql -uroot -pnew-password
CREATE USER 'ninja'@'localhost' IDENTIFIED BY 'ninja';
GRANT ALL PRIVILEGES ON `ninja`.* TO 'ninja'@'localhost';

Download Composer:-

curl -sS | php
php composer.phar install
cp .env.example .env
php artisan serve

From here you can access http://localhost:8000/ and then fill in the setup page.

End Notes

Running PHP on Alpine seem promising. This is just a starter so I’m not sure yet how it would end up. There are still a lot of thing to look into - setting up nginx, php-fpm etc. All needed packages so far can be installed via apk.

Resource wise, it also promising. PHP dev server + mariadb totalled to 89MB RAM usage. My macbook air so far not screaming yet.

Written on April 9, 2016 by kamal
About author

Lead Engineer at Xoxzo Inc. Develop web applications in Python/Django. Interested in open source and tech talent development. provide API services for developer to develop messaging and voice based application. The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions. I can be reached via Twitter @k4ml.

Ikuti perkembangan terkini melalui twitter kami @koditi atau FB Page