Fix Segmentation Faults on WordPress Apache PHP
In this article
Segmentation faults on a WordPress site running Apache and PHP are sudden crashes where the web server process dies, often returning a 500 error or an empty page. This guide walks you through the most common causes and the exact steps to diagnose and fix them, from checking error logs to adjusting PHP memory limits and disabling problematic plugins.
What You'll Need
- SSH (terminal) access to your server
- sudo or root privileges
- Basic familiarity with the command line
- Access to your WordPress admin dashboard (if the site still loads occasionally)
Step-by-Step
- Check the Apache error log. The first place to look is the Apache error log. On most Linux systems it's at
/var/log/apache2/error.log(Debian/Ubuntu) or/var/log/httpd/error_log(RHEL/CentOS). Runsudo tail -n 100 /var/log/apache2/error.logand look for lines containing "segfault" or "signal 11". Note the exact file and line number if mentioned – that's your clue. - Check PHP's error log. PHP often logs fatal errors separately. Look in
/var/log/php*.logor check yourphp.iniforerror_logsetting. If the log is empty, temporarily setdisplay_errors = Onanderror_reporting = E_ALLin php.ini, restart Apache, and reproduce the crash. - Reproduce the crash. Try to trigger the segfault by browsing specific pages. If it happens on a particular page, note the URL. If it's random, it's likely a resource issue or a plugin conflict. Use
curl -v http://yourdomain.comfrom the command line to see if you can get a consistent response. - Disable all plugins temporarily. Rename the
wp-content/pluginsdirectory toplugins_offvia FTP or SSH:mv wp-content/plugins wp-content/plugins_off. Then try loading the site again. If the crash stops, one of your plugins is the culprit. Re-enable plugins one by one (rename back, then deactivate each in wp-admin) to find the offender. - Switch to a default theme. If plugins aren't the issue, your theme might be. Rename the active theme folder in
wp-content/themesto something else. WordPress will fall back to a default theme. If the segfault disappears, your theme has a bug. - Increase PHP memory limit. A low memory limit can cause crashes. Edit your
php.inifile (find it withphp -i | grep php.ini). Setmemory_limit = 256M(or higher, up to 512M for large sites). Also setmax_execution_time = 300. Restart Apache:sudo systemctl restart apache2(orhttpd). - Check for corrupted opcode cache. If you use OPcache, a corrupted cache can cause segfaults. Add
opcache.validate_timestamps=1andopcache.revalidate_freq=0to your php.ini (or just clear the cache by restarting PHP-FPM or Apache). If the problem goes away, consider updating OPcache to the latest version. - Update PHP and Apache. Outdated versions have known segfault bugs. Check your versions:
php -vandapache2 -v. Update to the latest stable release using your package manager (e.g.,sudo apt update && sudo apt upgradeon Debian/Ubuntu). - Check for incompatible PHP extensions. A badly written or outdated extension (like ionCube, Xdebug, or a third-party opcache) can crash PHP. Temporarily comment out all non-essential extensions in php.ini (lines starting with
extension=), restart Apache, and see if the crash stops. If it does, re-enable them one by one. - Examine system resources. Segfaults can happen when the server runs out of memory. Run
free -hto see available RAM. If it's consistently low, consider increasing swap space or upgrading your plan. Also check disk space withdf -h– a full disk can cause crashes. - Review Apache modules. Some Apache modules (like mod_security) can cause segfaults with certain requests. Disable non-essential modules in your Apache config (e.g.,
sudo a2dismod mod_security) and restart. If the crash stops, you've found the issue. - Test with a clean PHP script. Create a simple file in your web root:
echo "<?php phpinfo();" > test.php. Load it in your browser. If it crashes, the problem is server-wide, not WordPress-specific. If it doesn't, the issue is within WordPress (plugin, theme, or core files). - Reinstall WordPress core. If nothing else works, download a fresh copy of WordPress from wordpress.org, and replace the
wp-adminandwp-includesdirectories (keepwp-contentandwp-config.php). This fixes corrupted core files.
Common Mistakes
- Ignoring the error log. Guessing without checking logs wastes time. Always start there.
- Disabling all plugins but not clearing caches. After renaming the plugins folder, clear your browser cache and any server-side caches (like Redis or Varnish) before testing.
- Changing php.ini without restarting Apache. PHP settings only take effect after a restart. Always run
sudo systemctl restart apache2(orhttpd) after editing php.ini. - Overlooking the theme. Many people only suspect plugins, but themes can also have buggy code that causes segfaults.
- Not checking for corrupted .htaccess. A malformed .htaccess can cause Apache to crash. Rename
.htaccessto.htaccess_oldand see if the problem persists. If it goes away, reset permalinks in WordPress.
Tips
- Enable core dumps temporarily to get more details: add
CoreDumpDirectory /tmpto your Apache config, restart, and reproduce the crash. The core dump can be analyzed withgdbto pinpoint the exact function. - Use a staging environment to test changes before applying to production.
- Keep a backup of your
php.iniand Apache config files before making changes. - If you're on a managed WordPress host, contact their support – they often have tools to diagnose segfaults.
Troubleshooting
If the segfault persists after all steps:
- Check for hardware issues. Run
sudo dmesg | grep -i errorto see if there are memory or disk errors. Faulty RAM can cause random segfaults. - Try a different PHP version. If you're on PHP 8.2 and the crash is consistent, switch to 8.1 or 7.4 (if supported) to see if it's a PHP bug.
- Use strace. Run
sudo strace -f -p $(pidof apache2)while reproducing the crash to see the last system calls before the segfault. This can reveal file access issues. - Check for malware. Some malicious code can cause crashes. Scan your WordPress files with a security plugin or manually look for suspicious base64-encoded strings in your theme files.
- Consult the PHP bug tracker. Search for your PHP version and "segfault" to see if it's a known issue with a patch.
Frequently Asked Questions
What exactly is a segmentation fault?
A segmentation fault (segfault) is when a program tries to access memory it's not allowed to. In the context of Apache/PHP, it means the PHP interpreter crashed, causing the web server process to die.
Will increasing memory limit always fix it?
No. While low memory can cause crashes, segfaults are more often caused by buggy code (plugins/themes) or incompatible extensions. Increasing memory is a quick test, but not a guaranteed fix.
Why does the site work for some users but crash for others?
This usually indicates a specific request or user action triggers the crash. It could be a particular page with a heavy query, or a plugin that only runs under certain conditions (e.g., when a user is logged in).
Can a segfault be caused by a DDoS attack?
Yes, a flood of malicious requests can exhaust resources and cause crashes. Check your server logs for unusual traffic patterns. If you suspect an attack, consider using a firewall or CDN.
Is it safe to keep the site running while I debug?
If the segfault is frequent, it's better to put up a maintenance page to avoid serving errors to users. You can do this by adding a temporary maintenance.php file or using a plugin.
What if I don't have SSH access?
If you're on shared hosting, contact your host's support. They can check error logs and often fix the issue for you. You can still try disabling plugins and switching themes via the WordPress admin dashboard.