Install PHP on Linux is one of the most common hosting searches — usually right before WordPress, Laravel, or a legacy admin panel. Modern stacks use
PHP-FPM behind Nginx or Apache, not embedded mod_php inside every Apache worker.
After PHP is running, pair with Nginx reverse proxy,
MariaDB, and
502 troubleshooting when FPM is down.
Choose PHP-FPM for New Servers
PHP-FPM runs as a separate service with its own worker pool — easier to tune and isolate than mod_php.

Install on Ubuntu / Debian
Use distribution packages unless you need a bleeding-edge minor version from a third-party repo.
sudo apt update
sudo apt install -y php-fpm php-cli php-mysql php-curl php-mbstring php-xml
php -v
sudo systemctl enable --now php8.3-fpm # version may vary

Install on AlmaLinux / Rocky
Enable AppStream PHP or Remi when you need newer minors; always start php-fpm.
sudo dnf install -y php php-fpm php-mysqlnd php-cli
sudo systemctl enable --now php-fpm
php -v

php-fpm Pool Basics
Default pool listens on a Unix socket; Nginx must use the same path and socket permissions.
; listen = /run/php/php8.3-fpm.sock
; listen.owner = www-data
; listen.group = www-data

Extensions You Actually Need
WordPress wants mysql/mysqli, curl, mbstring, xml, zip. Install only what apps require.
php -m | grep -E 'mysqli|curl|mbstring|xml'

Nginx fastcgi_pass
Typical pattern: try_files then pass .php to the FPM socket.
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}

Verify and Harden
Hit a test page, then remove phpinfo() from production.

Quick Reference
- Package:
php-fpm+ app extensions - Nginx:
fastcgi_pass unix:... - 502 often means php-fpm stopped or wrong socket path
Related tutorials
Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.