Step-by-Step Guide to Updating PHP Version on Nginx

I am a born-again Christian and a software engineer at Korlie Limited. I'm an ALX graduate and I'm studying software engineering at Limkokwing University. I like chess ❤️
To upgrade PHP on your Nginx server to version 8.4 or any other version (8.4 will be used in this blog), follow these steps. This assumes a Debian-based system (e.g., Ubuntu or Debian), as your CLI output indicates a Debian build.
1. Add the Ondřej Surý PHP Repository (if not already added)
This trusted PPA provides the latest PHP versions (including 8.4) for Ubuntu/Debian.
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
(If you get a locale warning, prefix with LC_ALL=C.UTF-8 .)
2. Install PHP 8.4 FPM and Common Extensions
Install PHP-FPM for Nginx and extensions commonly needed for Laravel/web apps:
sudo apt install php8.4 php8.4-fpm php8.4-cli php8.4-mbstring php8.4-xml php8.4-curl php8.4-zip php8.4-gd php8.4-mysql php8.4-bcmath php8.4-intl -y
This installs co-existable versions—your existing older PHP remains unless removed.
3. Enable and Start PHP 8.4 FPM
sudo systemctl enable php8.4-fpm
sudo systemctl start php8.4-fpm
sudo systemctl status php8.4-fpm # Verify it's active
4. Update Nginx Configuration to Use PHP 8.4 FPM
Edit your site's Nginx config file (commonly /etc/nginx/sites-available/default or /etc/nginx/sites-available/your-site.conf).
Find the PHP processing block (usually location ~ \.php$ {}) and change the fastcgi_pass line to the 8.4 socket:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# Or include fastcgi_params;
fastcgi_pass unix:/run/php/php8.4-fpm.sock; # This is the key change
fastcgi_param SCRIPT_FILENAME \(document_root\)fastcgi_script_name;
include fastcgi_params;
}
The socket path is typically
/run/php/php8.4-fpm.sock(confirm withls /run/php/).If using a port instead (rare), it would be
127.0.0.1:9000or similar—check/etc/php/8.4/fpm/pool.d/www.conf.
Save the file, then test and reload Nginx:
sudo nginx -t # Test config
sudo systemctl reload nginx
5. Verify the Change
Create or edit a phpinfo.php file in your web root (e.g., /var/www/html/phpinfo.php):
<?php phpinfo(); ?>
Access it in your browser (e.g., http://your-server-ip/phpinfo.php). It should show PHP Version 8.4.16 (or similar) and Server API as FPM/FastCGI.
Delete this file afterward for security.
6. Optional: Clean Up Old PHP Version
If you no longer need the previous version (e.g., 8.3):
sudo apt purge php8.3* # Adjust version as needed
sudo apt autoremove
Restart services afterward.
Your Laravel app should now load without the Composer platform warning, as the web runtime matches the required >=8.4.0.
If issues persist (e.g., 502 errors), check logs:
sudo tail -f /var/log/nginx/error.log
sudo journalctl -u php8.4-fpm
Thank you
I hope you found this helpful ✨






