Linode Tutorial: How To Move Your WordPress Blog to Linode

Ray Wenderlich
We're now on a Linode!

We're now on a Linode!

Yesterday, I moved this WordPress blog from a shared hosting site to a virtual private server at Linode.com. Did anybody notice? :]

The process was much easier than I expected, largely due to the excellent instructions available at the Linode Library.

However, in practice I found myself navigating between several guides and blog posts, so I wanted to gather all the material it takes to do this in a single Linode tutorial.

Why Linode?

Personally, the main reason I switched to Linode was so that I could have a web server that I could customize the way I wanted it. This way, I can easily play around with various technologies such as APNS or running my own TCP services on arbitrary ports.

I also like the improved performance it offers over shared hosting and the simple fact that it gives me some good practice at Linux administration! :]

As for why I chose Linode specifically, there are several other options out there (including Slicehost) that are pretty similar. I’ve heard good things about Linode from a lot of people and was impressed with their site and documentation, so decided to give them a shot.

And based on my experience with them so far, I’ve been very happy!

Signing Up and Booting Up

If you’ve decided to sign up for a Linode account and like this blog, please consider using my referral link – it helps reduce my web hosting cost, at no cost to you.

Either way, all you have to do is go to the main site, click “Sign up” and fill in the one page form – that’s all there is to it!

As for the plan to select, it depends on your space and traffic needs. I just have this blog and my wife’s blog on the box, so all I needed was the smallest plan (the Linode 360), which is $19.95/month for 16GB storage and 200GB data transfer.

Looking at the site, it appears to be quite easy to upgrade resources on the Linode if you need to later so it looks like it doesn’t hurt to start small (although I haven’t tried this myself).

Screenshot of Linode Upgrade Screen

Once you’ve signed up, the next step is to choose a datacenter for your Linode.

Check out used the speed test page on the web site to download the various binaries simultaneously to get an eyeball of which loaded more quickly.

Once you’ve chosen you can install an OS on your Linode. Personally, I picked Ubuntu 9.10 because that is the distribution I’m most famliar with at the moment – and it’s also recommended for people who are new to administering Linux.

I chose the 32-bit distribution rather than the 64-bit distribution because it saves memory, chose the entire disk space available for the Linode, and left the Swap Disk size at the default option.

The OS is usually deployed to the Linode extremely quickly – probably 30 seconds or so. Once it’s done just click the Boot button to load it up, and pow – your own VPS ready to roll!

Connecting And Upgrading

Once it’s booted up, click on the Network tab in the Linode manager, and jot down the IP address of your Linode. You can SSH to it from your remote machine with the following command:

ssh root@x.x.x.x

Enter the password you chose when you set up the Linode, and you’re in! The first thing to do is to update the system so the latest security patches applied.

You can either do this with apt-get or with aptitude. I chose to do so with aptitude after reading a couple of threads like this one that explain some of the benefits of aptitude over apt-get, including better removal of unused packages and simpler command-line interface.

To use aptitude, first enable the “universe” reposititories in the aptitude configuration file, which is disabled by default. This allows aptitude to search the community-maintained open source software for Ubuntu as well as the official Ubuntu-supported software.

Just edit /etc/apt/sources.list with your favorite editor and uncomment the six lines under the “universe repositories” section.

Then to update the system, run the following commands:

aptitude update
aptitude safe-upgrade
aptitude full-upgrade

That’s it – system updated!

Initial Configuration Tidbits

Also, early in the process you should probably set up a hostname for your machine. Even if you haven’t modified the DNS record for your domain yet, it’s not a problem to configure the machine so it treats itself like that early.

You can set the hostname with the following commands (naming your machine www):

echo "www" > /etc/hostname
hostname -F /etc/hostname

Then fix up /etc/hosts so that it has an entry for your IP:

127.0.0.1 localhost
x.x.x.x www.yourdomain.com www

Also, you may notice that if you let your terminal idle for a while, when you return to the terminal the SSH session may be hung. Obviously, this can be quite annoying, but there is an easy fix. Simply edit /etc/ssh_config and add the following line to the bottom of the file:

ServerAliveInterval 5

This will cause your SSH client to send a keepalive packet to the server every 5 seconds.

Keep in mind that this is basically disabling a security feature (I guess so that if you leave your computer unattended someone can’t hijack your session), but this wasn’t a concern for me so I’d rather have the convenience :]

Securing SSH and Setting Up a Firewall

As is, the system has a big security weakness: SSH is enabled, on the default port, and for root logins! That means that someone could run a password guessing attack against your system and potentially gain root access.

The other problem is we’re still using a root login rather than a user login using sudo, another security no-no! Luckily, it’s easy to patch these up – use the following guide from Slicehost. Just page 1, page 2 is optional.

Don’t worry that it’s about an older version of Ubuntu and for Slicehost, it works just the same with the latest version of Ubuntu on Linode!

Also, you may find it useful to have a way to test that the firewall is indeed working. Before you setup your new firewall rules (blocking everything), you can verify that the existing rules (allowing everything) allow you to connect to an arbitrary port by using netcat to listen on a port:

nc -l -p 1234

Then you can use telnet on your local machine to see if you can connect to that port:

telnet x.x.x.x 1234

You should be able to connect with the default rules, but not with your modified rules.

Setting up a LAMP Server

Again, another guide has got us covered here. Just run through this excellent guide on installing a LAMP server on Ubuntu 9.10 and you’ll be up and running in no time.

At this point, I’d recommend making a little test index.php script inside your public_html directory, then browse to it from your local machine to make sure everything works. You can use a very simple index.php like the following:

<?php
   echo 'Hello, PHP!';
?>

To test this out, you’ll need to set up the /etc/hosts file on your local machine to map your domain name to your new Linode server’s IP.

Just add the following line to /etc/hosts:

x.x.x.x  www.yourdomain.com

Then use your web browser on your local machine to browse to your domain. If all works well, you should see the results from your index.php script!

Migrating WordPress

Ok now onto the fun part – migrating the WordPress blog over! There are seven quick steps to make this happen.

1. Go to your old web server and made a backup of the entire WordPress database, as well as WordPress’s wp-content folder.

Save the resulting files to your local PC, and then copy them to your Linode via scp (change the port to whatever you set up as the SSH port):

scp -P 30000 wordpress_db_backup.sql username@x.x.x.x:/home/username
scp -P 30000 wordpress_content_backup.zip username@x.x.x.x:/home/username

2. Make a new database for your WordPress data on your Linode box and import the old database contents:

mysql -u root -p
create database wordpress
use wordpress;
grant all privileges on wordpress.* to 'username'@'localhost' 
    identified by 'password';
exit;
mysql -p -d wordpress < /home/username/wordpress_db_backup.sql

3. Move to the public_html directory for your site, and download WordPress according to the following instructions from the Linode WordPress guide:

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
mv wordpress/* ./
rmdir wordpress
cp wp-config-sample.php wp-config.php

4. Edit wp-config.php to specify the database name, username, and password that you specified above.

5. Unzip your old wp-content data into the wordpress installation:

mv wp-content wp-content-old
sudo aptitude install unzip
unzip /home/username/wordpress_content_backup.zip

6. You should enable mod_rewrite in Apache because WordPress uses it to rewrite URLs.

a2enmod rewrite

7. You need to set up your .htaccess file. The .htaccess file is a set of directives to Apache that you can use to protect certain files and folders, tweak settings, and rewrite URLs, among other things.

All you have to do is create a new file named .htaccess in your public_html directory, and add the following to the file (note you'll have to replace the last section with data from WordPress):

<files .htaccess>
order allow,deny
deny from all
</files>

# disable the server signature
ServerSignature Off

# protect wpconfig.php

order allow,deny
deny from all


# who has access, who doesn't
order allow,deny
allow from all

# disable directory browsing
Options All -Indexes

# set the canonical url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ryourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

# wordpress settings - from Settings\Permalinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

And that's it! At this point you can fire up www.yourdomain.com in your web browser on your local PC, and if all works well your WordPress blog should show up like normal!

Final Details

There are two more details you'll have to fix up that you might not notice at first glance.

First, you'll probably want to set up a SMTP server so WordPress can send you mail (such as when a comment needs moderation). To do this, just run through this this handy guide from Linode - it just takes a couple minutes.

Second, you'll want to set up the permissions on your wp-content/uploads directory so that WordPress can write files to this directory. You can fix this by changing the group of your web site directories to the group apache runs under (www-data) and setting the permissions of wp-content/uploads to 775.

cd /srv/www
sudo chgrp -R www-data *
cd yourdomain.com/public_html/wp-content
sudo chmod -R 755 uploads/

Once you're satisfied everything is working, you can go to your DNS provider (I use dnsmadeeasy.com) and switch the A record to point to your new server's IP.

With my DNS provider, it just took about half an hour for the changes to take effect!

And That's a Wrap!

I'm loving the new VPS for this site - the performance seems a lot better, and I love being able to customizer the server however I want. Everything about the Linode server has been great so far, and they did a great job making everything go smoothly with their excellent documentation!

Let me know if you have any questions about Linode or doing a WordPress migration, or if you are a Linux guru and have tips for additional things I should/shouldn't do! :]

References:

Ray Wenderlich

Ray is part of a great team - the raywenderlich.com team, a group of over 100 developers and editors from across the world. He and the rest of the team are passionate both about making apps and teaching others the techniques to make them.

When Ray’s not programming, he’s probably playing video games, role playing games, or board games.

Other Items of Interest

raywenderlich.com Weekly

Sign up to receive the latest tutorials from raywenderlich.com each week, and receive a free epic-length tutorial as a bonus!

Advertise with Us!

PragmaConf 2016 Come check out Alt U

Our Books

Our Team

Video Team

... 8 total!

Swift Team

... 15 total!

iOS Team

... 34 total!

Android Team

... 16 total!

macOS Team

... 13 total!

Apple Game Frameworks Team

... 13 total!

Unity Team

... 10 total!

Articles Team

... 10 total!

Resident Authors Team

... 6 total!