Moved to Wordpress for technical blogging

Internet
Linux
Author

Vinh Nguyen

Published

April 5, 2010

So I've decided to move my technical blog to wordpress, the .org version, not the .com version; that is, to host my own instance of wordpress. The move came from various reasons:

  1. syntax highlighting for soure codes,
  2. LaTeX support for my stat/math display,
  3. post via email,
  4. post via emacs,
  5. text-to-html syntax for blogging (think org-mode),
  6. easy to backup,
  7. all these features must be permanent (ie, the services above cannot be changed and my posts no longer look "right"), and finally,
  8. extensible

Points 4, 5, and 8 were never addressed with blogger, and point 2 was not consistent (contradicts point 7).

Posterous seemed very nice when i tried it out (especially point 3), but it didn't seem too good for points 1 and 2 (although points 2 can be addressed by mathurl or Sitmo's Equation Editor based on this post). I tried wordpress.com once, but thought it was inadequate. I knew it was possible to install your own wordpress version on a server but thought it was too much of a hassle. However, out of the blue I looked into the above features and found that wordpress had plugins (point 8) that really much fulfilled a lot of my needs.

I will outline how I installed wordpress on my school's server and how I customized it to give me the features I want.

I pretty much followed the instructions from wordpress. My server already had apache on it, so I installed the following in addition:

sudo apt-get update
sudo apt-get install php5
sudo apt-get install mysql-server
sudo apt-get install php5-mysql
## mod_rewrite Apache module already installed
wget http://wordpress.org/latest.tar.gz
tar xvf latest.tar.gz
mysql -u root -p ## enter password

In mysql, I have to set up the user and password:

CREATE USER 'ENTER MY USERNAME'@'localhost' IDENTIFIED BY 'ENTER MY PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'ENTER MY USERNAME'@'localhost'
 WITH GRANT OPTION;
EXIT

I also have to set up a database for the blog's data by:

mysql -u USERNAME -p
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "ENTER MY USERNAME"@"localhost"
 IDENTIFIED BY "Enter Wordpress Password";
FLUSH PRIVILEGES;
EXIT

We also need to update the wp-config.php file:

emacs -q -nw wp-config.php ## follow instructions in above site, generate random key, and set table_prefix to "snc_" for supernerdycool
cd ~/
cd blog.nguyenvq.com
cp -rf ~/Downloads/wordpress/* ./

sudo emacs -q -nw /etc/apache2/conf.d/virtual.conf
sudo emacs -q -nw /etc/apache2/conf.d/virtual.conf
## make sure it looks like following:
#
# We're running multiple virtual hosts.
#
NameVirtualHost *
## done

## make sure following is in /etc/apache2/httpd.conf:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

sudo emacs -q -nw /etc/apache2/sites-available/blog.nguyenvq.com
place following in it:
#
# Example.com (/etc/apache2/sites-available/adrc.nguyenvq.com)
#

 # Basic setup
 ServerAdmin EnterMyEmail
 ServerName blog.nguyenvq.com
 DocumentRoot /path/to/blog.nguyenvq.com


 # HTML documents, with indexing.

 Options Indexes FollowSymLinks MultiViews




## enable site
sudo ln -s /etc/apache2/sites-available/blog.nguyenvq.com /etc/apache2/sites-enabled/blog.nguyenvq.com
sudo /etc/init.d/apache2 restart

## go to http://blog.nguyenvq.com/wp-admin/install.php in web browser

I initially had some errors with mysql and php, but this showed me that I was missing mysql-php in the install (apt-get); restart apache again.

To install plugins, it is easiest to have an ftp server set up for the server. I installed it via "apt-get install proftpd ## select standalone."

I addressed what I wanted above with:

  1. SyntaxHighlighter Evolved,
  2. wp-latex,
  3. postie (require php5-imap for imap) or wordpress's native email support (this didn't work too well for me') – email does not work well with wp-latex and syntaxhighlighter as this modifies the incoming text,
  4. weblogger mode in emacs (turn on xml-rpc in wordpress),
  5. Markdown for Wordpress and bbPress
  6. backup by using rsync (for wordpress files) and mysqldump for the database (data),
  7. since these are installed on my own server, of course all these services are permanent (of course I can move them to another server too),
  8. other plugins: Akismet, WP-reCAPTCHA, Acronyms, Search and Replace (very good for updating all posts), Search Unleashed(uncheck "Some themes don't display any search result content. Enable this option to force the theme to display results" in options or when visiting post from google search result, syntax highlighting will get screwed up), ShareThis (share to twitter, facebook, …, all social media), and Simple Image Widget.

The SyntaxHighlighter Evolved and Markdown didn't play nicely together. This post's comments has the solution, by wrapping the source code chunk with the div tag and changing the add_filter line in markdown to 9 (see below). Since this is hard to display, I will describe the characters in text:

LeftAngleBracket div RightAngleBracketDiv LeftSquareBracket bash RightSquareBracket
my code
LeftSquareBracket FORWARD SLASH bash RightSquareBracket LeftAngleBracket FORWARD SLASH div RightAngleBracket

Also change markdown.php:

add_filter('the_content_rss', 'Markdown', 6);
## to
add_filter('the_content_rss', 'Markdown', 9);
## syntax highlighter's is less than 9

See this site for the lnaguages supported.

For LaTeX, include code by:

DOLLARSIGN latex ENTER LATEX CODE DOLLARSIGN

to get \(latex y=x'\beta_0\).

For Markdown syntax, look at this site for a quick reference. The main thing is to use two asterisks (\/\/) around the text for bold and one asterisk (\*) around the text for italics. For links, use

LeftSquareBracket TEXT RightSquareBracket LeftParen URL RightParen

. There are a lot more, but these will be commonly used. I would like the syntax to be like that of org-mode, but I can't have everything. I could hack the php file to modify the syntax like org-mode's, but I'm too lazy now and don't want to deal with the regexp's.

I also like the notepad theme as it fits my technical blog quite nice.

backup wordpress site:

rsync -av --modify-window=1 --delete username@myserver:location localLocation
## this backs up to my computer

backup database and some cron scripts (multiple scripts in the following):

### http://codex.wordpress.org/Backing_Up_Your_Database
mysqldump --add-drop-table -u MyUsername -p Databasename | bzip2 -c > blog.nguyenvq.com.bak.sql.bz2 ## wordpress is the database name, -p says to specify password after
## now enter password

#### restore database
### http://codex.wordpress.org/Restoring_Your_Database_From_Backup
bzip2 -d blog.nguyenvq.com.bak.sql.bz2
mysql -u MyUserName -p Databasename < blog.nguyenvq.com.bak.sql
## enter password

#### setup cron job on server
Backup_blog.nguyenvq.com_DB.sh:
#! /usr/bin/env bash
mysqldump --add-drop-table -u MyUsername --password=MYPASSWORD Databasename | bzip2 -c > /path/to/blog.nguyenvq.com.bak.sql.bz2

chmod +x Backup_blog.nguyenvq.com_DB.sh
chmod o-r Backup_blog.nguyenvq.com_DB.sh

crontab -e:
00 12 * * * /path/to/Backup_blog.nguyenvq.com_DB.sh
59 23 * * * /path/to/Backup_blog.nguyenvq.com_DB.sh
## need a carriage return at end of file

#### setup cron job on my computer
## make sure passwordless ssh is on
Backup_blog.nguyenvq.com.sh:
#! /usr/bin/env bash
INCREMENT=`date +%Y%m%d%H%M`
DIR="$HOME/path/to/wherever"
DIR="$HOME/path/to/wherever/Wordpress_blog.nguyenvq.com"
# -q for quiet in cron
rsync -q -av --modify-window=1 --delete username@server:/path/to/blog $DIR0/
scp -q username@server:/path/to/nguyenvq.com.bak.sql.bz2 $DIR/blog.nguyenvq.com.bak.sql.$INCREMENT.bz2
find $DIR -mtime +14 -exec rm -f {} \; ## delete files older than 14 days

crontab -e:
02 12 * * * /path/to/Backup_blog.nguyenvq.com.sh
02 00 * * * /path/to/Backup_blog.nguyenvq.com.sh