WordPress host IP changed not able to open wp-admin and site page looks scattered

WordPress host IP changed not able to open wp-admin and site page looks scattered

Today I was working on my Virtual Machine in my laptop and was trying to check some theme options.In Virtual Machine I have set ip address to be taken dynamically from DHCP server.Today my wifi change the ip address of Virtual machine and all of sudden the demo wordpress site in VM (Virtual Machine) was not working .
In below screenshot it is showing how the page is scattered . I was not able to login in wp-admin after this.

wordpress4

OK I will put some detail which make the scenario more clear.

Previous Virtual Machine IP = 10.10.0.6
Current Virtual Machine IP = 10.10.0.8

How to Solve this problem

Okay I will give some roadmap of what we are going to do.

  • We will change the hostname of Virtual Machine which is in my Virtual Box, eg. ubuntu.example.com
  • I will update the wp_options table in wordpress database in Virtual Machine from where my wordpress is running
  • In my laptop I will make entry of hostname of my Virtual Machine in /etc/hosts file.So that whenever the ip will change I only have to update my /etc/hosts file with new IP
  • Lets start now.

    Step 1: I login into Virtual Machine , New IP Address is 10.10.0.8 (from DHCP) ,Wordpress database name is wordpress also.Going to change Hostname of Virtual machine which is Ubuntu 12.04 LTS.

    I edited the line and gave the value like this “127.0.1.1 ubuntu.example.com ubuntu” . See in below code viewer.

    sudo vi /etc/hosts
    127.0.0.1	localhost
    127.0.1.1       ubuntu.example.com ubuntu
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
     

    Now edited the /etc/hostname file and gave hostname “ubuntu”

    sudo vi /etc/hostname 
    ubuntu

    Restart the service called hostname so that hostname of Virtual Machine will take effect.

    sudo service hostname restart
    

    Now check if hostname of Virtual machine is set or not.

    `hostname` command is only to see host name
    `hostname -f` is to see FQDN (Fully Qualified Domain Name)

    linux@ubuntu:~$ hostname
    ubuntu
    linux@ubuntu:~$ hostname -f
    ubuntu.example.com
    linux@ubuntu:~$

    Step 2: Now updating the mysql

    Here,

    Database Name: wordpress
    Note: Replace the value of ubuntu.example.com/wordpress with your wordpress link.

    mysql -u root -p
    
    mysql> use wordpress
    
    mysql> Select * from wp_options where option_id = 1 OR option_id = 39;
    
    mysql> update wp_options set option_value='http://ubuntu.example.com/wordpress' where option_id = 1;
    
    mysql>

    exit

    Step 3:

    Because example.com we generally use for testing. To open the wordpress demo site ubuntu.example.com I edited the file /etc/hosts and added the new line with new assigned DHCP ip correspond to ubuntu.example.com

    vi /etc/hosts
    127.0.0.1	localhost		
    10.10.0.8       ubuntu.example.com
    
    # The following lines are desirable for IPv6 capable hosts
    
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    
     

    Now whenever the ip address of machine was changing I was only updating my laptop /etc/hosts file.

    Now I opened the URL from my laptop http://ubuntu.example.com/wordpress
    Done.

    wordpress-final

    4 thoughts on “WordPress host IP changed not able to open wp-admin and site page looks scattered”

    1. Hello Sharad,

      First of all it was a nice and pretty helpful article. Secondly, i am new to linux, mysql, wordpress and webhosting, it would be nice of you if you could suggest me a book which will help me learn promptly all the above

      Reply
    2. Thanks for the tutorial , was searching for something like this for a few hours now….. i purged wordpress installation deleted everything….except for the database that i created for the previous installation .

      Don’t know a lot of sql queries so i went in phpmyadmin and edited the table wp_option -> line siteurl

      Good thing i was accesing my wordpress site from mozilla that was showing me that it tried to access the old ip 192.168.1.65 instead of the new one 192.168.0.65

      Thanks again

      Alex

      Reply
      • Thankyou Alex,

        Your comment give me some confidence that this issue could be common for many readers.
        Happy to see your positive feedback, which is definitely a helpful one for our blog readers.

        Regards
        Sharad

        Reply

    Leave a Comment

    This site uses Akismet to reduce spam. Learn how your comment data is processed.