WordPress No Admin & Frustration

Recently I set up a copy / backup site on localhost using Xampp (Windows 10). It all went smoothly until I tried to log in to the Admin, which redirected back to the main site for some unknown reason. Then, trying again would display the message: “Sorry, you are not allowed to access this page”. But I should be!

Things tried that didn’t work:

  • Clearing all cookies and cache.
  • Disabling all plugins by renaming the plugins folder to something else.
  • Renaming the current theme folder, causing a revert to the default TwentyWhatever.
  • Re-saving Permalinks.
  • Adding the following lines to wp-config:
    • define(‘WP_HOME’, ‘http://example.com’);
    • define(‘WP_SITEURL’, ‘http://example.com’);

Eventually, I found by comparing the local database with the online (fully functional) database, that the table prefixes weren’t identical. They were the same apart from an uppercase letter in the online version. I realised then, that while importing the database tables to phpMyAdmin locally, the table prefix had been forced to lowercase. Even though I must have previously noticed this and also made the local wp-config.php table prefix reference lowercase to match, it finally occurred to me that there would be non-fully-lowercase table prefix references stored within the database tables.

The solution was to grab a new copy of the online database, open the SQL file in a text editor and replace all instances of the table prefix with the lowercase version. Example (and totally fictitious): b941N_ becomes b941n_

Zipping this file, dropping all local tables and re-importing fixed the problem.

I hope this helps save someone some time and frustration, unlike my adventure in WordPress / database pain.