0

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 Answers2

0

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.

nayan
  • 1
  • Thanks for the suggestion. I've tried that and unfortunately still get a blank white screen with no error message and no standard debug log created. I'm not sure if it's related but I do get a php_error.log file created in the directory and I've added that output in my original post. – Bob Loblaw Apr 08 '23 at 16:16
  • There's an issue with your `wp-config.php` please try to copy the `wp-config.php` file from a fresh WordPress source and replace the database configurations as needed and try to run it on your localhost. It will start to work again. – nayan May 10 '23 at 06:44
0

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