Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Answer

sudo apt update
apt-cache policy php-fpm
sudo apt install php-fpm php-cli
php -v

The unversioned names point to the PHP version your release ships: PHP 8.3 on Ubuntu 24.04 and PHP 8.5 on Ubuntu 26.04. The same commands work on Debian, which ships its own PHP version per release.

Avoid sudo apt install php on an Nginx server: that metapackage prefers the Apache module, so it installs Apache as well. Install php-fpm instead.

PHP-FPM or mod_php

PHP-FPMmod_php
Runs asIts own servicePart of Apache
Web serversNginx, ApacheApache only
Apache modeeventprefork
Pools per siteYesNo

PHP-FPM is the usual choice: it runs each site's pool under its own user and lets Apache use its faster event mode.

Connect PHP-FPM to Nginx

Find the socket name with ls /run/php/. The examples on this page use 8.3, the version on Ubuntu 24.04; on Ubuntu 26.04 write 8.5, and in general the version your server shows.

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}

Test with sudo nginx -t, then sudo systemctl reload nginx. If PHP pages fail, see 403 Forbidden in Nginx and 503 Service Unavailable.

Connect PHP-FPM to Apache

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo apachectl configtest
sudo systemctl reload apache2

Common Extensions

sudo apt install php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl php-bcmath
php -m
  • php-mysql: MySQL and MariaDB through mysqli and PDO.
  • php-curl: HTTP requests to other services.
  • php-gd: image resizing.
  • php-mbstring and php-intl: multibyte text and locale handling.
  • php-xml and php-zip: XML parsing and archives, needed by many frameworks and by Composer.

php -m lists the loaded modules. After installing extensions, restart PHP-FPM with sudo systemctl restart php8.3-fpm.

Where php.ini Lives

  • PHP-FPM (websites): /etc/php/8.3/fpm/php.ini
  • Command line: /etc/php/8.3/cli/php.ini
  • Apache module: /etc/php/8.3/apache2/php.ini
  • Pool settings: /etc/php/8.3/fpm/pool.d/www.conf

Each one has a conf.d folder next to it for extension settings. The command line and PHP-FPM read different files, so php --ini shows only the command line's. Settings that come up often are upload_max_filesize, post_max_size, memory_limit, and max_execution_time. After a change, test with sudo php-fpm8.3 -t and apply it with sudo systemctl reload php8.3-fpm.

Several PHP Versions Side by Side

The Ubuntu archive carries one PHP line per release. Other versions come from third-party repositories or PPAs that package each version under its own name. Adding one means trusting its publisher with root on the server, so first check whether the application runs on the version Ubuntu ships, or whether a newer Ubuntu release ships the one you need. If you do add one, see add-apt-repository command not found. Each installed version then has its own FPM service and socket, each site points to the socket of its version, and sudo update-alternatives --config php picks the command-line default. Containers are another way to keep versions apart; see how to install Docker on Ubuntu.

AlmaLinux and Rocky Linux

Install with sudo dnf install php-fpm php-cli, then start it with sudo systemctl enable --now php-fpm. The settings are in /etc/php.ini and the pools in /etc/php-fpm.d/. To manage PHP libraries for a project, see what is Composer.

Was this answer helpful?
Loading...