skip to Main Content

I’m fairly new to WordPress building and had a great site built and running only on my local network. I found a suggestion to make it publicly accessible by adding the following to my wp-config file. After adding this and restarting, everything crashed and I can’t access the Dashboard or my site on any combination of urls. What all would this code alter when it ran that I might need to fix?

if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
// accesing site from my local server
define('WP_SITEURL', 'http://localhost');
define('WP_HOME', 'http://localhost');
} else if (strpos($_SERVER['REMOTE_ADDR'],'192.168.0.') !== false) {
// accesing site from another machine in my home network,
// all their (internal) network addresses begin with this number;
// the next line provides the server's own internal network address
define('WP_SITEURL', 'http://192.168.0.142');
define('WP_HOME', 'http://192.168.0.142');
} else { //accesing site from outside home
define('WP_SITEURL', 'http://myexternalip'); //replace by your external home IP
define('WP_HOME', 'http://myexternalip');
}
//error_log("Siteurl is ".WP_SITEURL);

Tried fresh manual install of WordPress, tried deleting plugins, and tried removing the added code from the wp-config.php file but still no luck and getting a white screen of death/http error 500.

No debug error message or file created but do get a php_error.log with the following message:

Stack trace:
#0 /var/www/html/index.php(17): require()
#1 {main} 
thrown in /var/www/html/wp-blog-header.php on line 16
[07-Apr-2023 20:11:15 Europe/London] PHP Fatal error:  Uncaught Error: Call to undefined function wp() in /var/www/html/wp-blog-header.php:16  
Stack trace:
#0 /var/www/html/index.php(17): require()
#1 {main} 
thrown in /var/www/html/wp-blog-header.php on line 16  

And here’s the file content in my wp-blog-header.php file:

* Loads the WordPress environment and template.
*
* @package WordPress
*/

if ( ! isset( $wp_did_header ) ) {

    $wp_did_header = true;

    // Load the WordPress library.
    require_once __DIR__ . '/wp-load.php';

    // Set up the WordPress query.
    wp();

    // Load the theme template.
    require_once ABSPATH . WPINC . '/template-loader.php';

}


 * Loads the WordPress environment and template.
 *
 * @package WordPress
 */

if ( ! isset( $wp_did_header ) ) {

    $wp_did_header = true;

    // Load the WordPress library.
    require_once __DIR__ . '/wp-load.php';

    // Set up the WordPress query.
    wp();

    // Load the theme template.
    require_once ABSPATH . WPINC . '/template-loader.php';

}

2

Answers


  1. Chosen as BEST ANSWER

    Ok, I found the problem by turning on error reporting in PHP, which was off by default. Once that was on, I found the error line in wp-config.php file. Here's the instructions I followed to turn it on: https://phoenixnap.com/kb/php-error-reporting


  2. I think you should turn the debugging on and see what the issue is.

    Edit the wp-config.php for your website

    Change WP_DEBUG from false to true:

    define( 'WP_DEBUG', false );
    

    With debugging enabled:

    define( 'WP_DEBUG', true );
    

    On the following line, type:

    define( 'WP_DEBUG_LOG', true );
    

    Now when you visit the URL of your website you may see the fatal error stating your problem. Try to find workaround to fix the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search