Moving WP installation

January 8, 2014

If I move my WP installation I can hard code the IP address using define in wp-config.php (codex here) but since I have 4 sites using subfolders I wanted to change one line instead of going to 4 files and change 8 lines. This solution is to use a file say ip.text at htdocs then insert below snippet in all 4 wp-config.php files to read the line containing the IP address in the text file.

$file = fopen(str_replace(substr(ABSPATH,-2),"",ABSPATH)."ip.txt", "r");
$ip = fgets($file);
define('WP_HOME','http://'.$ip."/a/");
define('WP_SITEURL','http://'.$ip."/a/");

In this example /a/ is the subfolder containing a WP installation.

There are more issues than I ever anticipated. In fact WP uses absolute url for all attachments and media that went into the posts therefore if the sites are running under a different IP all links are broken.   I have tried a few plugins which claim to resolve this, none of them can do all I want to do.

To completely replace IP addresses appear in all your posts I have to do it in mysql, fire up phpmyadmin then run below

UPDATE wp_posts SET post_content = REPLACE(post_content, 'xxx.xxx.xxx.old','xxx.xxx.xxx.new')

So that’s all I have to do to move my WP Intranet running under XAMPP portable Lite to an external drive, either thumb or HDD/SSD, run setup_xampp.bat in the XAMPP root folder do the little tricks above then I could run the installation in any Windows OS.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: