WordPress Notes

Russell Bateman
24 March 2012

I decided to set up WordPress one day as my wife's boys needed it. WordPress is the supreme weblog tool. It requires Apache, MySQL and PHP. I already had those installed as I regularly use the first two.

I followed a step-by-step I found on-line, the first of the Useful Links below. The article happened to be pretty much the version of Linux I'm running too.

There are some things I'd do differently from this article, but mostly because I don't keep everything in /var/www. I like to keep virtal host files on /etc/apache2/site-available and people's content in /home/domainuser/domain.com.

For these notes and the purpose of example, I'll assume the following:

So, WordPress is pretty small. You keep a full copy (as downloaded and unzipped) wherever it's needed. For me, this was five places; three domains for Brandon, one for Sam and one for me. You have to own wordpress to the content user who will use it, but it must also be writeable by Apache:

    /home/domainuser/domain $ chown -R domainuser:www-data wordpress
    /home/domainuser/domain $ chmod -R g+w wordpress

—otherwise, it will be hard to add themes and plug-ins: you'd have to add these by hand using bash.

This also means five new databases in MySQL which I named identical to the domain names plus db.

There are multiuser set ups for WordPress, but it's not worth the trouble for how little room it takes up (110K?).

The configuration file is named wordpress/wp-config.php and holds data including:

    define( 'DB_NAME',     'domainname_db' );
    define( 'DB_USER',     'mysqluser' );*
    define( 'DB_PASSWORD', 'mysqlpassword' );**
    define( 'DB_HOST',     'localhost' );

* Whatever name you granted rights to in MySQL.
** Whatever password you use when you granted those rights.

Here's an example of what I did in MySQL:

    mysql> CREATE DATABASE domainname_db;
    mysql> GRANT ALL PRIVILEGES ON domainname_db.* TO 'mysqluser'@'localhost' IDENTIFIED BY 'mysqlpassword';
    mysql> quit;

The changes to an Apache virtual host file are thus:

  <VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.domain.com
    ServerAlias domain.com *.domain.com
    DocumentRoot /home/domainuser/domain.com/wordpress
    ErrorLog /home/domainuser/log/domain.log
    CustomLog /home/domainuser/log/domain.log combined

    <Directory /home/domainuser/domain.com/wordpress>
        AllowOverride all

Bounce Apache thus:

    $ /etc/init.d/apache2 restart
     * Restarting web server apache2                            [Fail/OK]

If you fail to bounce Apache successfully, it's likely because of the change you just made to this virtual host file. You'll get no error or diagnostic message, just failure ([Fail]). In particular, I find that if I've not created the log subdirectory, it will fail to restart.

Content from an existing blog

There's a way to fetch content from your blogspot.com blog, for instance, and stick it at the new place you're setting up with WordPress. There is some kind of export functionality to do that with.

Installing plug-ins

The first time, it doesn't necessarily go well. It requires information and one might hesitate a little on it.

    Hostname           (my dotted quad):22
    FTP Username       domainuser
    FPT Password       domainuserpassword
    Connection Type    FTP       x FTPS (SSL)

Nothing seems to work at first. Even adding port 22 ('cause that' my ssh port) doesn't help.

There are two things wrong. First, ownership and permissions. Check those. As I copied WordPress, I had forgotten to fix those up.

That wasn't enough, however. I had to add this near the bottom of wp-config.php, something I found googling around:

    define( 'FS_METHOD', 'direct' );

This was something WordPress users already had to do back in version 2.8. Funny that WP would not have fixed this over so many ensuing versions (I'm on 3.3.1.)

And, I did have to add port 22 to the hostname above. Maybe there's configuration for that too, but I couldn't exactly find it after googling around for half an hour.

Nevertheless, there it is. This isn't intended to replace the pretty good tutorial listed in the links, but it's some good notes on how to resolve certain issues that may come up in specific cases.

Unable to do mail

When someone comes to your website and can't contact you via e-mail from the site, you need to enable PHP mail. Do this:

  1. Use the Synaptic Package Manager to install sendmail.
  2. Create php.ini at the root of the WordPress filesystem. Place the following content into it. Yes, it seems you do need the semicolons in PHP. Adjust SMTP appropriately. sendmail_from is the contact e-mail address. sendmail_path is where Synaptic installed sendmail plus some options.
        [mail function]
        SMTP = smtp.googlemail.com               ;
        sendmail_from [email protected]      ;
        sendmail_path = /usr/sbin/sendmail -t -i ;

In this way, you don't have to modify your global php.ini. This is a handy way to override whatever is in there, but just for the send-mail thing.

Unable to perform WordPress updates

For reasons of inadequate privilege, WordPress is unable to update itself. This is because it runs as www-data and hasn't rights over your (you as the WordPress user) filesystem.

To fix this, add yourself to Apache2's group. You'll need root privileges. To verify miscellaneous user information and/or group appartenance, examine the commands that follow:

    $ usermod -a -G www-data domainuser
    $ id domainuser
    $ groups domainuser

Useful Links