Wordpress site times out when updated themes

I found a serious issue with any wordpress site on virtualmin that completely destroys the site. Before I present the details of the problem I want to let everyone know I have the solution! I just want to post this for documentation and for any wordpress admins out there to check your configuration. I've been able to recreate the problem several times and it's a sure way to break anybody's wordpress site.

Here's the problem: In wordpress if I activate the theme "Overgrowth" or any major change on a wordpress site that takes more than 30seconds what happens is the site will time out and go to an "internal server error" page. As a result the wordpress website is will always load "internal server error" and the site appears to be completely destroyed.

Error log: /var/log/virtualmin/mywordpressdomain.com_error_log

[Tue Jan 14 20:21:32 2014] [warn] [client 11.11.11.11] mod_fcgid: read data timeout in 31 seconds
[Tue Jan 14 20:21:32 2014] [error] [client 11.11.11.11] Premature end of script headers: index.php
[Tue Jan 14 20:21:33 2014] [warn] [client 11.11.11.11] mod_fcgid: read data timeout in 31 seconds
[Tue Jan 14 20:21:33 2014] [error] [client 11.11.11.11] Premature end of script headers: index.php
[Tue Jan 14 20:22:12 2014] [warn] [client 11.11.11.11] mod_fcgid: read data timeout in 31 seconds
[Tue Jan 14 20:22:12 2014] [error] [client 11.11.11.11] Premature end of script headers: index.php
[Tue Jan 14 20:33:29 2014] [error] [client 22.22.22.22] File does not exist: /home/mywordpressdomain/public_html/category
[Tue Jan 14 20:33:32 2014] [error] [client 22.22.22.22] File does not exist: /home/mywordpressdomain/public_html/commercial-production
[Tue Jan 14 20:40:19 2014] [warn] [client 11.11.11.11] mod_fcgid: read data timeout in 31 seconds, referer: http://mywordpressdomain.com/wp-admin/themes.php
[Tue Jan 14 20:40:19 2014] [error] [client 11.11.11.11] Premature end of script headers: themes.php, referer: http://mywordpressdomain.com/wp-admin/themes.php

I changed my ip to 11.11.11.11 but notice the 31seconds? Seems like you could fix that in virtualmin by going to Services>PHP 5 Configuration>Resource Limits and changing Maximum execution time=300 right? Nope! Doesn't work. I was able to recreate the same exact error above even after setting the resource limits. I even erased the virtual server and tried it again. Still breaks at exactly 31seconds and the site is completely destroyed. Also notice this other log /var/log/apache2/error.log will have this,

[Tue Jan 14 20:21:33 2014] [warn] mod_fcgid: process 32610 graceful kill fail, sending SIGKILL

Which also happens the same time as the 31 second timeout.

Here's is what fixed that problem.

Quick Fix: Delete the broken virtual server. Create it again with the default template. Sometimes I get "DNS zone already exists" error and I have to uncheck "Setup DNS Zone?" before I click "Create Server". After the new virtual server finishes SSH into the server as root,

# cd /etc/apache2/sites-available
# nano mywordpressdomain.com.conf

Find the line that has IPCCommTimeout 31 and change it to IPCCommTimeout 300 Upload wordpress files and create its database. Upload the theme Overgrown. Log into the wordpress site and try to activate the theme Overgrown....wait...30seconds later still waiting.....at 1min 15seconds the site reloads and everything is working with the new theme activated! There's the quick fix. It's almost like going to Services>PHP 5 Configuration>Resource Limits and changing Maximum execution time=300 doesn't do anything. It's really stupid.

Here's my full blown fix on this problem (All suggestions welcome), Change all my server templates in virtualmin System Settings>Server Templates and for "Default Settings" and each one of my templates I go to "Apache website" and scroll down to PHP configuration variables for scripts hit the radio button "Entered below .. " and set the following variables

memory_limit=512M
max_execution_time=300
upload_max_filesize=30M
post_max_size=64M
max_input_time=120

Save...Now "Create Virtual Server" using one of the templates I changed. Try creating site if I get that stupid "DNS zone error" then when creating the virtual server under "Enabled features" uncheck "Setup DNS Zone?" and it usually creates the virtual server just fine. Upload WordPress and the them Overgrown. Now you'll notice the Maximum execution time=300 in Services>PHP 5 Configuration>Resource Limits along with all of the other settings I set up in the template. I can also SSH into the server and try,

# cd /etc/apache2/sites-available/
# grep IPCCommTimeout *

and see that all my sites are set to IPCCommTimeout 30 except for the new one I just created using the updated template. Yay it works! Now the other sites are just time bombs waiting for someone to run a wordpress update or activate any major theme on their site and finding out they broke their wordpress install. LOL So I manually edit each file under /etc/apache2/sites-available and change the line with IPCCommTimeout 31 to IPCCommTimeout 300 and that's it.

Is there anything I'm missing? Hopefully this helps somebody. I spend a lot of time on this and ended up with 2broken websites that have to be completely rebuilt. So everyone using wordpress should know about that.

How do my resource limits look is that about right?

Status: 
Closed (fixed)

Comments

Oh ya I also went into Webmin>Others>PHP Configuration and for each of the files showing,

/etc/php5/apache2/php.ini
/etc/php5/cgi/php.ini
/etc/php5/cli/php.ini

click "manage" then "resource" limits and set them to

memory_limit=512M
max_execution_time=300
upload_max_filesize=30M
post_max_size=64M
max_input_time=120

Then went through each domain and updated Services>PHP 5 Configuration>Resource Limits as well.

I'm glad you figured that out, thank you for posting your solution!

While I hadn't run into that before, even when changing WordPress themes, my suspicion is that some themes may require different resource/timeout settings.

Note that when using FCGID, you may need to use Server Configuration -> Website Options, and there setting the Maximum PHP script run time should also change the global FCGID runtime.

Oh I see. That's good to know about that.