Installing PHP-FPM
In this lesson we're going to install PHP-FPM. FPM (FastCGI Process Manager) is the modern and recommended way to run PHP applications like WordPress. It's widely supported, efficient, performant and secure.
What is PHP-FPM
You don't need a deep understanding of how PHP-FPM works in order to use it. However, having a general idea will help you create a more performant configuration for PHP, as well as help troubleshoot problems if they occur later on.
PHP-FPM runs as a background manager service and handles requests from your web server, such as Nginx. Upon receiving a request, the manager will forward this request to an available worker, which is a child process that will handle the request.
Each worker can only process one request at a time, so to process two requests simultaneously, you'll need at least two workers. However, note that each worker will require CPU time, some memory and other server resources, meaning we can't simply run an infinite number of workers. We'll get into right-sizing and performance benchmarking in a later module. For now it's okay to just stick to the defaults.
There are other ways to run PHP, including Apache's mod_php, Nginx Unit and LSPHP. We won't cover these in this course, but you're welcome to ask in our Discord community if you run into any trouble with them.
Installing PHP-FPM
On Ubuntu and other Debian-based systems, PHP-FPM is available in the official
package repositories, usually named php-fpm
, which is a meta-package
linked to a versioned package like php8.3-fpm
, php8.4-fpm
, etc. You can
install this package using:
sudo apt update
sudo apt install php-fpm
This will install the PHP interpreter/runtime, the FPM service, all relevant configs and some supporting modules.
PHP extensions
On most systems this will not include any MySQL modules, cURL, ImageMagick and some
other ones required or recommended for WordPress.
Fortunately, most of these are available through apt
as well:
sudo apt install php-mysql php-curl php-imagick php-mbstring \
php-xml php-zip php-igbinary php-intl php-redis
You can verify the current PHP version and a list of all installed modules using:
php -v
php -m
You may encounter plugins and themes that require another extension, which
you can install in a similar way. I like to keep this list in a php-extensions.sh
helper file in my configuration repo to keep track of the required extensions,
so that I can easily migrate to a new server without having to look everything
up again:
#!/bin/bash
apt install \
php-mysql \
php-curl \
php-imagick \
# ...
I usually keep notes in the file itself, but may also look through Git history if I need more context on a specific extension when doing spring cleaning. If you cannot find an extension in the OS package repository, you can usually install it from PECL.
Running PHP-FPM
The PHP-FPM package will also install a php8.3-fpm
(or another version)
systemd
service, which you can control using systemctl
:
sudo systemctl status php8.3-fpm
There will also be a default PHP-FPM log in /var/log/php8.3-fpm.log
with a
corresponding entry in /etc/logrotate/php8.3-fpm
.
On its own, PHP-FPM doesn't serve web requests directly. You will need to route some HTTP traffic from Nginx to your FCGI listener, and respond to that traffic using PHP. We'll do some of this in the next few lessons.