How to change a localhost url to ip in wordpress?

I am developing a site using wordpress, MySQL and Xampp. The current url is like localhost/wordpress/sitename.
How can I change the localhost to an ip address to get the site working on other computers on the same network?

Related posts

Leave a Reply

6 comments

  1. First Change url in “wp-option” table in site_url and home_url.
    then change folder name in .htaccess file. and then change database name in wp-config.php file

  2. In my scenario I found that intranet users weren’t receiving the images and other resources (stylesheets) when connecting to my locally hosted wordpress site by url. The problem was that the urls for those resources were being emitted as localhost, which of course wasn’t useful to their machine.

    The general solution is to update the WordPress Address and Site Address on the General Settings tab in the WordPress dashboard with your ip address rather than the default of localhost, then everything will be emitted relative to that.

    In my case I wasn’t able to edit those directly for configuration reasons I haven’t resolved. I found the solution on the WordPress site under the Relocate subtopic on “Changing the site URL”. It’s simple.

    Near the end of the wp-config.php file, just before the line

    /* That's all, stop editing! Happy blogging. */
    

    add the following

    define('RELOCATE',true);
    

    Then navigate to your site using the url rather than localhost and the setting s will be updated. In a local network situation where your url is changing frequently you could just leave the switch set to true, but on a production server it would be a security risk, and you should revert the setting to ‘false’ or remove the statement promptly.

  3. put this statements into wp-config.php :

    if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
        define('WP_SITEURL', 'http://localhost/wordpress/sitename/');
        define('WP_HOME'   , 'http://localhost/wordpress/sitename');
    } else if (strpos($_SERVER['REMOTE_ADDR'],'192.168.1.') !== false) {
        //local network: see ifconfig
        define('WP_SITEURL', 'http://192.168.1.57/wordpress/sitename/');
        define('WP_HOME'   , 'http://192.168.1.57/wordpress/sitename');
    }
    
  4. You put your IP address allocated by the network’s DHCP server(if it exists) instead of ‘localhost’ it should work. else just put your ip address form the other computers connected to the network.

    Eg. If your IP address turns out to be 127.23.45.66

    You should enter this in the address bar of the other comps

    127.23.45.66/wordpress/sitename

  5. You should change the site URL in your WordPress settings to your IP else WordPress will always redirect to what is in the settings.
    enter image description here

    after you access your site by 127.23.45.66/wordpress/sitename on any browser in your network including your own device.

  6. So, apparently, WordPress had saved that Other_IP (the old IP) in the database. Therefore, the solution was to change that Other_IP to the current IP (IP_of_Server) in the database, in our case, MySQL.

    So, now yes, we are going to solve it in one step.

    To do this, we must first enter the MySQL database engine or any other, locate ourselves in the specific WordPress database and update the corresponding fields, which are: site_url and home, which are inside the wp_options table, by default,or the equivalent according to the table prefix that you have left for the WordPress installation. We are going to illustrate with a specific example of our installation, how to solve the problem; You must adapt it to your case.

    To connect to mysql use following command:

    mysql -u [your_user] -p
    

    In case you know the name of your wp_options table, you can skip this step. Go to Update records

    Be aware it could be different according to the table prefix that you
    have left for the WordPress installation

    To find the table name, follow next step:

    Once you have access to Mysql, search for databases with command:

    show databases;
    

    Locate your wordpress database and use following commando to start using the database:

    use [wordpress_database_name];
    

    Once you are using the wordpress database, you should list the tables using the command:

    show tables;
    

    The command should return with all tables on you wordpress database, in which you can fin your [prefix]_options (wp_options by default)

    +-------------------------+
    | Tables_in_wordpress_db  |
    +-------------------------+
    | wp_commentmeta          |
    | wp_comments             |
    | wp_frmt_form_entry      |
    | wp_frmt_form_entry_meta |
    | wp_frmt_form_reports    |
    | wp_frmt_form_views      |
    | wp_links                |
    | wp_options              |
    | wp_postmeta             |
    | wp_posts                |
    | wp_term_relationships   |
    | wp_term_taxonomy        |
    | wp_termmeta             |
    | wp_terms                |
    | wp_usermeta             |
    | wp_users                |
    | wp_wfu_dbxqueue         |
    | wp_wfu_log              |
    | wp_wfu_userdata         |
    +-------------------------+
    

    Update records

    Once you know the table, you just need to update 2 records with the following commands:

    If your wordpress is not on you root folder of your server, you need to set the route. http://[IP_of_Server]/route, otherwise, it will not work correctly.

    UPDATE [prefix]_options SET option_value = "http://[IP_of_Server]" WHERE option_name = "home";
    UPDATE [prefix]_options SET option_value = "http://[IP_of_Server]" WHERE option_name = "siteurl";