Solved Cannot connect to Wordpress site

balanga

Son of Beastie

Reaction score: 118
Messages: 2,896

I set up a Wordpress site on my LAN the other day, and everything worked fine. I've since moved the system and a new IP address has been assigned. Now when I try browsing the new IP address (say 85) I get a msg saying this site cannot be accessed and a redirection to the old IP address is attempted.

Has anyone come across something like this before?

I can ping the new IP address and connect to Apache without any problems, but Wordpress does not connect. Could it be that Wordpress caches the old IP address somewhere?
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,896

After reassigning the IP address via my DHCP server I tried http://192.168.1.31 and got:-
192.168.1.64 was the original IP address when Wordpress was installed. Does Wordpress keep this original IP address somewhere in its configuration files, or could it be embedded within MySQL somewhere?

I can ping, http and ssh the new IP address, but am unable to access Wordpress.
 

drhowarddrfine

Son of Beastie

Reaction score: 1,198
Messages: 3,177

The link you show has a redirect to a different IP and that may be the cause. Remove everything after the question mark, including the question mark, and see what happens.
If that doesn't work, try using the redirect address.
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,896

I don't know what is causing the redirect.

Wordpress is now on 192.168.1.31. When it was installed the IP address was 192.168.1.64.

When I try http://192.168.1.31/wordpress/ I get the above redirect.

http://192.168.1.31/ produces the standard Apache 'It Works!'

I can't make any sense of what is happening.
 

drhowarddrfine

Son of Beastie

Reaction score: 1,198
Messages: 3,177

The login was a standard page url. That is, 192.168.1.31/admin or admin.php or something like that. I don't recall. I've not seen the wordpress/ before.
 

Lamia

Well-Known Member

Reaction score: 48
Messages: 286

Your internal DNS server is 'searching" the Internet for the private address.


You need stop such.

You should also check that your host file has the IP address.

Try curl 192...., traceroute and other utilities to fix it.
 

Lamia

Well-Known Member

Reaction score: 48
Messages: 286

Check your WordPress config file too.

Try loopback IP, etc
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,896

I've just been away for a couple of weeks and set up a Wordpress Server on a on a USB attached disk. Everything worked fine, but now I'm back home and cannot connect to it when attached to my LAN. I get a redirection to the IP address assigned when it was built while I was away:-
This site can’t be reached
192.168.0.26 took too long to respond.


Try:
ERR_CONNECTION_TIMED_OUT
The server now has an IP address of 192.168.1.31, but something is causing a redirection to 192.168.0.26! It looks to me like Wordpress holds the IP address of the original setup somewhere.

Any ideas as to where to look?
 
OP
OP
B

balanga

Son of Beastie

Reaction score: 118
Messages: 2,896

Many thanks!

This is the bit that pinpointed the cause:-
Categories
Changing The Site URL
TOPICS
On the Settings -> General screen in a single site installation of WordPress, there are two fields named “WordPress Address (URL)” and “Site Address (URL)”. They are important settings, since they control where WordPress is located. These settings control the display of the URL in the admin section of your page, as well as the front end, and are used throughout the WordPress code.
  • The “Site Address (URL)” setting is the address you want people to type in their browser to reach your WordPress blog.
  • The “WordPress Address (URL)” setting is the address where your WordPress core files reside.
Note: Both settings should include the http:// part and should not have a slash “/” at the end.
Every once in a while, somebody finds a need to manually change (or fix) these settings. Usually this happens when they change one or both and discover that their site no longer works properly. This can leave the user with no easily discoverable way to correct the problem. This article tells you how to change these settings directly.
Additional information is presented here for the case where you are moving WordPress from one site to another, as this will also require changing the site URL. You should not attempt to use this additional information if you’re only attempting to correct a “broken” site.
Alert! These directions are for single installs of WordPress only. If you are using WordPress MultiSite, you will need to manually edit your database.
Changing the Site URL #Changing the Site URL
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
Edit wp-config.php #Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where “example.com” is the correct location of your site.
1
2
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );
This is not necessarily the best fix, it’s just hard-coding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.
Top ↑
Edit functions.php #Edit functions.php
If you have access to the site via FTP, then this method will help you quickly get a site back up and running, if you changed those values incorrectly.
  1. FTP to the site, and get a copy of the active theme’s functions.php file. You’re going to edit it in a simple text editor and upload it back to the site.
  2. Add these two lines to the file, immediately after the initial “<?php” line:
1
2
update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );
Use your own URL instead of example.com, obviously.
3. Upload the file back to your site, in the same location. FileZilla offers a handy “edit file” function to do all of the above rapidly; if you can use that, do so.
4. Load the login or admin page a couple of times. The site should come back up.
Important! Do not leave this code in the functions.php file. Remove them after the site is up and running again.
Note: If your theme doesn’t have a functions.php file create a new one with a text editor. Add the <?php tag and the two lines using your own URL instead of example.com:
<?php
update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );

Upload this file to your theme directory. Remove the lines or the remove the file after the site is up and running again.
Here are some additional details that step you through transfering a LAN-based WordPress site into an externally accessible site as well enabling editing the wordpress site from inside the LAN.
Two important keys are router/firewall modifications and the “wait 10+ minutes” after making the changes at the end.
using ssh to log into your server (nano is a server preinstalled text editor)
$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
add lines just after <?php
update_option( 'siteurl', 'http://your.site.url:port/yourblog ');
update_option( 'home', 'http://your.site.url:port/yourblog ');[
refresh your web browser using your external site URL:
http://your.site.url:port/yourblog
$ nano /var/www/books/wp-content/themes/twentyeleven/functions.php
remove those lines you just added (or comment them out)
access your router, these steps are for pfSense, other routers should have similar settings to look for/watch out for)
add to firewall/nat table a line like this
wan/tcp/port/LAN.server.IP/80
add to firewall/rules table a line like this
tcp/*/port/LAN.server.IP/port/*
uncheck the box at System/advanced/network address translation/Disable NAT Reflection
"Disables the automatic creation of NAT redirect rules for access to your public IP addresses from within your internal networks. Note: Reflection only works on port forward type items and does not work for large ranges > 500 ports."
Then go do something for ten minutes and when you get back see if the external url http://your.site.url:port/yourblog from a LAN browser brings the page up correctly.
Top ↑
Relocate method #Relocate method
WordPress supports an automatic relocation method intended to be a quick assist to getting a site working when relocating a site from one server to another.
Code function #Code function
When RELOCATE has been defined as true in wp-config.php (see next chapter), the following code in wp-login.php will take action:
1
2
3
4
5
6
7
8
if ( defined( 'RELOCATE' ) AND RELOCATE ) {
// Move flag is set
if ( isset( $_SERVER['PATH_INFO'] ) AND ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], "", $_SERVER['PHP_SELF'] );
$url = dirname( set_url_scheme( 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
if ( $url != get_option( 'siteurl' ) )
update_option( 'siteurl', $url );
}
Top ↑
Steps #Steps
  1. Edit the wp-config.php file.
  2. After the “define” statements (just before the comment line that says “That’s all, stop editing!”), insert a new line, and type: define('RELOCATE',true);
  3. Save your wp-config.php file.
  4. Open a web browser and manually point it to wp-login.php on the new server. For example, if your new site is at http://www.yourdomainname.com, then type http://www.yourdomainname.com/wp-login.php into your browser’s address bar.
  5. Login as per normal.
  6. Look in your web browser’s address bar to verify that you have, indeed, logged in to the correct server. If this is the case, then in the Admin back-end, navigate to Settings > General and verify that both the address settings are correct. Remember to Save Changes.
  7. Once this has been fixed, edit wp-config.php and either completely remove the line that you added (delete the whole line), comment it out (with //) or change the true value to false if you think it’s likely you will be relocating again.
Note: When the RELOCATE flag is set to true, the Site URL will be automatically updated to whatever path you are using to access the login screen. This will get the admin section up and running on the new URL, but it will not correct any other part of the setup. You’ll still need to alter those manually.
Important! Leaving the RELOCATE constant in your wp-config.php file is insecure, as it allows an attacker to change your site URL to anything they want in some configurations. Always remove the RELOCATE line from wp-config.php after you’re done.
Top ↑
Changing the URL directly in the database #Changing the URL directly in the database
If you know how to access phpMyAdmin on your host, then you can edit these values directly to get your site up and running again.
  1. Backup your database and save the copy off-site.
  2. Login to phpMyAdmin.
  3. Click the link to your Databases.
  4. A list of your databases will appear. Choose the one that is your WordPress database.
  5. All the tables in your database will appear on the screen.
  6. From the list, look for wp_options. Note: The table prefix of wp_ may be different if you changed it when installing.
  7. Click on the small icon indicated as Browse.
  8. A screen will open with a list of the fields within the wp_options table.
  9. Under the field option_name, scroll down and look for siteurl.
  10. Click the Edit Field icon which usually is found at the far left at the beginning of the row.
  11. The Edit Field window will appear.
  12. In the input box for option_value, carefully change the URL information to the new address.
  13. Verify this is correct and click Go to save the information.
  14. You should be returned to your wp_options table.
  15. Look for the home field in the table and click Edit Field. Note There are several pages of tables inside wp_options. Look for the> symbol to page through them.
  16. In the input box for option_value, carefully change the URL information to the new address.
  17. Verify this is correct and click Go to save the information.
I used Adminer which is actually a single php file which can be installed by directly downloading it from the website...
 
Top