## Index → Cookbook

## Cookbook: Setting up Wordpress

Setting up Wordpress with Cherokee is really easy. We will assume that our `Document Root` directory is `/var/www/wordpress` of the server we are working on. This recipe uses Wordpress 2.6.3, which is the latest release at the time of writing.

You will need PHP support correctly configured in Cherokee, and PHP with the MySQL module installed. The default configuration already provides a valid PHP configuration for Cherokee if you have php-cgi installed, but you can follow the appropriate recipe about setting up PHP in case you don't have it available for some reason.

Under these conditions, you could start Wordpress's installation and you would already be able to have your site up and running.

However, we can add several refinements to Cherokee's setting. Mainly:

1. Forward all requests for www.example.net (or whatever domain is resolved to our machine) to example.net

2. Set up an appropriate url rewrite configuration for Wordpress, so you can enable permalinks.

3. Serve directly as static content some specific file types and directories, avoiding any other file requests and eliminating this way any security risk related to vulnerable archives.

WARNING: Beware of the long time it gets Wordpress to get through the installation. It has been known to exceed the timeout that Cherokee uses as default, and while this will still somwtimes allow for a complete installation, it will most probably cause a failure while delivering the last page of the process. Since this is the page that provides the random password needed to access the admin page of Wordpress, you installation will be useless.

If you encounter this problem, please increase your server's `timeout` value, under the `Basic Behavior` paragraph of the `General` tab, and start over.

If you are going to attempt to make an installation as is, with no reconfiguration of Cherokee whatsoever, you can skip right to the secction Setting up Wordpress.

### Setting up Cherokee

#### Default virtual server

We're assuming we have the default configuration initially provided by Cherokee Admin.

We will begin by cloning the default virtual server, just to keep the default PHP configuration. Create a clone named `example.net`.

Then, we'll delete every erasable rule in the default virtual server since we are going to use it to redirect every petition not matched by the example.net virtual server. We will set the remaining one to be managed by the `Redirection` handler, like this:

Type | Regular Expression | Redirection
--- | --- | ---
External | ^(.*)$ | http://example.net/$1

After that, this is how the list of rules for this server should look like.

This clears the first milestone. The remaining ones will be accomplished by tweaking the `example.net` virtual server.

#### example.net

Remember to set up the `Document root` to `/var/www/wordpress`.

Delete all the rules except `php` and `Default`. We're heading right to the second milestone now.

As previously, we will manage the `Default` rule with the redirection handler.

Type | Regular Expression | Redirection
--- | --- | ---
Internal | ^/(.*)$ | /index.php

After this, most of the redirections will work. We'll set some more rules to fine tune the rest of Wordpress' features. Those will be `Directory` type rules for the following directories: `wp-includes`, `wp-content` and `wp-admin`. These are to be managed with the `List & Send` handler.

The third milestone, directly serving static files, is an easy task to accomplish. This step is not required by Wordpress, but we will be treating as static the contents of a couple of directories and the sitemap files generated by our Google XML Sitemaps plugin of choice.

To do this, we will be creating `Directory` type rules for the `images` and `static` directory, and a `Regular Expression` type rule for the sitemap.

Type | Value
--- | ---
Directory | /images
Directory | /static
Regular Expression | /sitemap.xml.*

Remeber to manage them with a handler that can serve files: `Static content` and `List & Send`.

Almost any evaluation order of your rules will suffice, as long as the one that handles the PHP files is the first one. This is a valid one, for instance.

### Setting up Wordpress

First download and uncompress the distributed Wordpress release into `/var/www/wordpress`, and create a database suitable for the installation.

Log in to MySQL:

    mysql -u root -p

And create the database for Wordpress. We will be using the name wp, the user wpuser and the password wppassword, but you should set up your own.

    CREATE DATABASE wp;
    GRANT ALL PRIVILEGES ON wp.* TO wpuser@localhost IDENTIFIED BY 'wppassword';
    GRANT ALL PRIVILEGES ON wp.* TO wpuser@localhost.localdomain IDENTIFIED BY 'wppassword';
    FLUSH PRIVILEGES;
    quit;

Then point your web browser to `http://localhost` and follow the instructions provided by the installer.

And the installation will be automatic. Just fill up the requested values and you will obtain the following results once your are through.

With that, you are done installing. Let's log in and make the last adjustments.

Once we're logged, we can configure the way `permalinks` are displayed. Just use the `Settings`→`Permalinks` menu, and adjust the way the links are to be rewritten.

Remember to set up the plugins that are of interest for you, such as the sitemaps generator, in a fashion compatible with what you configured in Cherokee.

And voilà! You have a Wordpress installation working flawlessly with Cherokee.