Website Down? 7 Performance Fixes That Actually Work
Fix a website down by tuning PHP, MySQL, and Nginx. Stop 502 errors with these 7 practical steps and verify results in under 10 minutes.

On this page
TL;DR — Key takeaways
- A 'website down' status often means the web server is overwhelmed, not offline; check process counts before restarting services.
- Increase PHP-FPM process limits and adjust Nginx worker connections to match your server's RAM and CPU cores.
- Identify slow database queries using the MySQL slow query log to prevent connection pool exhaustion.
- Enable OPcache and configure static asset caching to reduce backend load during traffic spikes.
- Monitor real-time resource usage with tools like `htop` and `mysqladmin` to distinguish between CPU, memory, and I/O bottlenecks.
When a customer reports a website down, the first instinct is often to restart services. That rarely helps. In support tickets I handled, the usual culprit was a full disk or an exhausted PHP-FPM process pool, not a crashed server.
This guide walks through seven practical performance tuning steps to fix and prevent website downtime. You will learn how to identify bottlenecks, adjust configuration files, and verify that your changes actually improve stability.
Diagnose the Root Cause Before Tuning
Jumping straight to configuration changes is risky. You need to know what is failing. Start with basic connectivity checks. Can you ping the server? Can you SSH in? If SSH works, the network is fine. The issue is local.
Check disk space first. A full disk causes databases to stop writing and web servers to fail. Run `df -h` to see usage. If any partition is above 90%, free up space immediately. Check inodes too with `df -i`. A full inode table prevents new file creation even if disk space remains.
Next, look at the web server error logs. For Nginx, check `/var/log/nginx/error.log`. Look for `upstream timed out` or `connect() failed` messages. These point to backend issues. For Apache, check `/var/log/apache2/error.log` or `/var/log/httpd/error_log`.
- Run `df -h` and `df -i` to check disk and inode usage.
- Check `/var/log/nginx/error.log` for upstream timeout errors.
- Verify SSH access to rule out network issues.
Tune PHP-FPM Process Pools
PHP-FPM manages PHP processes. If the pool is too small, requests queue up and time out. If it is too large, the server runs out of memory. The default configuration is often conservative.
Edit your PHP-FPM pool configuration file, usually `/etc/php/8.2/fpm/pool.d/www.conf` (adjust version as needed). Look for the `pm` section. For shared hosting or small sites, use `pm = dynamic`. Set `pm.max_children` to a value that fits your RAM. A rough formula is `(2 * CPU_cores) + 1`, but monitor memory usage to adjust.
Also check `pm.start_servers`, `pm.min_spare_servers`, and `pm.max_spare_servers`. These control how many processes are kept ready. If you see frequent spikes, increase `pm.max_spare_servers` to reduce cold-start latency. After changes, reload PHP-FPM with `systemctl reload php8.2-fpm`.
- Edit `/etc/php/8.2/fpm/pool.d/www.conf`.
- Set `pm.max_children` based on available RAM.
- Reload PHP-FPM after configuration changes.
Optimize Nginx Worker Connections
Nginx handles incoming connections. If `worker_connections` is too low, Nginx cannot accept new requests during traffic spikes. The default is often 768, which may be insufficient for busy sites.
Open `/etc/nginx/nginx.conf`. Find the `events` block. Increase `worker_connections` to 1024 or 2048. Also set `worker_rlimit_nofile` to a higher value, such as 65535, to allow more open file descriptors. This prevents `too many open files` errors.
In the `http` block, adjust `keepalive_timeout` to 65 seconds. This keeps connections open longer, reducing the overhead of repeated handshakes. Test changes with `nginx -t` before reloading. If the syntax is valid, run `systemctl reload nginx`.
- Increase `worker_connections` to 1024 or higher.
- Set `worker_rlimit_nofile` to 65535.
- Adjust `keepalive_timeout` to 65 seconds.
- Validate config with `nginx -t` before reloading.
Identify and Fix Slow Database Queries
Database bottlenecks are a common cause of website downtime. Slow queries hold connections open, exhausting the pool. New requests then queue up and time out.
Enable the MySQL slow query log if it is not already active. Edit `/etc/mysql/my.cnf` or `/etc/my.cnf.d/server.cnf`. Set `slow_query_log = 1` and `long_query_time = 1`. Restart MySQL with `systemctl restart mysql`.
Check the slow query log file, usually `/var/log/mysql/slow.log`. Look for queries with high `Rows_examined` or long `Query_time`. Add indexes to columns used in `WHERE` clauses. Use `EXPLAIN` to verify index usage. Avoid `SELECT *` in production code. Fetch only needed columns.
- Enable `slow_query_log` in MySQL config.
- Set `long_query_time` to 1 second.
- Add indexes to frequently queried columns.
- Use `EXPLAIN` to verify query plans.
Enable OPcache and Static Asset Caching
OPcache caches compiled PHP bytecode in shared memory. This reduces CPU load by avoiding repeated compilation. It is often disabled by default in production environments.
Install the OPcache extension if missing: `apt install php8.2-opcache`. Edit `/etc/php/8.2/fpm/conf.d/10-opcache.ini`. Set `opcache.enable = 1`. Set `opcache.memory_consumption` to 128 or 256 MB, depending on your RAM. Set `opcache.max_accelerated_files` to 20000 or higher for large applications.
For static assets, configure Nginx to cache CSS, JS, and images. Add a location block for `/static/` or `/assets/`. Set `expires 30d` and `add_header Cache-Control "public, immutable"`. This reduces backend requests significantly. Test with browser developer tools to confirm caching headers are present.
- Install and enable OPcache.
- Set `opcache.memory_consumption` to 128-256 MB.
- Configure Nginx to cache static assets for 30 days.
- Verify caching headers in browser developer tools.
Monitor Performance and Set Alerts
Tuning is not a one-time task. Traffic patterns change. New code releases introduce bugs. You need continuous monitoring to catch issues before they cause downtime.
Use `htop` to monitor CPU and memory usage in real time. Watch for processes consuming excessive resources. Use `mysqladmin -u root -p processlist` to see active database connections. If you see many `Sleep` states, your connection pool may be too large or queries are hanging.
Set up basic alerts. Use `cron` jobs to check disk space and send an email if usage exceeds 85%. Use `logwatch` or `fail2ban` to monitor logs for anomalies. For more advanced monitoring, consider Prometheus and Grafana. Start simple. A single disk space alert prevents most outages.
- Use `htop` to monitor CPU and memory usage.
- Check `mysqladmin processlist` for active connections.
- Set up cron-based disk space alerts.
- Consider Prometheus and Grafana for advanced monitoring.
Safe Testing and Rollback Procedures
Before applying changes to a production server, test them in a staging environment. If you do not have staging, take a backup first. Use `mysqldump` for databases and `tar` for file systems.
Apply changes one at a time. After each change, test the website. Check for errors in logs. If performance degrades, revert the change immediately. Keep a copy of original configuration files before editing.
Document every change. Note the date, time, and reason for each modification. This makes troubleshooting easier later. If a change causes issues, you can quickly identify and revert it. Never make multiple changes at once without testing.
- Take backups before making changes.
- Apply changes one at a time.
- Test website functionality after each change.
- Document all modifications with timestamps.
Quick troubleshooting checklist
- Check disk space and inode usage with `df -h` and `df -i`.
- Review Nginx error logs for upstream timeout messages.
- Verify PHP-FPM process pool status and increase `pm.max_children` if needed.
- Analyze MySQL slow query log for queries exceeding 1 second.
- Enable OPcache and set appropriate memory limits in `php.ini`.
- Configure Nginx `worker_connections` and `keepalive_timeout` for better throughput.
- Set up basic monitoring alerts for CPU, memory, and disk I/O.
FAQ
Why does my website show a 502 Bad Gateway error?
A 502 error typically means the web server (Nginx/Apache) cannot communicate with the backend application server (PHP-FPM). This usually happens when PHP-FPM processes are exhausted or the backend crashes due to memory limits or unhandled exceptions.
How many PHP-FPM processes should I configure?
A common starting point is `(2 * CPU_cores) + 1` for the `static` pool mode. However, you should monitor memory usage and adjust based on actual load. Each process consumes RAM, so ensure total memory usage stays below 80% of available RAM.
What is the first step when a website goes down?
Check if the server is reachable via ping and SSH. If accessible, immediately check disk space (`df -h`) and web server error logs. A full disk is the most common cause of sudden website outages.
Related articles
- Hosting OperationsWebsite Down Not Working: 6 Fixes That Actually WorkFix website down not working errors by checking DNS, disk space, and PHP limits. This guide provides 6 practical steps to restore uptime fast.
- Hosting OperationsWebsite Down Not Working: 7 Fixes That Actually WorkFix a website down not working error by checking DNS, disk space, and PHP limits. Stop downtime fast with these 7 practical hosting troubleshooting steps.
- Hosting OperationsWebsite Down Error: 7 Fixes That Actually WorkFix a website down error by comparing DNS, server, and code causes. Stop guessing and apply these 7 practical steps to restore uptime fast.
- Hosting OperationsWebsite Down? 7 Fixes That Actually Work in 2026Fix a website down issue fast. Check DNS, PHP, and disk space. Stop downtime with these 7 practical performance tuning steps and monitoring tips.
- Hosting OperationsWebsite Down? 5 Fixes to Restore Uptime FastFix a website down issue by checking disk space, PHP limits, and DNS. Follow these 5 steps to restore service and prevent future outages.
- Hosting OperationsWebsite Down? 7 Fixes That Actually Work in 2026Fix your website down issue fast. Check DNS, server status, and code errors with these 7 practical steps for hosting owners and engineers.