Quick answer: Install PHP with FPM — sudo apt install php-fpm on Ubuntu/Debian or sudo dnf install php-fpm on AlmaLinux/Rocky — plus the extensions your app needs (e.g. php-mysql, php-xml, php-curl). PHP-FPM pairs with Nginx; Apache can use FPM or mod_php.
Overview
PHP powers WordPress, Laravel, WHMCS and most of the web. Modern setups run PHP-FPM (FastCGI Process Manager) behind a web server. Distribution repositories ship one default PHP version; if you need a specific newer one on Ubuntu, the widely used ppa:ondrej/php PPA provides all supported versions side by side.
Before you start
- A web server installed (Nginx or Apache).
- Know which PHP version and extensions your application requires.
Step-by-step guide
- Install PHP-FPM and common extensions:
# Ubuntu/Debian sudo apt -y install php-fpm php-mysql php-xml php-curl php-mbstring php-zip php-gd # AlmaLinux/Rocky sudo dnf -y install php-fpm php-mysqlnd php-xml php-mbstring php-zip php-gd - (Ubuntu, specific version) add the PPA first:
sudo add-apt-repository ppa:ondrej/php sudo apt update && sudo apt -y install php8.3-fpm - Enable the service (name includes the version on most systems):
sudo systemctl enable --now php8.3-fpm # or php-fpm on RHEL family - Wire it to Nginx — in your server block:
Thenlocation ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }sudo nginx -t && sudo systemctl reload nginx. - Verify:
php -vand a phpinfo test file (delete it afterwards).
Common issues
- 502 from Nginx: the
fastcgi_passsocket path doesn't match your PHP version — check/run/php/. - Missing extension errors: install
php<ver>-<ext>and restart FPM. - Upload/memory limits: edit
php.ini(seephp --inifor the path), then restart the FPM service.
When to contact support
PHP tuning is application-level work on an unmanaged server; contact us via ticket if the server itself misbehaves at the platform level.
Frequently asked questions
How do I install a specific PHP version on Ubuntu?
Add the widely used ondrej/php PPA, run apt update, then install the exact version you need, for example php8.3-fpm. Multiple versions can coexist side by side.
What is PHP-FPM and do I need it?
PHP-FPM is the FastCGI process manager that runs PHP for Nginx and modern Apache setups. It is the standard, fastest way to serve PHP applications today.
Why does Nginx return 502 Bad Gateway with PHP?
Usually the fastcgi_pass socket path does not match your installed PHP version. Check the actual socket name under /run/php/ and update the server block to match.
Related articles
Ready to get started? Order a VPS at Cloud2Y →
