WordPress blog posting with local POP3 mail

March 15th, 2009

This article describes how to set up popa3d (a POP3 mail server daemon process) and create a user account (in Debian Lenny) solely for the purposes of blog posting.

0 – A preliminary note about popa3d

popa3d is a more or less zero-configuration *nix POP3 daemon process that will serve up any mail found in the spool file belonging to any user account (apart from the root account) if the correct user account password is provided.

If you don’t want all your user accounts’ mail spool files to be POP3 enabled, then popa3d is not for you.

1 – Install popa3d

# apt-get install popa3d

Answer ‘yes’ when asked whether you would like to run popa3d in standalone mode.

You can now start, restart and stop popa3d using the init script provided:

# /etc/init.d/popa3d {start|restart|stop}

If you want to disable popa3d permanently (so that it isn’t started at boot time) it is sufficient to simply edit /etc/default/popa3d to read:

RUN_STANDALONE=no

Important tip:  popa3d’s other mode of operation is as an internet ’service’.  For popa3d to work in this mode you must also edit /etc/inetd.conf.

2 – Create a user account for your WordPress blog posts

We now need to create a user account, with a name that should be very hard to guess because WordPress will retrieve (and treat as blog posts ‘pending’) any and all mail it finds in the specified mailbox (when instructed to do so ).  Ideally you should create an account called something like jhuwe7KJ23h but for the purposes of this article we will call the account obscure.

We know that popa3d won’t serve mail that has been delivered to the root account, nor will it serve mail delivered to an ordinary user account unless the correct user account password is provided, but there also happens to be a third security measure which isn’t documented – it won’t serve mail delivered to a user account if the user doesn’t have write access to their home directory.

So, we have to create a user account (with an obscure name) that provides write access to its home directory, but we don’t want to allow logins, we don’t want it intermingling with ordinary user login accounts and we don’t want an unused sub-directory of /home lying around either, especially not if we’re going to provide a number of these accounts for a number of WordPress blogs we may be hosting.

Now, when popa3d is installed (on a Debian system) a number of things happen behind the scenes…

  • a system user popa3d is created
  • a system group popa3d is created
  • user popa3d’s home directory /var/lib/popa3d is created (with owner root and group root)

…so we’re going to give user obscure a UID which keeps her well out of the way of ordinary login accounts, make her a member of the popa3d group, make /var/lib/popa3d her home directory and deny her a shell (thus preventing logins), like so:

# useradd -c "POP3 mail account" -u 65501 -g popa3d \
          -d /var/lib/popa3d -s /bin/false obscure

And we now have to give her a password:

# passwd obscure
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

One final thing remains for us to do – make user popa3d the owner and group owner of directory /var/lib/popa3d and give members of group popa3d write access to it:

# chown popa3d:popa3d /var/lib/popa3d
# chmod g+w /var/lib/popa3d
3 – Check everything is working with telnet

Fire up your command line telnet client:

telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK

If you get the ‘OK’ popa3d is up and running and waiting for client requests.

Build the PostgreSQL manual in Info format

March 15th, 2009

Here’s a step-by-step guide to building the PostgreSQL manual in Info format on a Debian Lenny box:

1 – Install a few extra packages

The PostgreSQL manual is in Docbook format, so…

$ sudo apt-get install bzip2 docbook-dsssl docbook2x opensp
2 – Grab the PostgreSQL source, unpack and configure it

Change ~/workspace/src to suit your needs.

$ cd ~/workspace/src
$ apt-get source postgresql
$ cd postgresql-8.3-8.3.5
$ bunzip2 postgresql-8.3-8.3.5.tar.bz2
$ tar -xf postgresql-8.3-8.3.5.tar
## this next operation is not strictly necessary but...
$ sudo chown -R sebyte:sebyte postgresql-8.3.5  # change user/group name to suit
$ cd postgresql-8.3.5
$ ./configure
[...]
3 – Edit one of the Makefiles included in the source

We need to tell a program called osx to ignore any errors by editing the relevant Makefile using your favourite text editor.

$ cd doc/src/sgml
$ emacs -Q Makefile

## change line 227 to read:
##
##  $(OSX) -E0 -x lower $< | \
##          ^
##          |___ add this switch

While you are about it, you may also decide to edit the Makefile so that the resulting Info manual utilises the full width of your screen. (This greatly improves the look of tables within the manual, of which there are many).

## change line 263 to read:
##
## $(MAEKINFO) --fill-column 184 --enable-encoding --no-split --no-validate $< -o $@
##                            ^
## specify number of columns _|
4 – That’s it. You’re ready to roll.

Complete the process by running make:

# make postgres.info
[...]
# ls -l postgres.info
-rw-rw-r-- 1 sebyte sebyte 4939332 Jan 24 15:33 postgres.info

Job done :)

When I did it, ‘osx’ generated 108,484 errors, all of which were ignored, and there were 14 other warnings in the output, but the resulting Info manual is fine.

Installing WordPress on a Debian box, with lighttpd serving up the goods

February 4th, 2009

Apache users can simply install the Debian wordpress package.  lighttpd users can’t do this because Apache is one of the wordpress package dependencies.

1 – Install MySQL

According to the WordPress developers, moves are being made to port WordPress to PostgreSQL (and the sooner the better) but for the time being we have to make do with MySQL, memory hog that it is:

# apt-get install mysql-server-5.0

Important tip:  Don’t install the meta-package mysql-server if you don’t want your MySQL installation automatically upgraded when you run apt-get upgrade at some point in the future.  (You can of course delete mysql-server after it’s pulled in the latest version but then apt-get autoremove will include your MySQL installation in its list of packages which were automatically installed and are no longer required).

2 – Create a MySQL database for your WordPress blog

The easiest way to do this is with the MySQL client, called simply mysql.

# mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON databasename.*
-> TO "wordpressusername"@"hostname"
-> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT Bye
#
3 – Install PHP

There are three server-side versions of the PHP5 interpreter available as Debian packages.  We only want the ‘CGI’ version (and the MySQL PHP module).

# apt-get install php5-cgi php5-mysql
4 – Grab a copy of WordPress and configure it

Install Subversion if necessary (apt-get install subversion), cd to the document root of your website and run the command:

# svn co http://svn.automattic.com/wordpress/tags/2.7 wordpress

Make the sample config file your actual config file:

# mv wordpress/wp-config-sample.php wordpress/wp-config.php

Edit the database section of wp-config.php to reflect your choices in step 2.

5 – Configure lighttpd

Open /etc/lighttpd.conf and ensure the following lines are included:

server.modules += ( "mod_cgi" )
$HTTP["url"] =~ "^/wordpress/" { 
  cgi.assign = ( ".php" => "/usr/bin/php-cgi" )
}

This tells lighttpd to treat the wordpress subdirectory of your document root as a CGI executable directory.

If you want to hide the wordpress subdirectory in your blog’s URLs, ensure the following lines are included in your /etc/lighttpd.conf as well:

server.modules += ( "mod_rewrite" )
$HTTP["host"] =~ "^example.org$" {
  url.rewrite-once = ( "^/(.*)" => "/wordpress/$1" )
}

If there are some files or directories under your document root for which page requests shouldn’t be rewritten, alter the url.rewrite-once line above as in this example:

url.rewrite-once = ( "^/((?!(sitemap.xml$|robots.txt$|images/)).*)"
                     => "/wordpress/$1" )

And while we’re at it, and assuming your DNS records are set up appropriately, why not dispense with the visionary, but entirely unnecessary www in page requests that include it?

server.modules += ( "mod_redirect" )
$HTTP["host"] =~ "^www.example.org$" {
  url.redirect = ( "^/(.*)" => "http://example.org/$1" )
}

Don’t forget to restart lighttpd after making your changes:

# /etc/init.d/lighttpd restart
6 – Complete the installation

Visit http://example.org/wp-admin/install.php in your browser (or http://example.org/wordpress/wp-admin/install.php if you’ve chosen not to hide the wordpress subdirectory as described above), give your blog a title, enter an email address and login.

 

Hope this helps.  Feel free to comment on what you have read.