Install PHP from prebuilt packages on Alpine Linux with OpenLiteSpeed and MariaDB

Install PHP on Alpine Linux

First, let's install PHP. Alpine Linux official repositories contain slightly outdated PHP versions. You can install PHP on Alpine Linux using apk tool:

apk add --no-cache php7

3rd party repository Alpine repository provides the latest PHP versions.

Adding repository to your Alpine:

apk add --no-cache wget ca-certificates \
&& wget -O /etc/apk/keys/ \
&& echo "" >> /etc/apk/repositories PHP packages are prefixed with php7.2, php7.1 and php7.0. Installing latest PHP is as simple as:

apk add --no-cache php7.2

Install OpenLiteSpeed

echo '@testing' >> /etc/apk/repositories
apk add --no-cache litespeed@testing

Install MariaDB

apk add --no-cache mariadb

Development on localhost using built-in web server

If you're developing PHP applications on your local workstation, PHP also has a useful built-in web server for localhost development. It is not intended to be used for production environments.

Inside your project folder you can run it from the command line using PHP CLI SAPI:

php -S localhost:8000

Visit http://localhost:8000/ in your browser to access it.