Today I found a weird issue when trying to activate a WordPress plugin. I always got redirected to 404 Error Page (Not Found). This is the first time I met this error. In most cases it is a crash problem or PHP Fatal error, which is easy to fix. I tried to debug the Apache error log, Nginx error log and MySQL log. There were no errors related to the issue.
After debugging for hours, I finally found the issue. It was a very slow query which led to exceeding the PHP max execution time. There are 3 queries to the database which alter the wp_posts table that take more than 100 seconds to finish. I found this when I activated the MySQL slow query log. So to fix the issue, I commented out those 3 lines and manually updated the database table from PHPMyAdmin. Then I tried to activate the plugin.
Now the plugin works perfectly. So if you have a similar issue, please check that plugin’s code at the wp_activation_hook function. And find if there is a code or database query that will take forever to finish. Hope my experience could help you all.
