On this page
- Which PHP version does each distribution ship?
- How do you install the packaged PHP-FPM on Ubuntu or Debian?
- How do you install PHP-FPM on Rocky Linux or AlmaLinux?
- How do you get a newer PHP from the Ondrej PPA on Ubuntu?
- How do you add the Sury repository on Debian?
- How do you use the Remi repository on Rocky or Alma?
- Which extensions do most applications need?
- Which php.ini settings should you change?
- How do you confirm which settings PHP-FPM really uses?
- Questions
Which PHP version does each distribution ship?
Each release freezes one PHP branch and backports security fixes to it for the life of the release.
- Ubuntu 24.04: PHP 8.3
- Ubuntu 22.04: PHP 8.1
- Debian 13: PHP 8.4
- Debian 12: PHP 8.2
- Rocky Linux 9 and AlmaLinux 9: PHP 8.0 by default, plus module streams for 8.1, 8.2 and 8.3 (run
dnf module list phpto see the current list)
Distribution packages are the low-maintenance choice because they update with the rest of the system. Third-party repositories make sense when an application needs a newer branch, such as 8.4 or 8.5, or when you want the same PHP version on servers running different releases. Whichever image you deploy from the image list, the steps below cover it.
How do you install the packaged PHP-FPM on Ubuntu or Debian?
Install php-fpm together with the command line binary and the extensions your app needs; the unversioned names resolve to the release default.
sudo apt update
sudo apt install -y php-fpm php-cli php-mysql php-curl php-gd \
php-mbstring php-xml php-zip php-intl php-bcmath
php -v
systemctl status php8.3-fpm --no-pagerReplace 8.3 with the version your release ships. Configuration lives under /etc/php/8.3/, with separate fpm and cli folders, and the socket for web servers is /run/php/php8.3-fpm.sock. Installing php-fpm on its own does not add Apache, unlike the plain php metapackage.
How do you install PHP-FPM on Rocky Linux or AlmaLinux?
Pick a module stream, then install from AppStream.
sudo dnf module list php
sudo dnf module reset -y php
sudo dnf module enable -y php:8.3
sudo dnf install -y php-fpm php-cli php-mysqlnd php-gd php-mbstring \
php-xml php-intl php-opcache php-bcmath
sudo systemctl enable --now php-fpm
php -vHere the configuration is in /etc/php.ini, extension files are in /etc/php.d/, pools are in /etc/php-fpm.d/ and the default socket is /run/php-fpm/www.sock. If the stream you want is not listed, use Remi as shown below.
How do you get a newer PHP from the Ondrej PPA on Ubuntu?
Add the PPA with add-apt-repository, then install versioned packages such as php8.4-fpm.
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install -y php8.4-fpm php8.4-cli php8.4-mysql php8.4-curl \
php8.4-gd php8.4-mbstring php8.4-xml php8.4-zip php8.4-intl
php8.4 -vThe PPA targets Ubuntu LTS releases. Once it is added, plain apt upgrade also moves the default PHP packages to the PPA builds, which is expected and keeps everything consistent.
How do you add the Sury repository on Debian?
Install the signing key package, write the source line for your Debian codename and install the versioned packages.
sudo apt install -y ca-certificates curl
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
. /etc/os-release
echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $VERSION_CODENAME main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install -y php8.4-fpm php8.4-cli php8.4-mysql php8.4-mbstring php8.4-xml php8.4-intlThe $VERSION_CODENAME variable expands to bookworm on Debian 12 or trixie on Debian 13. Do not add the Ubuntu PPA to Debian; the two repositories are built for different base systems.
How do you use the Remi repository on Rocky or Alma?
Remi depends on EPEL, so enable CRB and EPEL first, then switch the PHP module to a Remi stream.
sudo dnf config-manager --set-enabled crb
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf module reset -y php
sudo dnf module enable -y php:remi-8.4
sudo dnf install -y php-fpm php-cli php-mysqlnd php-opcache php-intl
php -vOn AlmaLinux you can also run sudo dnf install -y epel-release instead of the URL. Module streams replace the base PHP in place; for two versions side by side, see running older PHP versions.
Which extensions do most applications need?
A typical CMS or framework wants the database driver, multibyte strings, XML, cURL, image handling, internationalisation, ZIP and OPcache.
mysqlormysqlnd: mysqli and PDO for MySQL and MariaDB;pgsqlfor PostgreSQLmbstring,intl,xml: text handling and locale aware formattingcurl,zip,gdorimagick: HTTP calls, archives, thumbnailsbcmathorgmp: arbitrary precision math, used by payment and crypto librariesredisorapcu: object caches
php -m # list loaded modules
apt search php8.3- | less # Debian / Ubuntu
dnf search php- | less # Rocky / Alma
sudo phpenmod -v 8.3 intl # Debian / Ubuntu: enable a moduleAfter adding an extension, restart PHP-FPM so the workers load it. Composer projects list their requirements in composer.json, which you can check with composer check-platform-reqs; the Composer guide covers the tool itself.
Which php.ini settings should you change?
Leave the shipped php.ini alone and put your values in a late-loading override file, so package updates never overwrite them.
# Debian / Ubuntu: applies to PHP-FPM 8.3 only
sudo tee /etc/php/8.3/fpm/conf.d/99-site.ini >/dev/null <<'EOF'
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 60
date.timezone = UTC
expose_php = Off
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 1
EOF
sudo systemctl restart php8.3-fpm
# Rocky / Alma: same content in /etc/php.d/99-site.ini, then
sudo systemctl restart php-fpmKeep post_max_size at least as large as upload_max_filesize, and remember the web server has its own body limit (client_max_body_size in Nginx). On a server that only changes code during deploys you can set opcache.validate_timestamps = 0 for a little extra speed, but then restart PHP-FPM after every deploy.
How do you confirm which settings PHP-FPM really uses?
The CLI and PHP-FPM read different files, so check the FPM side through a web request or its own test switch.
php --ini # files the CLI loads
sudo php-fpm8.3 -tt 2>&1 | head # Debian / Ubuntu: test FPM config
sudo php-fpm -t # Rocky / Alma
echo '<?php echo ini_get("memory_limit"), " ", php_sapi_name();' | sudo tee /var/www/example.net/public/ini.php
curl -s http://example.net/ini.php && sudo rm /var/www/example.net/public/ini.phpIf a value is not applied, look for a pool line such as php_admin_value[memory_limit], which overrides any .ini file. Never leave a full phpinfo() page online, since it reveals paths and module versions.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install PHP 8 and PHP-FPM
Do I need PHP-FPM if I use Apache?
Not strictly; Apache can run PHP as a module on Debian and Ubuntu. PHP-FPM is required for Nginx and is the default with Apache on Rocky and Alma. It also lets each site run as its own user.
Is the Ondrej PPA safe to use on a production server?
It is a long-running, widely used repository with signed packages, maintained by a Debian PHP packager. As with any third-party source, add only the repositories you need and keep them updated.
Why does php -v show a different version than my website?
The CLI default is chosen by update-alternatives on Debian and Ubuntu, while the site uses whichever FPM socket the web server points at. They can differ when several versions are installed.
Where do PHP-FPM errors go?
Pool errors go to the journal, readable with journalctl -u php8.3-fpm or journalctl -u php-fpm; script errors follow error_log in php.ini or the web server error log.
How do I install a PECL extension that has no package?
Check the repositories first, since Ondrej, Sury and Remi package most popular extensions. Otherwise install the matching php8.x-dev or php-devel package and use pecl install, then add an .ini file that loads it.