Blooming Cacti

Bring life to a barren, technological wasteland

Linode: Final Migration Steps

This post is a bit of a grab bag, of the final things that I did to set up my new Linode server.

Videohub Migration

I had created a very small, personal video hosting application using PHP and symfony. It was pretty easy to move but I’d forgotten some of the details of how it worked, so I had to figure out a few extra steps to get it working.

  1. I rsynced the project over to Linode.

  2. I symlinked the videohub2/web directory to the public_html directory that I’d created for the application.

  3. I edited the symfony file, to change the PHP path to /usr/bin/php.

  4. I cleaned the symfony cache, to remove cached references to the old server.

    ./symfony cc
    
  5. I set the timezone, at the top of web/index.php, to stop PHP from complaining about a missing default time zone.

    date_default_timezone_set('America/Chicago');
    
  6. Then I got a fun error from PHP, preventing the app from running at all.

    PHP Fatal error:  session_start(): Failed to initialize storage module: files (path: )
    

    I figured out that PHP didn’t have anywhere to save session files. I solved this by adding a new config line to my PHP-FPM pool definition and creating a new directory. (This happened before I finalized my PHP application creation script.)

    php_admin_value[session.save_path] = /srv/www/videohub/tmp
    
  7. Finally, I hit my last error.

    Unable to open PDO connection [wrapped: could not find driver]
    

    I’d semi-forgotten that the app was built with a SQLite database and that PHP needed SQLite extensions, to access the database. I solved the error by installing the PHP extension for SQLite.

    apt-get install sqlite3 php5-sqlite
    

After I restarted PHP (to pick up the new extensions), the app worked beautifully.

Sending Mail

I don’t want to run a full mail server on my Linode, but I did want the ability to send out emails, so that I could get notifications from my cron jobs, in the event that anything went wrong.

After a quick search of the Linode Library, I found a guide to creating a gateway with Postfix on Debian 6 (Squeeze). I followed the steps in that guide (up until the “create mail directories” step) and ended up with a perfectly functional outgoing mail server.

Logrotate

I needed to ensure that none of my (many) nginx and PHP log files grew too large. Debian comes with logrotate preinstalled. Adding my log files to logrotate’s configuration was pretty easy. Out of the box, logrotate loads its configurations from any files that are in /etc/logrotate.d. I created a new file there, called www.

I rotates files weekly, as long as they’re at least 1 megabyte. The rotated logs are created under the www-data user / group and compressed with bzip2. As the logs are rotated, I’m keeping only the last 12 logs (about 3 months worth). Each rotated file is named with the date it was rotated.

/srv/www/*/log/*.log {
        size 1M
        copytruncate
        create 0660 www-data www-data
        rotate 12
        compress
        dateext
        weekly
        missingok
        compresscmd /bin/bzip2
        compressext .bz2
}

It works well.

Offsite Backups

Finally, I setup a script to use rsync to copy both the /srv/www and database backup folders over to Strongspace, nightly. In the event of disaster, I’ll never lose more than a day’s worth of changes to the sites.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/bin/bash

RSYNC="/usr/bin/rsync"
OPTIONS="-rltvz --delete"
SERVER="df@df.strongspace.com"
MYDATE="`date +%d | sed 's/0*//'`"

SRC="/var/backup/"
DEST="/strongspace/df/home/JoesFiles/mark_copy"
BACKUPDIR="/home/df/Backups/Joe/mark_copy/Backup-$((${MYDATE}/2))"
EXCLUDE="/root/excludes.txt"
${RSYNC} ${OPTIONS} --exclude-from "${EXCLUDE}" "${SRC}" "${SERVER}":"${DEST}"

SRC="/srv/www/"
DEST="/strongspace/df/home/JoesFiles/mark_copy"
BACKUPDIR="/home/df/Backups/Joe/mark_copy/Backup-$((${MYDATE}/2))"
EXCLUDE="/root/excludes.txt"
${RSYNC} ${OPTIONS} --exclude-from "${EXCLUDE}" "${SRC}" "${SERVER}":"${DEST}"

And, with that, I’m done with my migration to Linode. It was fun but now I’m ready to get back to actually enhancing my sites rather than just moving my sites.