MAKE SURE TO BACKUP ALL YOUR DATA BEFORE USING THIS METHOD!
Step 1: If you are using docker to run the MySQL server,
sudo docker exec -it <your mysql container> /bin/bash
In my case, it’s
sudo docker exec -it mysql_1 /bin/bash
Connect to the MySQL database
mysql -h <ip> -P <port> -u <your username> -p
In my case, it’s
mysql -h 127.0.0.1 -P 3306 -u silicon -p
Step 2: Display all of the databases and select the WordPress database
show databases;
use wordpress;
Step 3: Modify the site URL and the home URL with the following commands
For private IP,
update wp_options set option_value="https://192.168.1.18:8080" where option_id=1;
update wp_options set option_value="https://192.168.1.18:8080" where option_id=2;
For public IP/domain,
update wp_options set option_value="https://silicon.blog" where option_id=1;
update wp_options set option_value="https://silicon.blog" where option_id=2;
Replace the URL with your IP/domain. Remember to change HTTPS to HTTP if HTTPS is not needed in your case.
(Optional) To disable all active plugins,
update wp_options set option_value = 'a:0:{}' where option_id = 33;
Step 4: If you are using docker to host the WordPress server, copy the wp-config.php from your docker container. Skip this step and find wp-config.php by yourself if this is not your case.
sudo docker cp <your wordpress container>:/var/www/html/wp-config.php wp-config.php
In my case, it’s
sudo docker cp wordpress_1:/var/www/html/wp-config.php wp-config.php
Step 5: Modify <your private IP range>, <your private IP: port>, add this statement to wp-config.php before the line /* That’s all, stop editing! Happy publishing. */
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { //localhost
define('WP_SITEURL', 'https://localhost/');
define('WP_HOME' , 'https://localhost/');
} else if (strpos($_SERVER['REMOTE_ADDR'],'<your private ip range>') !== false) { //private ip
define('WP_SITEURL', 'https://<your private ip: port>');
define('WP_HOME' , 'https://<your private ip: port>');
} else { //public ip or domain name
define('WP_SITEURL', 'https:// . $_SERVER['HTTP_HOST'] );
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] );
}
In my case, it’s
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { //localhost
define('WP_SITEURL', 'https://localhost/');
define('WP_HOME' , 'https://localhost/');
} else if (strpos($_SERVER['REMOTE_ADDR'],'192.168.1.') !== false) { //private ip
define('WP_SITEURL', 'https://192.168.1.18:8080/');
define('WP_HOME' , 'https://192.168.1.18:8080/');
} else { //public ip or domain name
define('WP_SITEURL', 'https:// . $_SERVER['HTTP_HOST'] );
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] );
}
Remember to change HTTPS to HTTP if HTTPS is not needed in your case.
Step 6: If you are using docker to host the WordPress server, update the wp-config.php with this command. Skip this step and replace the wp-config.php by yourself if this is not your case.
sudo docker cp wp-config.php wordpress_1:/var/www/html/wp-config.php
Step 7: Remember to remove the wp-config.php on your local side.
sudo rm wp-config.php
Step 8: Done. Reboot your server.