500 error on all pages after enabling CDN
-
I have W3TC setup using memcached and it seemed to be working reasonably well. Then I clicked the checkbox on General Settings to Enable CDN and selected AWS S3. When I saved the changes I got a 500 page back. Every request for any page after that would return a 500 error. Nothing was written to the error logs on the server. The access log showed a 500 was returned, but no further details. AT some point the site started working for non-logged-in users, but still returns a 500 if you are logged in, or even try to load the login page. Removing the plugin directory makes the site work again (though it shows warnings about advanced_cache.php, db.php, and object_cache.php being present without the plugin). If I activate the plugin again the 500 errors return immediately, so I can’t change any of the settings.
The site is using Nginx, PHP 7.3 FPM, and managed with Trellis.
Any help would be very much appreciated.
-
Hello @mwheelermindbox
I am sorry about the issue you are having with enabling CDN and I am happy to assist you with this.
Is there a possibility that you have some other plugin for AWS? if not try to completely remove and re-install W3 Total Cache with following steps:
1. Deactivate and Delete Plugin
2. Check .htaccess/nginx File (make backup)
W3TC will create many directives in .htaccess/nginx file to control the caching behavior. Each section will start and end with comments like “#BEGIN W3TC Page Cache core” and “#END W3TC Page Cache core”.
Ensure that no residual entries are leftover in your .htaccess/nginx file after deleting the plugin.
3. Delete wp-content files and folders
– cache folder
– w3tc-config folder
– object-cache.php (if exists)
– advanced-cache.php (if exists)
– dbcache.php (if exists)
– upgrade folder
– delete w3-total-cache folder in wp-content (if exists)
4. Delete Cached Files from CDN (if using CDN)
Besides deleting all the relevant files, if you use CDN then ensure to purge the cached content from your CDN. This is necessary when you enabled the minify option in W3TC settings. You should delete the minified and combined scripts and CSS files from your CDN server to avoid the site breaking on the browser.5. Go to your wp dashboard and re-install W3 Total Cache
After you re-install W3 Total Cache and configure (without CDN), make sure to export the configuration in Performance>General settings>Import export configuration or better yet, make a backup of the master.php file in wp-content/w3tc-config/
So when you enable CDN and still experience the same issue, simply replace the master.php file.
Then, of course, we need to determine what might be causing this kind of issue.
Thank you!Marko,
Thanks for the followup. I am using memcached for all the config and caching (because our WordPress is on autoscaling servers behind a load balancer), so I don’t think the cache or w3tc-config folders are being used. With the config being stored in memcached, and me not knowing the key it’s stored under I haven’t figured out a way to delete it.
On the live site we are using the MediaCloud plugin to store images on S3. We are not using that on our staging environment, and I have replicated the 500 error from turning on CDN in W3TC on staging. Our staging environment is not behind a load balancer and is using 127.0.0.1 memcached, rather than a remote server like production.
How do I clear the config in memcached? How do I setup W3TC to use S3 as a CDN?
Thanks
Hello @mwheelermindbox
Perhaps I was not very clear and I apologize for that.
Removing the plugin directory makes the site work again (though it shows warnings about advanced_cache.php, db.php, and object_cache.php being present without the plugin).
Can you please share where did you remove the plugin directory from? Should be in wp-content/plugins/
w3tc-config folder needs to be used by the plugin because the plugin settings are stored in the master.php file withing the w3tc-config folder.
Simply enabling the CDN and choosing Amazon Cloudfront from a dropdown menu should not cause 500 errors as the CDN need to be configured in Performance>CDN.
I would suggest temporarily disable other plugins and see if there is a possible conflict while CDN is enabled in W3 Total Cache. If the issue is gone when other plugins are disabled, start enabling the plugin one by one and see which one might be causing the conflict.
This is environment-specific as I’ve enabled the CDN in couple of my installations and selected Amazon, but no 500 error occurred.
Thank you!The only file in w3-config is index.html because I am storing the config in memcached because there are three servers behind a load balancer and they all need to use the same config.
How do I clear the memcached config?
To remove the plugin I renamed the w3-total-cache in the plugins directory to w3-total-cache-bak. Loading the plugins page in WP-Admin then causes WordPress to disable the plugin because it isn’t where expected. If I remove the object-cache.php file I can then rename the plugin directory back to w3-total-cache and the site works. Obviously I should also remove advanced-cache.php and db.php if W3TC is not activated.
If I disable every other plugin and just enable W3TC I still get a 500 error on every page load with the current configuration in memcached that I have been unable to change or delete. To be able to get anywhere and troubleshoot this, I need to be able to delete the memcached config. I’ve tried memcached at the command line and listed the keys in all the albs, but didn’t see anything that was obviously the config for W3TC. Lots of objects, some minified data, some page caches, nothing that looks like config based on the key names.
Hmmm, even after doing a flush_all on Memcached to delete everything in there, I still get a 500 error on every page when activating the plugin.
Hello @mwheelermindbox
Can you please check if you have
define( 'W3TC_CONFIG_DATABASE', true );added to your wp-config.php?
Also, can you please export the settings in Performance>General settings>Export/Import settings and share that JSON file?
Thank you!Marko,
W3TC_CONFIG_DATABASE is true. I had assumed that was referring to saving it in memcached, but now realize it’s probably saving the config in the MySQL database. I’ve checked wp_options before for option_name like ‘%w3%’ and it returns nothing, so I guess the option name is different or the table it uses is different.
I cannot export the settings since the site returns a 500 error on every page if the plugin is active.
Thanks,
MikeHello @mwheelermindbox
The database-stored configuration will increase request response time. This functionality should be used only when you have no other option. To enable the database-stored setting, add define( ‘W3TC_CONFIG_DATABASE’, true ); to your wp-config.php and the plugin will immediately begin to use options table for configuration storage via the wp-options table. Alternatively, define( ‘W3TC_CONFIG_DATABASE_TABLE’, ‘wp_options’ ); constant can be defined to specify a table you created specifically for this use case.
Note: If you customized your settings prior to switching to the database storage setting, you will lose your configuration settings. Be sure to export settings beforehand, then import afterward. You can then remove the configuration file from your source control if it was there and delete it. Ideally, defining the W3TC_CONFIG_DATABASE constant prior plugin activation allows you to skip all of these steps.
Now in your case, the configuration is already stored in the database. Can you please remove define( ‘W3TC_CONFIG_DATABASE’, true ); re-enable W3 Total Cache and check if the configuration is in the w3tc-config.
Thank you!Hello @mwheelermindbox
Also, you should check the error log when W3 Total Cache is enabled to see why is it throwing a 500 error.
Thanks!@vmarko Thanks for continuing to look into this. As mentioned nothing is being written to the error logs for reasons I have not been able to determine. The server is provisioned and managed by Trellis (roots.io/trellis) and error logs usually, but in my experience not always, work properly with that. It sure would be helpful in troubleshooting if I could get error logging to work….
Since production is a series of load balanced servers the config does need to be stored in the database, but staging is a single server, so I can set that to use a file for config for debugging this problem. When I do that it looks like all my settings are writing to the w3tc-config/master.php file though I’m not sure how since I haven’t found them in the wp_options table. In any case, here’s what is written to master.php when I activate the plugin:
https://gist.github.com/myquealer/0fa1dce0aafd254646762c5bc92355f3
Activating the plugin throws a 500 error, as does every page until I force the plugin to be deactivated by renaming the w3-total-cache directory in the plugins directory.
Hello,
Can you please try to edit line 358 in the provided file:
"cdn.enabled": true,
with
"cdn.enabled": false,
replace the file with the edited one and try to enable W3 Total Cache.
Thank you!I still get a 500 error when changing cdn.enabled to false and cdn.engine back to stackpath2, which are the only changes I made between the plaugin and site working and 500 errors on every page.
Hello @mwheelermindbox
Sorry for the late reply. As there are no error logs and your setup is the way it is, this issue seems environment-specific.
The only thing I can offer you is our Professional support and you can reach us via the plugin in Performance>Support.
Thank you!
The topic ‘500 error on all pages after enabling CDN’ is closed to new replies.