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 an indie software developer currently focusing on iPhone and iPad development, and the administrator of this site. He’s the founder of a small iPhone development studio called Razeware, and is 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.

User Comments

5 Comments

  • Thank you for the detailed information. Exactly what I was looking for after some initial Linode research. Will need to read about 10 more times and go through the links. I joined your forum and read more about your dev stuff, also very interesting. My question is about: Learning all this after using cPanels and then a DH custom panel where I have client sites still on a shared machine. [Say you're not scared] - I'm pretty geeky [mil trained] but know nothing about unmanaged servers and some of the jargon like 'chowning' is my fav.

    It looks like the bandwidth of the small Linode will easily handle several client cms/blogs bandwidth, which is the missing part of how to set up on a vps compared with what I'm used to, like phpMyAdmin - I want to concentrate on my own apps, dev and WordPress for clients and not become a ubuntu or apache god. I truly believe I need a vps but will need a shove into this arena. I can understand ssh but I guess I sorta like a gui. Am I headed down the wrong path here? Meaning I want to configure it for pretty straight forward sites with good security and host multiple domains within the Linode. I have the luxury of being able to break it for a couple months learning, before I have to migrate the sites in.

    Over the last years I've been learning flash and AS while becoming fairly good at WordPress, CDN's and media delivery - expanding my proficiency for the business end, which is what the client sees and cares about - if that makes sense.

    cheers
    stu
    stu2u
  • Hey Stu,

    If you want to host your own VPS with Linode, you're going to have to get down & dirty with Linux commands and such (rather than GUIs like cPanel) most likely. But that's half the fun! :]

    The nice thing about Linode is they make it pretty easy to get started even if you're rusty on Linux and such due to their great documentation center. It's really easy to host multiple domains w/ Apache - that's what I do - I'm running 5 or so domains off the same box.

    If you do want to keep with the cPanel route, it might be better to go with another web host that sets things up for you rather than requiring you to do everything yourself though. I personally picked Linode for learning experience, plus the ability to do/install/setup whatever I wanted.

    Best of luck!
    rwenderlich
  • Your .htaccess file is missing some crucial lines. For example:

    Code: Select all

    # protect wpconfig.php

    order allow,deny
    deny from all



    should actually be

    Code: Select all

    # protect wpconfig.php
    <files wp-config.php>
    order allow,deny
    deny from all
    </files>
    ntraft
  • ntraft wrote:Your .htaccess file is missing some crucial lines.


    Oh, actually I just realized that those lines aren't missing, they were just rendered as HTML. The source lines should be:

    Code: Select all

    # protect wpconfig.php
    &lt;files wp-config.php&gt;
    order allow,deny
    deny from all
    &lt;/files&gt;
    ntraft
  • We recently moved our site from godaddy VPS to Linode
    The site will not load on mobile devices, and we've spent weeks trying to figure it out
    Linode has no answers, and my team cannot figure out the issue
    Any help would be greatly appreciated!!
    ss_universal

Other Items of Interest

Ray's Monthly Newsletter

Sign up to receive a monthly newsletter with my favorite dev links, and receive a free epic-length tutorial as a bonus!

Advertise with Us!

Vote for Our Next Tutorial!

Every week, we alternate between Gaming and Non-Gaming tutorial votes. This week: Non-Gaming!

    Loading ... Loading ...

Last week's winner: How To Make a Tower Defense Game with Swift.

Suggest a Tutorial - Past Results

Hang Out With Us!

Every month, we have a free live Tech Talk - come hang out with us!


Coming up in December: The Great CALayer Tour

Sign Up - December

Our Books

Our Team

Tutorial Team

  • Brian Broom
  • Tony Dahbura

... 57 total!

Update Team

... 14 total!

Editorial Team

... 22 total!

Code Team

  • Orta Therox

... 3 total!

Subject Matter Experts

... 4 total!