Blooming Cacti

Bring life to a barren, technological wasteland

Moving Lessn

The last site that I’m going to move this weekend is a small: my personal URL shortener, using Lessn. It’s a good small test, because it uses PHP and it will let me make sure that I can get PHP working, without having to mess with a large, complex site.

I’m not going to detail all of the setup. For the most part, I’m taking the basic nginx / PHP setup stragith from Linode’s Nginx and PHP-FastCGI on Debian 6 guide.

Here are the MySQL steps, to create the Lessn database and a secure user for it.

mysqladmin create lessn

CREATE USER 'lessn'@'localhost' IDENTIFIED BY 'xxxxx';
GRANT ALL ON lessn.* TO 'lessn'@'localhost';

Finally, I could load the database backup, from Litho.

scp jmartin@litho.joyent.us:/users/home/jmartin/backups/db/latest/jmartin_lessn_2012-08-19_01h03m.Sunday.sql.bz2 .
bzip2 -d jmartin_lessn_2012-08-19_01h03m.Sunday.sql.bz2
cat jmartin_lessn_2012-08-19_01h03m.Sunday.sql | mysql -u lessn -p lessn

I also need to copy the site files over, from Litho, and configure them for their new home.

rsync -ravn jmartin@litho.joyent.us:/users/home/jmartin/domains/jmdf.im/web/public /srv/www/jmdf.im/public_html
chown -R www-data:www-data /srv/www/jmdf.im
vim /srv/www/jmdf.im/public_html/-/config.php

The final change I had to make was to enable URL rewriting, for lessn, in /etc/nginx/sites-available/jmdf.im.

location / {
    index index.php index.html index.htm;
    # if the requested file exists, return it immediately
    if (-e $request_filename) {
            break;
    }

    # all other requests go to Wordpress
    if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?token=$1 last;
    }
}

After I reloaded nginx with the new configuration, everything worked perfectly.