Plautus has shell access. Video.
This is deep geek, probably incomprehensible. indi.ca crashed for a day, but the only way to learn about computers is breaking them. This is a guide to moving a modern website from one server to another using command line. This is something I’ve done repeatedly and fucked up repeatedly so I just want to write it down. Note that I don’t really recommend following any of my instructions, use the WordPress Codex. The first step is connecting to both servers and getting a Linux command line. Then you backup the database and all files with about one line of text and place it somewhere. Then you open the other window and wget those files somewhere, unzip them and recreate the directories and databases. Then it should, theoretically, work. I’m doing it from memory and haven’t tested these exact commands.
Command line is just connecting to a Linux/Unix machine in one of the oldest ways possible. Under the Windows Start button you can hit ‘Run’ and then type in ‘command’ and it’ll give you Shell access. It basically just lets you look at files and folders and do operations on them. You can do the same stuff with FTP or a graphical user interface, but you can’t do it in 5 minutes.
I use Putty. It’s a 500k program that I keep on a flash disk. You just enter the domain (say, indi.ca) and the username and password your webhost gives you. Should be in an email somewhere. Then you have command line access.
The only commands I know are
ls – give a file list so you know where the hell you are
cd – open a directory, like cd home
cd ~ – take you back to the home directory
Backup The Site
I think tarball used to mean Tape Archive. It’s just a format, like zip. You need to make a copy of your site to move it. First you need to ls and cd until you know your way around and where the WordPress is stored. On Dreamhost it’s all in a directory called ‘public’. You might be buried, could be cd web/public/html, or any number of places. You’ll need to orient yourself. On Dreamhost you know it’s in public, so it’s pretty simple.
tar -cvzf site.tar.gz public/*
That tells it to create a tarball called site.tar.gz and fill it with the everything in my public folder. I’m not sure what -cvzf means but I’m sure it’s important.
Note that I typed ‘public/*’ instead of just public ‘public’. I don’t want the parent folder, I just want the stuff inside. The parent folders have different names on different servers.
Backup The Database
The posts and comments and everything important is in a MySQL database. You need to know the name and username/password for you database. Should be in a mail from your webhost, or you can set via the control panel. It’s also written in wp-config.php in your WordPress folder. Anyways, this command should backup your database. I use this Kirupa post as a guide everytime.
mysqldump -u username -p db_name | gzip > database.sql.gz
It’ll prompt you for the database password. This tells it to backup the MySQL for this user on this database, and to ‘pipe’ it through gzip (a compressor) to a file named database.sql. If you’re on Dreamhost or something where the host is not localhost then you’ll need to add ‘-h hostname’ to the command, after ‘-p’ I guess. This is rare.
Anyways, now if you do an ‘ls’ you should get a list that includes the files database.sql.gz and site.tar.gz. And that’s your WordPress blog.
Pack The Stuff
Right now the files are beneath the public director, which means they’re not public. Note that this is VERY DANGEROUS AND STUPID because you’re basically making all you passwords and stuff on the Internet so you can copy them over in the next 5 minutes and then delete all the evidence. If you forget then you’re quite easily fucked. This will move both files into the public directory (or wherever you want them to be).
mv site.tar.gz database.sql.gz public
Unpack The Stuff
Then you need to collect the stuff from the destination server. So, open that window, which is connected to another Linux/Unix machine entirely, quite possibly in another country from the first machine. Shell into that (if you haven’t before) with the username password and look around till you find the public directory you want to install WordPress into. ‘cd’ into that. Then you can collect the files from the other server. This uses a command called wget.
Note that those are two separate commands, you’re getting two files. Then you can unpack the tarballs. This is a two lines more code than you need because I have two separate files, you could make one big tarball of both and zip that.
tar xvf site.tar
tar xvf database.tar
This should give you your full directory structure, which includes all the WordPress folders and your documents and uploads and stuff. And it gives you a file called database.sql. Now you need to load that into the new database.
mysql -u username -pPassword databasename < backup.sql
Note that there’s no space between -p and password. Dunno why. Also you need to add ‘-h hostname’ with the Dreamhost host (if it’s not localhost). You need to setup a database beforehand in the Control Panel and add a user and password, FYI.
Then clean up all the files on both servers. On the destination server type
On the original server type
Then you can login to your WordPress and check the plugins and stuff. Everything should sorta be working. There’s no guarantees on the methods above and there’s better documentation on the WordPress Codex and just Googling around.
Before this I used to download everything to my PC via FTP, then reupload everything to the new site. In Sri Lanka this takes hours. Connecting server to server I can move 100 MB or more in like seconds. So these little scraps of command line are useful to now. Command Line is obviously insanely more powerful that this, I’m sure you could do the same thing in two lines of elegant code. But this sorta works for me.