Install PHP from prebuilt packages on Alpine Linux with Caddy and PostgreSQL

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 PostgreSQL

apk add --no-cache postgresql

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.