How to Migrate cPanel Accounts Between Servers Using WHM Transfer Tool (Zero-Downtime Guide) Moving live…
The Complete Linux Web Server Error Troubleshooting Guide (Fixing 500, 502, 503, 504 & 403 Errors)

When a website on a Linux VPS goes down with a 500, 502, 503, 504, or 403 HTTP status code, guessing at random configuration tweaks wastes critical recovery time. Knowing how to troubleshoot Linux web server errors systematically lets you pinpoint the exact failing layer—web server, PHP-FPM pool, reverse proxy upstream, database, or filesystem permission—in under two minutes.
Every HTTP error code points to a distinct failure boundary in your stack. A 403 means Nginx or Apache explicitly refused access to a resource it found. A 500 means the web server or application crashed internally while processing the request. A 502, 503, or 504 means your front-end proxy (Nginx, Apache, or Cloudflare) could not get a valid, timely response from an upstream worker or backend service.
This diagnostic playbook covers how to troubleshoot Linux web server errors across Ubuntu, Debian, AlmaLinux, and Rocky Linux servers—mapping each status code to its exact log files, root causes, verification commands, and permanent configuration fixes.

Master Diagnostic Matrix: How to Troubleshoot Linux Web Server Errors Fast
Before editing configuration files, match the HTTP status code in your browser to the exact system layer and log path below. Following a structured triage order is the fastest way to troubleshoot Linux web server errors without introducing new syntax mistakes:
| HTTP Code | Primary Meaning | Most Common Root Causes on a VPS | First Log to Inspect |
|---|---|---|---|
| 500 Internal Server Error | Application or web server crashed internally | Fatal PHP exception, broken .htaccess directive, exhausted PHP memory_limit, full disk/inodes |
PHP error log & web server error.log |
| 502 Bad Gateway | Proxy received an invalid or empty upstream response | PHP-FPM stopped or killed by OOM, wrong Unix socket path, backend app (Node/Docker) down, undersized FastCGI buffers | Nginx error.log & dmesg -T |
| 503 Service Unavailable | Server is overloaded or in maintenance mode | pm.max_children worker pool full, Apache MaxRequestWorkers reached, stuck .maintenance file, rate limit triggered |
PHP-FPM pool log & web server error.log |
| 504 Gateway Timeout | Upstream service took too long to respond | Slow database query, heavy import/cron script hitting fastcgi_read_timeout or max_execution_time |
Nginx error.log & MySQL slow query log |
| 403 Forbidden | Server understood the request but refused access | Wrong chown/chmod permissions, missing parent directory +x bit, missing index file, SELinux or WAF block |
Web server error.log & ModSecurity audit log |
Exact Log File Locations Across Linux Distributions
Keep these distribution-specific log paths handy whenever you troubleshoot Linux web server errors over SSH:
- Nginx (Ubuntu, Debian, AlmaLinux, Rocky Linux):
/var/log/nginx/error.logand/var/log/nginx/access.log - Apache on Ubuntu and Debian:
/var/log/apache2/error.logand/var/log/apache2/access.log - Apache on AlmaLinux and Rocky Linux:
/var/log/httpd/error_logand/var/log/httpd/access_log - PHP-FPM Service Logs:
/var/log/php8.3-fpm.log(adjust version number to8.1,8.2, or8.4) or/var/log/php-fpm/www-error.logon RHEL-based systems - MariaDB / MySQL Logs:
/var/log/mysql/error.logor/var/log/mariadb/mariadb.log
To watch errors in real time while reproducing an outage in your browser, stream the last 30 lines of your web server and PHP-FPM logs simultaneously:
sudo tail -n 30 -f /var/log/nginx/error.log /var/log/php8.3-fpm.log
Once you capture the exact error line, jump directly to the matching section below.
1. How to Fix 500 Internal Server Error
An HTTP 500 Internal Server Error means your web server accepted the connection, handed the request off to a configuration parser or PHP runtime, and encountered an unhandled failure. When you troubleshoot Linux web server errors returning status 500, check these four causes in order.
Cause 1: Corrupted or Unsupported .htaccess Directives (Apache)
On Apache servers, a single typo in a site’s root .htaccess file—or an unsupported directive like php_value when running PHP-FPM instead of mod_php—triggers an immediate 500 error across the entire domain. Check your Apache error log first:
sudo tail -n 20 /var/log/apache2/error.log
If you see messages such as “Invalid command ‘php_value'” or “RewriteCond: bad flag delimiters”, temporarily rename .htaccess to confirm whether it is the culprit:
mv /var/www/html/.htaccess /var/www/html/.htaccess.disabled
Reload your browser. If the homepage loads immediately, inspect the backup file line by line, move any PHP directives into a .user.ini file or your PHP-FPM pool configuration, and restore a clean .htaccess.
Cause 2: Fatal PHP Exceptions and Exhausted memory_limit
When engineers troubleshoot Linux web server errors on high-traffic PHP applications, exhausted memory limits are one of the first bottlenecks to check. If a PHP script runs out of memory or hits an uncaught fatal error while display_errors is turned off for security, PHP returns a blank white screen alongside an HTTP 500 status code. Search your PHP-FPM log for fatal entries:
sudo grep -iE "Fatal error|Allowed memory size" /var/log/php8.3-fpm.log | tail -n 15
If you see Allowed memory size of 134217728 bytes exhausted, your script hit PHP’s default 128M memory ceiling. Open your active PHP-FPM php.ini file and raise memory_limit to 256M or 512M:
sudo nano /etc/php/8.3/fpm/php.ini
Locate and update these directives:
memory_limit = 256M
log_errors = On
error_log = /var/log/php8.3-fpm-errors.log
Save the file and restart PHP-FPM to apply the new memory limit:
sudo systemctl restart php8.3-fpm
Cause 3: Broken WordPress Plugins or Themes
Another common reason administrators troubleshoot Linux web server errors on WordPress sites is a faulty plugin update or PHP version mismatch. If you have WP-CLI installed on your VPS, deactivate all plugins safely from your site root without touching the database manually:
cd /var/www/html
wp plugin deactivate --all --allow-root
If WP-CLI is not installed, rename the plugins folder temporarily to force WordPress to bypass every active plugin:
mv /var/www/html/wp-content/plugins /var/www/html/wp-content/plugins.disabled
Once the site comes back online, rename the directory back to plugins and re-enable plugins one by one to isolate the broken extension.
Cause 4: Full Root Disk or Exhausted Inodes
Always check disk and inode capacity when you troubleshoot Linux web server errors, because full partitions break session writes immediately. Even when your code and configuration files are completely valid, PHP throws a 500 error if it cannot write session files, temporary uploads, or cache entries to disk:
df -h
df -i
If either Use% or IUse% reads 100% on / or /tmp, clear old journal logs, unused APT archives, or stale PHP session files right away:
sudo journalctl --vacuum-size=200M
sudo apt clean
2. How to Fix 502 Bad Gateway Errors
An HTTP 502 Bad Gateway means your reverse proxy or web server (Nginx, Apache, or Cloudflare) connected to an upstream backend—such as PHP-FPM, Node.js, Python, or a Docker container—and received a broken, empty, or refused connection in return. When you troubleshoot Linux web server errors showing 502, verify these four upstream links.
Cause 1: PHP-FPM Stopped or Killed by the Linux OOM Killer
Whenever you troubleshoot Linux web server errors after a sudden traffic spike, check whether the Linux Out-Of-Memory (OOM) killer terminated PHP-FPM. Check the service status first:
sudo systemctl status php8.3-fpm
If the output shows inactive (dead) or failed, check your kernel ring buffer to see if low RAM triggered an OOM kill:
sudo dmesg -T | grep -iE "oom|killed process"
Restart PHP-FPM immediately to restore traffic:
sudo systemctl start php8.3-fpm
If your VPS has 1 GB or 2 GB of physical RAM and lacks swap space, adding a 2 GB swap file prevents sudden OOM crashes during traffic surges—follow our step-by-step tutorial on how to add swap space Linux to protect your worker processes.
Cause 2: Unix Socket or TCP Port Mismatch Between Nginx and PHP-FPM
Socket mismatches frequently appear when you troubleshoot Linux web server errors right after upgrading PHP versions on Ubuntu or Debian. Nginx often continues forwarding requests to an old Unix socket path that no longer exists, generating connect() to unix:/run/php/php8.1-fpm.sock failed (2: No such file or directory) in /var/log/nginx/error.log.
Inspect the active listen socket defined in your PHP-FPM pool configuration:
grep -E "^listen" /etc/php/8.3/fpm/pool.d/www.conf
Confirm that the exact socket path and ownership permissions match your Nginx user (www-data on Ubuntu/Debian or nginx on AlmaLinux/Rocky Linux):
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Next, verify that your Nginx server block points fastcgi_pass to that exact socket path—documented in the official Nginx FastCGI module documentation:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
Test and reload both services:
sudo nginx -t && sudo systemctl reload nginx php8.3-fpm
Cause 3: Reverse Proxy Backend Down or IPv4 vs. IPv6 Loopback Mismatch
If you reverse-proxy Node.js, Python, or Docker apps and need to troubleshoot Linux web server errors, verify the backend listener address and confirm the process is active on port 3000 or 8080:
ss -tulpn | grep -E ":3000|:8080"
A subtle trap occurs when Nginx proxies to http://localhost:3000: Linux resolves localhost to IPv6 ([::1]:3000) first, while many Node.js and Docker apps bind strictly to IPv4 (127.0.0.1:3000), causing Nginx to fail with Connection refused and return a 502 error. Always use an explicit IPv4 loopback address in your Nginx proxy_pass directive:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Cause 4: Undersized FastCGI or Proxy Response Headers
Header buffer overflows are another hidden culprit when you troubleshoot Linux web server errors on authentication-heavy sites. When WordPress plugins, OAuth logins, or WooCommerce sessions send large authentication cookies in HTTP response headers, Nginx rejects the oversized header with upstream sent too big header while reading response header from upstream and serves a 502 Bad Gateway.
Increase the FastCGI and proxy buffer sizes inside your Nginx http or server block:
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
proxy_buffers 16 16k;
proxy_buffer_size 32k;
Run sudo nginx -t and reload Nginx—your large header responses will pass through cleanly.

3. How to Fix 503 Service Unavailable Errors
An HTTP 503 Service Unavailable means your web server is running, but the backend worker pool is saturated or an intentional maintenance/rate-limit rule is blocking new requests. When you troubleshoot Linux web server errors returning 503, inspect worker capacity first.
Cause 1: PHP-FPM pm.max_children Worker Pool Exhaustion
Learning how to troubleshoot Linux web server errors under load requires sizing pm.max_children accurately for your VPS memory. Every concurrent PHP request requires one dedicated PHP-FPM worker process, and when slow uncached pages occupy every worker, incoming visitors receive a 503 error. Confirm this in your PHP-FPM log:
sudo grep "server reached pm.max_children" /var/log/php8.3-fpm.log | tail -n 10
To size pm.max_children accurately without crashing your server’s RAM, measure the average memory footprint of a single running PHP-FPM worker:
ps --no-headers -o "rss,cmd" -C php-fpm8.3 | awk '{ sum+=$1 } END { printf ("Avg worker RAM: %.1f MB\n", sum/NR/1024) }'
Use the formula (Available RAM for PHP ÷ Average Worker RAM) based on the official PHP-FPM pool configuration guide and the sizing table below:
| Total VPS RAM | RAM Reserved for OS & MariaDB | Available RAM for PHP-FPM | Recommended pm.max_children (at ~60 MB/worker) |
|---|---|---|---|
| 1 GB VPS | ~500 MB | ~500 MB | 8 |
| 2 GB VPS | ~800 MB | ~1,200 MB | 18 – 20 |
| 4 GB VPS | ~1,400 MB | ~2,600 MB | 40 – 45 |
| 8 GB VPS | ~2,500 MB | ~5,500 MB | 85 – 90 |
Update /etc/php/8.3/fpm/pool.d/www.conf with your calculated values:
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
Setting pm.max_requests = 500 automatically recycles workers after 500 requests, preventing gradual memory leaks from inflating your RAM usage over time.
Cause 2: Apache MaxRequestWorkers Saturation
If you run Apache and need to troubleshoot Linux web server errors during traffic bursts, check your MPM worker ceiling next. Search /var/log/apache2/error.log for AH00161: server reached MaxRequestWorkers setting, inspect /etc/apache2/mods-available/mpm_event.conf, and raise MaxRequestWorkers proportionally to your free server memory before restarting Apache.
Cause 3: Stuck WordPress .maintenance File or Nginx Rate Limits
Stale maintenance locks and aggressive rate limits also surface when you troubleshoot Linux web server errors on busy domains. If a WordPress plugin or core update gets interrupted mid-install, WordPress leaves a hidden .maintenance file in your document root that forces every visitor onto a 503 maintenance screen. Check for and remove the stale file:
ls -la /var/www/html/.maintenance
rm -f /var/www/html/.maintenance
Also check Nginx for strict limit_req_zone directives returning status 503 when aggressive crawlers or legitimate API bursts hit your endpoints—raising the burst=20 nodelay allowance prevents false-positive 503 blocks during normal page loads.
4. How to Fix 504 Gateway Timeout Errors
An HTTP 504 Gateway Timeout occurs when your web server establishes a valid connection to PHP-FPM or an upstream application, waits for a response, and cuts the connection off because the backend took too long to finish. When you troubleshoot Linux web server errors involving timeouts, trace where the delay is happening.
Cause 1: Nginx fastcgi_read_timeout or proxy_read_timeout Cutoffs
Proxy read cutoffs are the first setting to inspect when you troubleshoot Linux web server errors caused by long-running imports or reports. By default, Nginx waits 60 seconds for PHP-FPM or a reverse-proxied backend to return data before terminating the request with upstream timed out (110: Connection timed out) while reading response header from upstream.
Increase the read timeout inside your Nginx PHP or proxy location block:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_read_timeout 300s;
fastcgi_send_timeout 300s;
}
If you are using Nginx as a reverse proxy in front of Node.js or Python, set proxy_read_timeout 300s; and proxy_connect_timeout 60s; in the proxy location block and reload Nginx.
Cause 2: PHP max_execution_time and FPM request_terminate_timeout
Always align PHP timeouts alongside Nginx when you troubleshoot Linux web server errors on long background scripts. Raising Nginx’s timeout alone will not help if PHP itself terminates the script at 30 seconds:
# In /etc/php/8.3/fpm/php.ini:
max_execution_time = 300
max_input_time = 300
# In /etc/php/8.3/fpm/pool.d/www.conf:
request_terminate_timeout = 300s
Restart PHP-FPM with sudo systemctl restart php8.3-fpm so both layers honor the 300-second ceiling.
Cause 3: Locked or Unindexed MariaDB / MySQL Queries
Database table locks are a major reason developers troubleshoot Linux web server errors during peak write operations. Often, PHP workers time out because they are stuck waiting on a locked table or an unindexed query scanning millions of rows. Connect to MariaDB or MySQL and inspect live running queries:
sudo mysql -e "SHOW FULL PROCESSLIST;"
Look for queries stuck in Sending data or Waiting for table metadata lock for more than 10 seconds. You can terminate a runaway query ID safely with KILL QUERY <Id>; and enable the slow query log in /etc/mysql/mariadb.conf.d/50-server.cnf to identify missing indexes permanently.
Cause 4: Cloudflare 100-Second Edge Timeout (Error 524)
Edge proxy timeouts also come into play when you troubleshoot Linux web server errors behind Cloudflare. Cloudflare enforces a hard 100-second HTTP response timeout on Free, Pro, and Business plans regardless of your origin Nginx settings. For migrations, large backups, or bulk imports that run longer than 100 seconds, execute them directly over SSH via WP-CLI or a background system cron job instead of a browser HTTP request.
5. How to Fix 403 Forbidden Errors
Unlike the 5xx server errors above, an HTTP 403 Forbidden error means Nginx or Apache processed the request properly, located the target path, and deliberately denied access due to ownership, directory traversal, index configuration, or security policy rules. When you troubleshoot Linux web server errors returning 403, work through these four checks.
Cause 1: Incorrect File Ownership and Recursive Permissions
File ownership mismatches are the most frequent reason beginners troubleshoot Linux web server errors after uploading files via SFTP. Uploading site files as root or a custom user often leaves files unreadable by the web server process (www-data on Ubuntu/Debian, or nginx/apache on AlmaLinux/Rocky Linux). Reset ownership and apply standard 755 directory and 644 file permissions—never use unsafe chmod 777 permissions:
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} +
sudo find /var/www/html -type f -exec chmod 644 {} +
Cause 2: Missing Parent Directory Execute (+x) Traverse Rights
Parent directory permissions often trip up administrators who troubleshoot Linux web server errors in custom web roots. Even when files inside /var/www/html have 644 permissions, Linux blocks the web server if any parent directory along the path lacks execute (x) traverse permission. Audit the full path in one command:
namei -m /var/www/html/index.php
Every parent directory (/var, /var/www, /var/www/html) must grant execute access (such as drwxr-xr-x). If a custom directory under /home/deploy/site shows drwx------, add traverse permission with sudo chmod o+x /home/deploy.
Cause 3: Missing Index File or Case-Sensitivity Mismatch
Missing index files and filename case sensitivity also force teams to troubleshoot Linux web server errors on fresh deployments. When directory indexing (autoindex) is disabled—which is standard on production servers—requesting https://yourdomain.com/ returns a 403 Forbidden error if none of the files listed in your Nginx index or Apache DirectoryIndex directive exist in your web root. Confirm that index.php or index.html is present in lowercase, as Linux filesystems treat Index.html and index.html as completely different files.
Cause 4: Apache 2.4 Access Directives, SELinux, or WAF Rules
Access directives and mandatory access control modules are the final layer when you troubleshoot Linux web server errors on RHEL or Ubuntu. On Apache 2.4+, ensure your VirtualHost directory block uses modern Require all granted syntax rather than deprecated Apache 2.2 rules—as detailed in the official Apache HTTP Server core documentation. On AlmaLinux and Rocky Linux, restore proper SELinux web contexts after moving files from a home directory:
sudo restorecon -R -v /var/www/html
For a deeper walkthrough of SELinux contexts, AppArmor profiles, and Nginx server block rules, see our dedicated guide on how to fix 403 Forbidden and Permission Denied errors on Nginx and Apache. If the 403 happens exclusively when saving code snippets inside WordPress, see how to resolve not a valid JSON response WordPress WAF errors.
Post-Fix Verification & Auto-Recovery Hardening
After applying any configuration fix to troubleshoot Linux web server errors, always follow a three-step verification sequence before closing your SSH session so a hidden typo never leaves your server offline:
- Validate configuration syntax before reloading: Run
sudo nginx -tfor Nginx,sudo apachectl configtestfor Apache, andsudo php-fpm8.3 -tfor PHP-FPM. Only reload services once every test printssyntax is ok. - Verify the live HTTP response header from the CLI: Test your domain locally with
curl -I -L https://yourdomain.comand confirm the final response returnsHTTP/2 200instead of a cached redirect or error status. - Enable automatic systemd crash recovery: Per the official systemd service unit manual, configure PHP-FPM and MariaDB to restart automatically within 5 seconds if a sudden traffic spike ever terminates them:
sudo systemctl edit php8.3-fpm
Add these two lines in the override editor, save, and exit:
[Service]
Restart=always
RestartSec=5s
Reload the systemd manager with sudo systemctl daemon-reload so your application workers recover automatically without manual intervention.
Frequently Asked Questions
What is the fastest way to tell whether a 502 or 504 error comes from Cloudflare or my VPS?
When you troubleshoot Linux web server errors behind a CDN, check the error page branding and test your origin IP directly. A Cloudflare-branded 502 or 504 error page displays a diagram showing Browser → Cloudflare → Host with a green checkmark on Cloudflare and a red X on Host—confirming Cloudflare is online and your VPS origin failed to respond. Confirm from your terminal by bypassing Cloudflare with curl -I --resolve yourdomain.com:443:YOUR_VPS_IP https://yourdomain.com.
Why do I get a 502 Bad Gateway right after updating PHP on Ubuntu?
Installing a newer PHP version (such as PHP 8.3) creates a new Unix socket at /run/php/php8.3-fpm.sock, while your existing Nginx site configuration still points fastcgi_pass to the old php8.1-fpm.sock or php8.2-fpm.sock path. Update the fastcgi_pass line in your Nginx server block to match the newly installed PHP-FPM socket and reload Nginx.
Can a full disk cause 500, 502, and 503 errors at the same time?
Yes—disk exhaustion is a classic multi-service failure you will encounter when you troubleshoot Linux web server errors on smaller VPS plans. When root disk usage or inode usage hits 100%, MariaDB refuses to write temporary tables or binary logs, PHP-FPM cannot create session files, and Nginx cannot buffer large upstream responses—triggering cascading 500 and 502 errors across every site on the VPS. Checking df -h and df -i should always be part of your initial triage.
Why does my site throw 503 errors during traffic spikes even when CPU usage is low?
A 503 error with low CPU usage almost always means your PHP-FPM worker pool (pm.max_children) is completely occupied waiting on slow external API calls, uncached WordPress pages, or database locks. While workers sit idle waiting on I/O, CPU usage stays low, yet new visitors cannot get a free PHP worker. Enabling page caching and tuning pm.max_children resolves the bottleneck immediately.
Should I restart the entire VPS when I encounter a 500 or 502 error?
No—rebooting clears logs and hides the root cause when you troubleshoot Linux web server errors. If a broken configuration file caused the outage, your web server will fail to start after reboot anyway. Always inspect your error logs first and restart only the specific affected service (nginx, apache2, php8.3-fpm, or mariadb) after testing its configuration syntax.
How can I prevent Out-Of-Memory 502 crashes on a 1 GB or 2 GB VPS?
Combine three safeguards: add a 2 GB swap file as an overflow safety net, cap PHP-FPM pm.max_children according to your available RAM (8 workers on 1 GB RAM, 18–20 workers on 2 GB RAM), and enable page caching so Nginx serves static HTML from memory without invoking PHP for every visitor.
Conclusion
Learning how to troubleshoot Linux web server errors systematically turns stressful downtime into a repeatable diagnostic routine. By checking your web server and PHP-FPM logs first, matching each HTTP code (500, 502, 503, 504, or 403) to its exact architectural boundary, and validating syntax before reloading services, you can restore production websites quickly and prevent repeat outages.
If you are building or securing a new server environment, pair this troubleshooting guide with our step-by-step tutorials on how to set up SSH keys on a Linux VPS, how to install CloudPanel on an Ubuntu VPS, and how to install Docker on Ubuntu 24.04.
