Nginx with PHP-FPM is the standard way to serve PHP applications on Alpine Linux. The whole stack fits in well under 100 MiB of packages, which is why it shows up in so many container images. Nginx handles the HTTP side and hands every .php request to the FastCGI Process Manager over a local FastCGI connection, the same split you’d use with Nginx and PHP-FPM on Ubuntu or any other distro. The difference on Alpine is the naming: packages, services and config paths all carry the PHP branch as php83, and the old php8.3-* names this guide once used don’t exist.
We’ll install Nginx and PHP-FPM, wire them together with a server block, then check that the running PHP carries the October 2026 PHP2Shell fix. Alpine’s community repository already ships that fix for PHP 8.3, so a fresh install is patched, but an existing server only gets it after an upgrade and an FPM restart. Every command below was run as root in October 2026 on fresh Alpine Linux 3.24 and 3.21 installs, and an Alpine 3.20 install running PHP 8.3 was upgraded to 3.24 at the package and service level, without a reboot, to test the patch path.
Update Alpine Linux
Log in to your Alpine Linux server and refresh the package index first. Alpine does not install sudo by default, so the commands below are written to run as root. If setup-alpine created an admin user for you, it set up doas instead, and you can prefix each command with doas. When you are turning these steps into a container image build, the same commands go into your Dockerfile, where they already run as root. For a disposable test box, Alpine in Vagrant is the quickest way to get one.
apk update
The index refresh lists the main and community repositories of your release, and community is where the PHP packages live.
v3.24.3-24-g80227f99f7e [https://dl-cdn.alpinelinux.org/alpine/v3.24/main]
v3.24.3-27-g19183ccb0db [https://dl-cdn.alpinelinux.org/alpine/v3.24/community]
OK: 28668 distinct packages available
Also upgrade the packages already installed.
apk upgrade
Once the package index is current, you can install and configure Nginx with PHP-FPM.
Install Nginx on Alpine Linux
Use the apk command line tool to install Nginx web server on Alpine Linux.
apk add nginx
The nginx-openrc package comes along automatically, and it provides the OpenRC service script used in the next steps.
(1/3) Installing pcre2 (10.49-r0)
(2/3) Installing nginx (1.30.6-r0)
Executing nginx-1.30.6-r0.pre-install
Executing nginx-1.30.6-r0.post-install
(3/3) Installing nginx-openrc (1.30.6-r0)
Executing busybox-1.37.0-r31.trigger
OK: 11.4 MiB in 24 packages
Start nginx service after installation.
rc-service nginx start
Confirm service status:
rc-service nginx status
A running service reports a single line.
* status: started
Set nginx service to be started at system boot.
rc-update add nginx default
OpenRC confirms the service joined the default runlevel.
* service nginx added to runlevel default
Install curl, which you’ll use to test both Nginx and PHP from the server itself:
apk add curl
Then use curl to confirm the web server answers.
curl -ik localhost
A 404 Not Found from nginx is the expected answer here, because Alpine’s stock /etc/nginx/http.d/default.conf returns 404 for everything until you give it a site:
HTTP/1.1 404 Not Found
Server: nginx
Date: Thu, 22 Oct 2026 19:28:37 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive
Nginx is up and listening on port 80. It has no PHP handler yet, so the next step installs PHP-FPM.
Install PHP-FPM on Alpine Linux
Alpine names its PHP packages after the branch without a dot: php83, php84 and php85. A command with php8.3-fpm fails with php8.3-fpm (no such package), and so does php83-mcrypt, because mcrypt left PHP back in 7.2. We install PHP 8.3 because it’s the one branch that carries the PHP2Shell fix on every supported Alpine release from 3.21 to 3.24, while Alpine 3.21 still ships PHP 8.4 as an unpatched 8.4.14. On Alpine 3.22 or newer you can swap the php83 prefix for php84, or for php85 on 3.23 and 3.24, and adjust the service and config names to match.
apk --update add \
php83 \
php83-bcmath \
php83-ctype \
php83-curl \
php83-fpm \
php83-gd \
php83-iconv \
php83-intl \
php83-mbstring \
php83-mysqlnd \
php83-opcache \
php83-openssl \
php83-pdo \
php83-pdo_mysql \
php83-pdo_pgsql \
php83-pdo_sqlite \
php83-phar \
php83-posix \
php83-session \
php83-soap \
php83-xml \
php83-zip
apk pulls in 60 packages, and every PHP one should carry the same version.
( 1/60) Installing php83-common (8.3.36-r0)
...
( 8/60) Installing php83 (8.3.36-r0)
( 9/60) Installing php83-bcmath (8.3.36-r0)
...
(60/60) Installing php83-zip (8.3.36-r0)
Executing busybox-1.37.0-r31.trigger
OK: 69.8 MiB in 93 packages
The FPM service is named php-fpm83. Start it and add it to the default runlevel so it comes back after a reboot.
rc-service php-fpm83 start
rc-update add php-fpm83 default
The PHP binary follows the same naming, so the command is php83, not php.
php83 -v
The CLI reports the version and confirms OPcache is loaded.
PHP 8.3.36 (cli) (built: Oct 21 2026 16:38:20) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.36, Copyright (c) Zend Technologies
with Zend OPcache v8.3.36, Copyright (c), by Zend Technologies
PHP and FPM configuration files are available in the following directory.
ls /etc/php83/
The pool definitions sit in php-fpm.d, and php.ini holds the settings shared by the CLI and FPM.
conf.d
php-fpm.conf
php-fpm.d
php.ini
You can install vim and use it to modify configuration files.
apk add vim
With PHP-FPM running and an editor in place, the last piece of the install is the Nginx site that sends PHP requests to FPM.
Point Nginx at PHP-FPM
Installing both packages does not connect them. The default www pool in /etc/php83/php-fpm.d/www.conf listens on 127.0.0.1:9000 and runs as nobody, so Nginx needs a server block that sends .php requests to that address. It is the same location block as the Ubuntu PHP-FPM setup, except that Ubuntu uses a Unix socket where Alpine’s pool uses TCP. Replace the stock 404 site with one that serves /var/www/localhost/htdocs:
vim /etc/nginx/http.d/default.conf
Delete the existing contents and paste this server block:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/localhost/htdocs;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
The try_files $uri =404 line inside the PHP location keeps Nginx from handing FPM a path that does not exist on disk. Test the syntax before reloading:
nginx -t
Both lines must say ok and successful before you go on.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reload Nginx, then drop a one-line probe page into the web root that prints the PHP version and the SAPI handling the request:
rc-service nginx reload
echo '<?php echo PHP_VERSION, " ", PHP_SAPI, PHP_EOL;' | tee /var/www/localhost/htdocs/info.php
Request the page through Nginx, not with the CLI, because only a web request shows what the FPM workers are actually running.
curl -s http://localhost/info.php
The answer fpm-fcgi proves the request went through PHP-FPM. A 502 Bad Gateway instead means Nginx can’t reach php-fpm83 on port 9000, so check that the service is started.
8.3.36 fpm-fcgi
Keep info.php until you’ve done the PHP2Shell check below, then delete it. From here you can upload your PHP application into the web root, and if it needs a database, MariaDB on Alpine pairs with the php83-pdo_mysql extension already installed.
Check and patch PHP2Shell (CVE-2026-109618, CVE-2026-109619)
PHP2Shell is two critical remote code execution bugs in PHP itself, CVE-2026-109618 and CVE-2026-109619, rated CVSS v4.0 9.2 in php.net’s 20 October pre-announcement and fixed upstream on 21 October 2026 in PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 (see the PHP security advisory). Alpine ships the fix: php83 8.3.36-r0 on Alpine 3.21 through 3.24, plus php84 8.4.27-r0 on 3.22 and newer and php85 8.5.12-r0 on 3.23 and 3.24. Alpine keeps upstream version numbers, so the package version is the check:
apk list -I php83-common php83-fpm
Anything at 8.3.36-r0 or later is patched, and anything older is vulnerable.
php83-common-8.3.36-r0 x86_64 {php83} (PHP-3.01 BSD-3-Clause LGPL-2.0-or-later MIT Zend-2.0) [installed]
php83-fpm-8.3.36-r0 x86_64 {php83} (PHP-3.01 BSD-3-Clause LGPL-2.0-or-later MIT Zend-2.0) [installed]
A fresh install can stop here. On an existing server, the installed package is only half the story, because apk didn’t restart FPM in our test. When we upgraded an Alpine 3.20 install from 8.3.15 to 8.3.36, the probe page kept answering 8.3.15 fpm-fcgi until FPM was restarted. Upgrade, restart FPM, and confirm the master process is new:
apk update && apk upgrade
rc-service php-fpm83 restart
ps -o pid,etime,args | grep '[p]hp-fpm: master'
curl -s http://localhost/info.php
The elapsed time in the second column must be a few seconds, which proves the master started after the upgrade, and the probe must report the patched version.
767 0:02 {php-fpm83} php-fpm: master process (/etc/php83/php-fpm.conf)
8.3.36 fpm-fcgi
Restart any long-running PHP CLI workers too (queue workers and similar daemons), since they keep the old code in memory the same way. If apk upgrade finds nothing while the version is still older, run apk policy php83-fpm: it lists the version each repository offers, and an older number there means your mirror has not synced yet, so retry later or switch /etc/apk/repositories to dl-cdn.alpinelinux.org.
Alpine 3.20 reached end of life on 1 April 2026 and has no fixed build: its php83 stops at 8.3.15. Alpine 3.21’s php84 is still 8.4.14 with no fix, and 3.21 itself goes end of life on 1 November 2026. On either, the real fix is a release upgrade, which is what we ran on the 3.20 install. A release upgrade replaces most of the system, so take a backup and read the release notes of every version you cross first, as the Alpine upgrade guide advises. A jump from 3.22 or older to 3.24 also crosses 3.23, where apk itself moved to apk-tools v3. The procedure stays the same apk upgrade --available, and our 3.20 install went from apk-tools 2.14.4 to 3.0.8 in that one step without trouble.
PHP 8.2 users need one extra decision, because 3.22 is the last Alpine branch that ships php82. Either target 3.22, where php82 8.2.35-r0 carries the fix, or move the application to php83 first and then go to 3.24.
Point the repositories at 3.24, upgrade everything, and restart both PHP-FPM and Nginx, since the release upgrade replaces the Nginx package too:
sed -i 's#/v3\.20/#/v3.24/#' /etc/apk/repositories
apk update && apk upgrade --available
rc-service php-fpm83 restart
rc-service nginx restart
Change v3\.20 to your current release in the sed line. On our test install the upgrade moved php83-fpm from 8.3.15-r0 to 8.3.36-r0 and Nginx from 1.26.3 to 1.30.6, and after the restarts the probe page answered 8.3.36 fpm-fcgi. Run the ps and curl checks above to confirm the same on yours, then delete info.php. If the upgrade replaced your kernel package, run sync and then reboot, because the running kernel stays the old one until you do.
Explore More with CloudSpinx
Looking to streamline your tech stack? At CloudSpinx, we deliver robust solutions tailored to your needs:
- Hosting Services: Web Hosting, VPS, and Email Hosting
- Development Services: Custom Web & Mobile Apps, UI/UX Design
- Consultancy Services: Cloud, DevOps, Cybersecurity, and Kubernetes Experts
- Managed Services: End-to-end infrastructure support
- Dedicated Servers: Power and control, fully managed
CloudSpinx also supports Linux infrastructure, containerization, virtualization and general IT services work.