PmWiki on nginx

I’ve been looking at a few wiki packages for a project and found PmWiki to my liking – under active development, a nice default skin, easily customizable, and it does not require a database. My personal choice is ikiwiki, which I run on my laptop for quick notes, but since this project is for a non-technical user, I decided to look first at end-user ease of usability, the availability of free themes, and possible integration with WordPress in the future.

The vast majority of web software packages assume that the admin is running Apache. It is always fun and interesting to sort out how to incorporate the various configurations for nginx, when most of the software packages only document mod_rewrite rules or just throw things in .htaccess files.

This is a very simple install of PmWiki focused only on getting the nginx configuration right. This assumes that you already have an nginx site configured to run PHP scripts through fastcgi – I’m not documenting that here.

Grab the source tarball from the Download page on http://pmwiki.org/, or use Subversion to fetch the latest stable release ($DOCROOT is your site document root):

cd $DOCROOT
svn export svn://pmwiki.org/pmwiki/tags/latest pmwiki --force

Now, hitting the URL in a browser ($HOST is your site, of course) – http://$HOST/pmwiki/pmwiki.php – you should see a little note about PmWiki needing write access to the document store directory – a quick permissions change:

chmod 2775 pmwiki/

Then hit the URL again – you should see the Main page of PmWiki after it does it’s configuration 🙂 but no so fast! Secure that directory now that we are basically done installing:

chmod 0755 pmwiki/

Follow the notes for adding a one-liner wrapper index.php if you like.

OK, so PmWiki should be working, but probably has some hidden configurations:

$ find pmwiki/ -name .ht*
pmwiki/scripts/.htaccess
pmwiki/cookbook/.htaccess
pmwiki/local/.htaccess
pmwiki/docs/.htaccess
pmwiki/wiki.d/.htaccess

Yep.. each of those .htaccess files, except pmwiki/docs/.htaccess, is a “Deny from all” so that files in those directories cannot be accessed publicly. I also added the directory pmwiki/wikilib.d/ which has the default local PmWiki documentation files and other local wiki pages – OK.

pmwiki/docs/.htaccess is a modification of mime type, so that any files in that directory ending in ‘.php’ will be rendered as plain text – ah, the sample config.php is in there – OK.

Here is my resulting nginx vhost configuration for wiki.example.com (replace with your own server_name and site root directory):

server {
  listen 80;
  charset utf-8;
  server_name wiki.example.com;
  access_log /var/log/nginx/wiki.access.log;
  root /var/www/wiki;
  index index.html index.php;
  
  # configs from pmwiki .htaccess files
  location ~ ^/pmwiki/(cookbook|local|scripts|wiki.d|wikilib.d) {
    deny all;
  }
  location ^~ /pmwiki/docs {
    autoindex on;
    types {
      text/plain php;
    }
  }

  # pass PHP scripts to FastCGI server listening on 127.0.0.1:8080
  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:8080;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
  }

  # deny access to all .dot-files
  location ~ /\. {
    deny all;
  }
}

This should give a working default PmWiki site running on nginx with the same functionality and secured directories as if you installed on Apache – make sure this basic setup is working right before moving on.

Next configuration steps for my install will be rewrite rules for shortened clean URLs.

Update: here’s the next post on PmWiki Clean URLs on nginx

One thought on “PmWiki on nginx”

Comments are closed.