Slow websites kill user experience and SEO rankings. If you’re running PHP (especially WordPress), optimizing performance is critical.
In this guide, you’ll learn how to speed up PHP using real-world techniques.
🔹 Check Your Current PHP Version
php -v
👉 Always use PHP 8.1+ or 8.2 for best performance.
🔹 Enable OPcache (Huge Speed Boost)
OPcache stores compiled PHP in memory.
Edit your config:
sudo nano /etc/php/8.2/fpm/php.ini
Enable:
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.validate_timestamps=1
Restart PHP:
sudo systemctl restart php8.2-fpm
🔹 Use PHP-FPM (Instead of mod_php)
PHP-FPM is faster and more efficient.
Install:
sudo apt install php8.2-fpm
Nginx example:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
🔹 Optimize php.ini Settings
memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 64M
post_max_size = 64M
🔹 Use Caching (Critical)
- Page caching (WordPress plugins)
- Object caching (Redis / Memcached)
Example Redis install:
sudo apt install redis-server php-redis
🔹 Reduce Database Load
- Optimize queries
- Add indexes
- Clean unused data
🔹 Use CDN (Optional but Powerful)
Use services like Cloudflare to:
- Cache static files
- Reduce latency
- Protect your server
🔹 Monitor Performance
Tools:
htoptopnetdata- slow query logs
🔹 Pro Tips
- Disable unused PHP extensions
- Use HTTP/2 or HTTP/3
- Keep PHP updated
🔹 Conclusion
With these optimizations, you can:
- ⚡ Reduce load times
- 📉 Lower server usage
- 🚀 Handle more traffic