Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Installing WordPress / Moving WordPress WordPress

  • SOLVED

Hi There,

I have a questiion about moving and installing wordpress.

Here's my current setup. I an building out a wordpress site locally on my machine using MAMP. I need to move this site to the clients server. The catch is that I'm going to be installing this onto a web server that doesn;t have a domain name pointing to it. The client's domain name currently points to a different server. I can currently access their new website (which is blank right now) by typing in the IP address of the server.

So how do I go about successfully moving this site to their server?

I understand I will need to change the address of my Blog in my local wordpress settings to the (IP address?) and then I will need to export my local database, upload all of the files to the new server (edit wp-config.php with new credentials), import the database and I think that's it? Is it ok if I use an IP Address for my Blog settings rather than a domain name?

What happens when they want to point their domain name to the new server? Do I have to change anything behind the scenes in wordpress?

Thank you in advance for all of your help.

Answers (2)

2010-04-20

Scott answers:

Do you have SSH access to the server?


WP Answers comments:

I believe so.

I don't have a ton of experience with SSH tho. Do I have to use terminal for that?


Scott comments:

Here is what I do for just about all of my WP sites. It does make use of the terminal a bit, but it's nothing too crazy, and might even be a good taste of how powerful it can be.

1. Edit your wp-config.php so it works on various environments. I do this like so:

// ** MySQL settings - You can get this info from your web host ** //
switch ($_SERVER['SERVER_NAME']) {
case 'mysite.local': // local dev environment
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'mylocal_db');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
break;
default:
/** The name of the database for WordPress */
define('DB_NAME', 'yourlive_db');
/** MySQL database username */
define('DB_USER', 'yourlive_dbuser');
/** MySQL database password */
define('DB_PASSWORD', 'yourlive_pw');
/** MySQL hostname */
define('DB_HOST', 'localhost');
break;
}


That will let you use the same wp-config.php file on either server.

2. I dump my local database. I do this using a little shell script that will search the mysql dump for my local url and replace it with the live one. I put the following in a file called dbdump.sh:

#!/bin/bash

# dump database
mysqldump -u root mylocal_db > mylocal_db_dump.sql

# search inside the mylocal_db_dump.sql file for 'mysite.local' and replace with 'thelivesite.com'
perl -pi -e 's/mysite.local/thelivesite.com/g' mylocal_db_dump.sql


Then I can run this script with the command "./dbdump.sh" anytime I want to export my local database to an sql file to import on the live site.

3. I use rsync to sync my local version of the site up to the server. Here is where you need SSH access. Alternatively, you could use FTP to upload the entire local site, but it's harder to keep things in sync this way. If you want to use SSH, I put the following into a file named something like "upload.sh" and put it in my blog folder.


#!/bin/bash
GO=$1
: ${GO:=""}

if [ "$GO" = "go" ]
then
ARGS="-avc"
else
ARGS="-avcn"
fi

rsync $ARGS --stats --progress --exclude-from=rsync_exclude.txt -e 'ssh' . [email protected]:/home/path/to/your/public_html


If you aren't familiar with shell scripting, that's ok. Basically what this does is execute the "rsync" command with a few arguments. It will look at the files in the current directory on your machine and compare them with the files on the server. If you execute this script with a "go" parameter, it will actually perform the copy; otherwise it does a dry-run to show you what changes would occur. I put a list of a few files to ignore while syncing in "rsync_exclude.txt". I ignore any hidden files like .DS_Store, my custom upload shell script which we just created, and temporary files and uploads.

Here is what mine usually contains:

.DS_Store
.htaccess
upload.sh
dbdump.sh
rsync_exclude.txt
/wp-content/cache/*
/wp-content/uploads/*


You can then run the upload.sh script by executing the command like this:

./upload.sh


And if it looks ok, you actually perform the sync with:

./upload.sh go


4. Now we have all our files synced up... we just need to update the database. You can either either use something like phpMyAdmin to upload your "mylocal_db_dump.sql" file, or if you have SSH access you can execute it using your live mysql user:


~: mysql -u yourlive_dbuser -p mylocal_db_dump.sql > yourlive_db


This may seem like a lot, but if you are rapidly developing your site and need to reupload to a staging server frequently, this ends up saving a ton of time. Once you have the files in place, updating the live site is a simple matter of running these commands:


./dbdump.sh
./upload.sh


and then insert your SQL file into your live database, either through the command line or phpMyAdmin.

If you are using a static IP address on your live site rather than a domain name, just use use the IP rather than "yourserver.com" in the examples above and it should work just fine. Good luck!


Scott comments:

Also... when you are ready to make the site "live" and you want to update the wordpress site to use the live domain name instead of the IP address, you can dump your live database to a file and run another search and replace like this:


perl -pi -e 's/12.34.56.78/thelivesite.com/g' thedbdump.sql


and then insert thedbdump.sql file back into your db.


WP Answers comments:

Hi.

I really appreciate the write up, but I don't think I'm comfortable enough with SSH to try it on this site (very tight deadline fast approaching).

This sounds super powerful though, I will certainly keep it for later use. You did write up a lot so I will split up the prize money on here.

Thanks again

2010-04-20

Lew Ayotte answers:

You've got pretty much the basics down... using the IP address probably won't work, if you're on a shared host. I would recommend setting up a development subdomain ... like:

dev.theirdomain.com

and using that as the site URLs.

Another recommendation is installing the Search and Replace plugin.

With that plugin you can do a search/replace on all the default wordpress tables from "localhost" to "dev.theirdomain.com" and then eventually from "dev.theirdomain.com" to "domain.com"...

This way you can be sure that you got all the little nooks and crannies of where the "old" domain names were.

Lew


WP Answers comments:

Hi,

I don't believe its a shared host, but I'm not 100% sure.

Its the dedicated virtual rage server from media temple:
http://mediatemple.net/webhosting/dv/


Lew Ayotte comments:

They probably have their own IP then, so you should be safe... generally I'd prefer a name associated with it anyway. But it's no big deal.

Lew


WP Answers comments:

Ok, I understand.

I may not have the ability to register a domain name, so do you think the IP will be ok?

And what will I need to do once they are ready to propagate their DNS to the new server so that their doman name is pointing to this new site?


Lew Ayotte comments:

Yeah, you should be fine with just the IP.

Do you have access to their registrar? You'll just need to change the DNS record for their domain (and www.domain) to point to the new IP address.

You might want to make sure the TTL (Time To Live) is set to 30 minutes (or lower) a few days before the move. This will make the transfer much smoother.

Lew


WP Answers comments:

Ok, great. I understand.

So I won't need to do anything to WordPress to prep for the move?

IE: When I move the site from my local machine to the server, the "Web Address" and "Blog Address" in wordpress will be set to the IP address. Is this ok or do I need it to point to the actual domain name? And if I do need to switch it to the domain name, what should I do first, update wordpress, or begin the DNS propagation?

SOrry about all the quesitons..


Lew Ayotte comments:

It'll be fine as the IP address... then when you get the domain switched over, you can switch the Web and Blog address to the domain... as well as the search-replace stuff I mentioned above.

Lew