1. Why Upgrade PHP?
Every PHP version has a limited support lifecycle. Once a version reaches EOL (End of Life), it no longer receives security patches — leaving your server exposed to known vulnerabilities.
- Security — EOL PHP versions receive no security patches
- Performance — PHP 8.x is 2-3x faster than PHP 7.x in many benchmarks
- Compatibility — Frameworks like Laravel 11+ require PHP 8.2+
- New Features — JIT compiler, named arguments, union types, and fibers are all PHP 8.x features
2. Current PHP Versions and EOL Dates
| PHP Version | Released | Active Support Until | Security EOL | Status |
|---|---|---|---|---|
| PHP 8.4 | Nov 2024 | Nov 2026 | Nov 2028 | ✅ Recommended |
| PHP 8.3 | Nov 2023 | Nov 2025 | Nov 2027 | ✅ Supported |
| PHP 8.2 | Dec 2022 | Dec 2024 | Dec 2026 | ⚠️ Security only |
| PHP 8.1 | Nov 2021 | Nov 2023 | Dec 2025 | ❌ Near EOL |
| PHP 8.0 | Nov 2020 | Nov 2022 | Nov 2023 | ❌ EOL |
| PHP 7.4 | Nov 2019 | Nov 2021 | Nov 2022 | ❌ EOL |
3. Pre-Upgrade Preparation
Upgrading PHP without preparation can bring your site down immediately. These steps minimize risk.
3.1 Check Current PHP Version
php -v
# PHP 7.4.33 (cli) ...
systemctl status php7.4-fpm
3.2 Back Everything Up
# Database backup
mysqldump -u root -p --all-databases > /backup/all-db-$(date +%Y%m%d).sql
# Web files
tar -czf /backup/webroot-$(date +%Y%m%d).tar.gz /var/www/
# Nginx config
cp -r /etc/nginx /backup/nginx-$(date +%Y%m%d)
# PHP config
cp -r /etc/php /backup/php-$(date +%Y%m%d)
3.3 Check Code Compatibility
composer require --dev phpcompatibility/php-compatibility
vendor/bin/phpcs --standard=PHPCompatibility \
--runtime-set testVersion 8.3 \
/var/www/html/
3.4 Test on Staging First
Clone your production environment to a staging VM or container, install the new PHP version, and run your full test suite before touching production.
4. Installing New PHP Version on Ubuntu
Use Ondřej Surý's PPA — the de facto standard for multiple PHP versions on Ubuntu/Debian.
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install -y \
php8.3 \
php8.3-fpm \
php8.3-mysql \
php8.3-mbstring \
php8.3-xml \
php8.3-curl \
php8.3-zip \
php8.3-gd \
php8.3-intl \
php8.3-bcmath \
php8.3-opcache \
php8.3-redis
php8.3 -v
5. Configuring Nginx + PHP-FPM
5.1 Verify PHP-FPM Socket
ls /run/php/php8.3-fpm.sock
sudo systemctl start php8.3-fpm
sudo systemctl enable php8.3-fpm
5.2 Update Nginx Config to Point to PHP 8.3
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
sudo nginx -t && sudo systemctl reload nginx
6. Testing Before Switching Traffic
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo-test.php
curl -s http://localhost/phpinfo-test.php | grep -i "php version"
rm /var/www/html/phpinfo-test.php
6.2 Application Tests
# Laravel
php8.3 artisan migrate:status
php8.3 artisan config:clear
# Monitor logs
tail -f /var/log/nginx/error.log
tail -f /var/log/php8.3-fpm.log
7. Switching the PHP Version
# Edit the Nginx site config
sudo nano /etc/nginx/sites-available/mysite.conf
# Change: fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# To: fastcgi_pass unix:/run/php/php8.3-fpm.sock;
sudo nginx -t && sudo systemctl reload nginx
# Set CLI default
sudo update-alternatives --set php /usr/bin/php8.3
| Check | Expected Result |
|---|---|
php -v | Shows 8.3.x |
curl -I https://example.com | HTTP 200 |
systemctl status php8.3-fpm | active (running) |
nginx -t | syntax is ok |
8. Emergency Rollback
sudo nano /etc/nginx/sites-available/mysite.conf
# Revert: fastcgi_pass unix:/run/php/php7.4-fpm.sock;
sudo nginx -t && sudo systemctl reload nginx
sudo systemctl start php7.4-fpm
9. Monitoring After Upgrade
9.1 Watch Error Logs
sudo tail -f /var/log/php8.3-fpm.log
sudo tail -f /var/log/nginx/error.log
9.2 Check OPcache Hit Rate
php8.3 -r "
\$s = opcache_get_status();
\$hit = \$s['opcache_statistics']['hits'];
\$miss = \$s['opcache_statistics']['misses'];
\$total = \$hit + \$miss;
echo 'Hit rate: ' . round(\$hit/\$total*100, 2) . '%\n';
"
A healthy OPcache hit rate should be 90%+ after 30 minutes of warm-up traffic.
9.3 Tune PHP-FPM Pool
# /etc/php/8.3/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
10. Summary
Upgrading PHP on a Nginx VPS safely comes down to five steps:
- Prepare — backup, snapshot, compatibility check
- Install — new PHP version, PHP-FPM, and extensions
- Configure — update Nginx fastcgi_pass to the new socket
- Test — staging first, then production
- Monitor — logs, OPcache hit rate, resource usage
Done right, a PHP upgrade means zero downtime — PHP-FPM lets you run two versions simultaneously and switch with a simple Nginx reload.
Need a VPS with snapshot support and a responsive support team? Check AsiaGB Thailand VPS — SSD storage, 99% Uptime.
Frequently Asked Questions
How often should I upgrade PHP?
Follow PHP's release cycle — upgrade minor versions every 6-12 months and major versions every 1-2 years. Always upgrade before EOL with at least 3-6 months to spare for compatibility testing.
What is the difference between PHP-FPM and mod_php?
PHP-FPM (FastCGI Process Manager) runs PHP separately from the web server, enabling better resource control and multiple version pools simultaneously. mod_php embeds directly into Apache. Nginx always uses PHP-FPM.
My site slowed down after upgrading PHP — what should I check?
Check that OPcache is enabled, review PHP error logs for deprecated warnings, and run php -i | grep opcache to confirm the extension is loaded. Also verify PHP-FPM pool max_children is sufficient for your traffic.
Can I run multiple PHP versions simultaneously on Nginx?
Yes — each PHP-FPM version uses its own socket file. Configure each Nginx server block to point fastcgi_pass to the socket of the PHP version needed for that virtual host.
How do I recover if rollback fails?
Restore a VPS snapshot taken before the upgrade if your provider supports it. Otherwise restore your database backup and redeploy stable code from git. This is why pre-upgrade backups are mandatory.
What WordPress errors occur after a PHP upgrade?
Common issues include plugins using deprecated functions like create_function(), each(), and split() from older PHP, and undefined variable or type errors in PHP 8.x strict mode. Always update plugins before upgrading PHP and test on staging first.