0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
JPPINTO
  • Home
  • Blog
  • Certifications
  • About
  • Contact
  • Shop
  • Gallery
  • Current Setup
Contact

Search

July 3, 2026 / Linux, Servers, Ubuntu

Install PHP-FPM and Common PHP Extensions on Ubuntu

Tags: linux, php, php-fpm, server setup, ubuntu, wordpress
Featured image for Install PHP-FPM and Common PHP Extensions on Ubuntu

PHP-FPM is the usual way to run PHP behind Nginx on Ubuntu. It gives you a long-running PHP process manager instead of starting PHP from scratch for every request.

This guide walks through installing PHP-FPM, adding common PHP extensions, detecting the installed PHP version, tuning php.ini, and restarting the right PHP-FPM service.

What the Script Does

The deployment script this article is based on:

  • Installs PHP, PHP-FPM, PHP CLI, and common extensions.
  • Detects the installed PHP major/minor version.
  • Finds the matching PHP-FPM service name.
  • Backs up the PHP-FPM and CLI php.ini files.
  • Updates upload, post, memory, and execution-time limits.
  • Enables and restarts PHP-FPM.

Install PHP and Extensions

Run:

sudo apt update

sudo apt install -y \
    php \
    php-fpm \
    php-cli \
    php-common \
    php-mysql \
    php-curl \
    php-gd \
    php-imagick \
    php-mbstring \
    php-xml \
    php-zip \
    php-intl \
    php-bcmath \
    php-redis \
    php-soap \
    php-readline \
    php-bz2 \
    php-gmp \
    php-ldap \
    php-sqlite3 \
    php-tidy \
    php-dev

Those extensions cover many common WordPress and PHP application needs, including MySQL, image handling, XML, ZIP files, Redis, SOAP, and multibyte strings.

Detect the PHP Version

Ubuntu package names include the PHP version in the FPM service name.

Detect it with:

PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')"
PHP_FPM_SERVICE="php${PHP_VERSION}-fpm"
PHP_FPM_INI="/etc/php/${PHP_VERSION}/fpm/php.ini"
PHP_CLI_INI="/etc/php/${PHP_VERSION}/cli/php.ini"

echo "PHP version: ${PHP_VERSION}"
echo "PHP-FPM service: ${PHP_FPM_SERVICE}"
echo "PHP-FPM ini: ${PHP_FPM_INI}"
echo "PHP CLI ini: ${PHP_CLI_INI}"

Example output:

PHP version: 8.3
PHP-FPM service: php8.3-fpm
PHP-FPM ini: /etc/php/8.3/fpm/php.ini
PHP CLI ini: /etc/php/8.3/cli/php.ini

Back Up PHP Config Files

Create a backup folder:

sudo mkdir -p /opt/server-backups/php
timestamp="$(date +%Y%m%d%H%M%S)"

Back up both PHP-FPM and PHP CLI settings:

sudo cp "${PHP_FPM_INI}" "/opt/server-backups/php/php.ini.fpm.before.${timestamp}.bak"
sudo cp "${PHP_CLI_INI}" "/opt/server-backups/php/php.ini.cli.before.${timestamp}.bak"

Tune PHP-FPM

This example sets:

  • upload_max_filesize = 64M
  • post_max_size = 64M
  • memory_limit = 256M
  • max_execution_time = 300

Apply them to the PHP-FPM php.ini:

sudo sed -i "s/^upload_max_filesize = .*/upload_max_filesize = 64M/" "${PHP_FPM_INI}"
sudo sed -i "s/^post_max_size = .*/post_max_size = 64M/" "${PHP_FPM_INI}"
sudo sed -i "s/^memory_limit = .*/memory_limit = 256M/" "${PHP_FPM_INI}"
sudo sed -i "s/^max_execution_time = .*/max_execution_time = 300/" "${PHP_FPM_INI}"

For CLI PHP, a common setup is to keep memory aligned but allow long-running command-line jobs:

sudo sed -i "s/^memory_limit = .*/memory_limit = 256M/" "${PHP_CLI_INI}"
sudo sed -i "s/^max_execution_time = .*/max_execution_time = 0/" "${PHP_CLI_INI}"

Restart PHP-FPM

Enable and restart the detected service:

sudo systemctl enable "${PHP_FPM_SERVICE}"
sudo systemctl restart "${PHP_FPM_SERVICE}"
sudo systemctl is-active --quiet "${PHP_FPM_SERVICE}"

Save after-change backups:

sudo cp "${PHP_FPM_INI}" "/opt/server-backups/php/php.ini.fpm.after.${timestamp}.bak"
sudo cp "${PHP_CLI_INI}" "/opt/server-backups/php/php.ini.cli.after.${timestamp}.bak"

Troubleshooting

If PHP-FPM does not restart, check:

sudo systemctl status "${PHP_FPM_SERVICE}"
sudo journalctl -u "${PHP_FPM_SERVICE}" -xe

If Nginx returns 502 Bad Gateway, confirm that the Nginx site config points to the correct PHP-FPM socket for your PHP version.

Quick Reference

PHP_VERSION="$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')"
PHP_FPM_SERVICE="php${PHP_VERSION}-fpm"
sudo systemctl restart "${PHP_FPM_SERVICE}"
sudo systemctl status "${PHP_FPM_SERVICE}"

The important habit is to detect the installed PHP version instead of hard-coding one. That makes the script work across different Ubuntu releases.

Post Views: 27
<- Install and Tune Nginx on Ubuntu for Web Hosting
Install and Configure MySQL on Ubuntu for WordPress ->

Categories

  • Active Directory (5)
  • AI (2)
  • Amazon Cloud Services (1)
  • Blazor (1)
  • C# (C-Sharp) (3)
  • CI/CD Pipelines (1)
  • Containers (4)
  • Deployment (2)
  • Development (4)
  • Docker (3)
  • General (5)
  • IIS 6.0 (4)
  • IIS 7.0 (10)
  • IIS 8.0 (1)
  • Infrastructure as Code (IaC) (1)
  • Kubernetes (3)
  • Linux (8)
  • Microsoft 365 (2)
  • MySQL (1)
  • Office 2010 (1)
  • PHP (1)
  • PowerShell (7)
  • Productivity (1)
  • Servers (8)
  • SharePoint 2007 (8)
  • SharePoint 2010 (19)
  • SharePoint 2013 (2)
  • SharePoint Online (1)
  • SMTP (4)
  • SQL Server 2008 (1)
  • SQL Server 2008 R2 (1)
  • SQL Server 2012 (2)
  • SQL Server 2019 (1)
  • Ubuntu (8)
  • Uncategorized (1)
  • URL Rewrite (2)
  • Visual Studio 2019 (1)
  • Visual Studio Code (1)
  • Windows 10 (5)
  • Windows 2003 (9)
  • Windows 2008 (18)
  • Windows 2012 (6)
  • Windows 7 (3)
  • Windows Firewall (1)
  • Windows Vista (1)
  • WordPress (3)
  • WP-CLI (3)

Recent Posts

  • Create an Nginx Default Catch-All Site on Ubuntu
  • Install and Configure Redis on Ubuntu for Local Object Cache
  • Install and Configure MySQL on Ubuntu for WordPress
  • Install PHP-FPM and Common PHP Extensions on Ubuntu
  • Install and Tune Nginx on Ubuntu for Web Hosting

Advertisement

Tags

ai coding agents bash developer workflow dev to production exe permissions externalize blob externalize sharepoint data filezilla server firewall rules filazilla full installation http redirect https https redirect IIS iis7 iis 7 installation IIS installation index server configuration installing cumulative updates linux load balance central administration microsoft 365 nginx nlb powerpoint powershell redirect http to https server setup sharepoint 2010 cumulative updates sharepoint 2010 farm build sharepoint 2010 farm configuration sharepoint 2010 farm installation sharepoint data externalization SMTP storagepoint ubuntu web server windows Windows 7 windows firewall configuration windows server 2008 wlbs wordpress wp-cli x86
© 2026 JPPinto.com. All rights reserved.