How to fix PHP Warning: Constant ABSPATH already defined in

Don’t you just hate it when you upgrade PHP to a new version and then you check the error_log file in your web hosting and notice it’s full of errors and warnings.

You really should always watch your error_log file no matter what content management system you use.

In this example it’s WordPress 6.2 on PHP 8.0.

[29-Apr-2023 23:56:51 UTC] PHP Warning: Constant ABSPATH already defined in /home/website/public_html/wp-config.php on line 34

Now what’s happening here is that WordPress has been updated to correct code issues with previous versions of PHP however the update process never updates the wp-config.php file which holds you precious website user and database credentials.

So you ALWAYS need to compare your wp-config.php with wp-config-sample.php after a major WordPress upgrade.

Here is what was in my old wp-config.php

define('ABSPATH', dirname(__FILE__).'/');

Here is what was in the new wp-config-sample.php

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
   define( 'ABSPATH', __DIR__ . '/' );

The solution then is to update the wp-config.php and get the code right to what the sample showed.

Problem solved.