WordPress : How to fix critical error on your website during install

WordPress install - critical error on your website problem

The other day, I was in the process of installing a WordPress website on my local Windows development machine, so I set up everything necessary and ran the WordPress installation page step by step. In the final step, after clicking Install WordPress button, the page was loading for a while and then an error message showed up telling me about the critical error on your website. In this article, I will show you how I found the cause of the issue and how I fixed it.

The exact error message "There has been a critical error on your website" was not very informative about the cause of the problem.

WordPress install - critical error on your website message

Even though, the page was complaining about "critical error", I still tried to check how the website loads and it did load, but the page was broken. When I tried to log in as an administrator, it complained with the "unknown user" error.

Checking the MySQL tables using the phpMyAdmin tool I noticed that all the WordPress tables were created, but they were all empty except for the wp_options table:

phpMyAdmin - WordPress tables

Click image to enlarge

No wonder, the login didn't work. The users table had no data. 🙂

Enabling the debugging with WP_DEBUG

The critical error page was linking to the Official WordPress page about debugging, where it suggests various ways to debug the issues with WordPress.

First, I tried to edit the wp-config.php file and set the WP_DEBUG to true. When the wp-config.php file is first created, it has WP_DEBUG set to false:

Open the wp-config.php file in the text editor and find the following line:

define( 'WP_DEBUG', false );

Change it to true:

define( 'WP_DEBUG', true );

Repeating the WordPress installation process

Now I needed to repeat the installation. As I mentioned before, visiting the homepage shows the broken webpage, so I tried to repeat the installation process by going to install page at:

/wp-admin/install.php

Unfortunately, WordPress falsely thinks that just because the WordPress MySQL tables already exist, the installation is not necessary, even though the MySQL tables had no data in them. It was giving me the "Already Installed" message saying "You appear to have already installed WordPress. To reinstall please clear your old database tables first":

WordPress already installed message

To fix this, I had to delete already generated WordPress MySQL tables from the failed installation. How to achieve that is discussed next.

Deleting the existing WordPress MySQL tables

We can delete every MySQL tables that the WordPress installation generated using the phpMyAdmin tool with the following steps:

  1. Login into phpMyAdmin.
  2. On the left sidebar, select the database you created for this installation.
    Warning: Double check it's the correct database so you don't delete the tables of a wrong one by mistake!
  3. The list of tables from the selected database should show up. At the bottom, click on the "Check all" checkbox to quickly select all the tables.
  4. Click on the dropdown menu nearby showing "With selected:" and choose DROP option as shown below.

    phpMyAdmin - delete WordPress tables to repeat installation process

    Click image to enlarge
  5. A generated SQL query will show up in red and ask you "Do you really want to execute the following query?". Click Yes.

    phpMyAdmin - deleting wordPress tables confirm message

    Click image to enlarge

The database for the WordPress website should now be empty and going to the Root URL should redirect you to the installation process.

I again entered the required information and the installation failed as expected, but there were no debug messages displayed either.

Enabling the debug log

Since displaying errors didn't work, I tried to use the debug logging feature instead.
In wp-config.php file, after define( 'WP_DEBUG', true ); I added this line:

define( 'WP_DEBUG_LOG', true );

With WP_DEBUG_LOG enabled, the debug errors should now be saved in a debug.log file located at /wp-content/ folder.

After deleting the MySQL tables one more time in order to run the installation page, the /wp-content/debug.log file was indeed created and I could finally find out the source of the critical error. The debug.log contained the following line:

PHP Fatal error: Maximum execution time of 30 seconds exceeded in ...\wp-includes\wp-db.php on line 2024

For you, the error might be different, but in my case, the issue was that the installation needs more than 30 seconds to complete, but the PHP doesn't allow it as it exceeds the default maximum time allowed. This seems like an easy fix, which is shown next.

Modifying the php.ini file

The execution time can be modified in the php.ini file by changing the value of the max_execution_time directive. I opened the php.ini in the text editor and located the following line:

max_execution_time = 30

I modified it to two minutes:

max_execution_time = 120

I saved the file, but for changes to take into effect, I had to also restart the Apache server.

Next, hopefully, for the last time, I again deleted the MySQL WordPress tables and run the installation page. After entering the WordPress username, password, email and clicked Install WordPress button, the page was loading for about a minute and this time finally, it showed that the installation was a success.

WordPress installation success message

Note: After successful installation, do not forget to disable debug logging in the wp-config.php file.

Conclusion

In this article, we examined what to do after fresh WordPress install gives you There has been a critical error on your website error. As the error message is not very informative about the cause of the problem, we used WordPress debugging to learn about the exact reason for installation failure. In my case, it was due to installation taking too much time, so the maximum execution time set in the php.ini terminated the installation process before it was able to finish.

Did you also have the critical error message during the installation? What caused the error in your case? Let us know.

Write a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.