While PHP can be installed from source, it is also available through
packages on Alpine Linux and derivatives that use the
apk package manager.
Warning
Builds from third-parties are considered unofficial and not directly
supported by the PHP project. Any bugs encountered should be reported to the
provider of those unofficial builds unless they can be reproduced using the
builds from » the official download
area.
The packages can be installed using the apk package manager.
Installing packages
PHP packages in Alpine Linux include the major version number in their name
(e.g. php83 for PHP 8.3). In the examples below, replace
83 with the PHP version available on your Alpine Linux release.
Before installing a package, ensure the package index is up to
date by running apk update.
Example #1 Alpine Install Example
# apk add php83
Alpine does not configure PHP for a web server automatically.
For FastCGI setups, install php83-fpm and enable
the php-fpm83 OpenRC service (note that the package
name and the service name use different ordering of the version suffix).
For example:
Only the core extensions are installed with the base package. Additional
extensions such as
MySQL, cURL, GD, etc.
can be installed as separate packages.
Example #3 Searching for available PHP packages
# apk search php83
The list of packages includes the CLI, FPM, and many extensions.
When extensions are installed, their dependencies are automatically
resolved.
Example #4 Install PHP with MySQL, GD
# apk add php83-mysqli php83-gd
Extensions are automatically enabled when installed; no manual
php.ini editing is required. Configuration files are placed in
/etc/php83/conf.d/. After installing new
extensions, PHP-FPM (or the web server) needs to be restarted for
the changes to take effect.