Setting Up Apache with PHP

From Alpine Linux
Revision as of 16:06, 17 March 2020 by Mckaygerhard (talk | contribs) (Installing Apache + PHP: fix explanation version of alpine where php5 packages were gone)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Installing Apache + PHP

Enable the repositories:

cat > /etc/apk/repositories << EOF$(cat /etc/alpine-release | cut -d'.' -f1,2)/main$(cat /etc/alpine-release | cut -d'.' -f1,2)/community

apk update

Add the main packages with the command:

export phpverx=$(alpinever=$(cat /etc/alpine-release|cut -d '.' -f1);[ $alpinever -ge 9 ] && echo 7|| echo 5)

apk add apache2 php$phpverx-apache2

The php"$phpverx"-apache2 will be "5" or "7" depending of the alpine version installed, since alpine 3.9 there's only the php7 packages.


Move to the directory where your site will reside:

cd /var/www/localhost/htdocs

And create an index.php file to test if everything is ok:

vi index.php

Add the following lines in the file:


That done, let us start apache2 web server:

rc-service apache2 start

Now access: http://<ip_address> and if everything is ok you will see the PHP info page.


Finally let us set up apache2 to start on operating system startup:

rc-update add apache2

Now you can create your PHP site and host in this directory.


This is the easiest way to setup Apache with PHP support, but it's the most inefficient (resource wise) setup, please refer to Apache with php-fpm