Description: Cherokee is a flexible, very fast, lightweight Web server. It is implemented entirely in C, and has no dependencies beyond a standard C library. It is embeddable and extensible with plug-ins. It supports on-the-fly configuration by reading files or strings, TLS/SSL (via GNUTLS or OpenSSL), virtual hosts, authentication, cache friendly features, PHP, custom error management, and much more.
Keywords: cherokee web server httpd http

## Index → Cookbook

## Cookbook: Setting up Drupal

Setting up Drupal with Cherokee is really easy. This recipe describes the Drupal 6.x installation, which is the latest release at the time of writing.

Of course you can always access Drupal and have it automatically downloaded and deployed through the `Market` section, but should you decide to install it manually here are the steps to follow.

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.

Provided the above conditions are met, you could start Drupal’s installation and you would already be able to have your site up and running.

However, we can add several refinements to Cherokee’s settings. 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 rewriting configuration for Drupal.

3. Serve directly the static content to avoid the dynamic-processing bottle-neck.

4. Use the regex from Drupal’s .htaccess for denying access to certain paths.

With this we should be able to do everything Drupal’s supposed to do, and it should work with Imagecache’s dynamic thumbnail generation.

There are two ways of installing Drupal: it can either be installed as a new virtual server or be installed inside a directory of some of the virtual servers that already exist. We’ll begin by covering the first scenario, and will then make a trivial adaptation to cover the second case.

### Setting up Cherokee on a new virtual server

#### Default virtual server

We’ll 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

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

#### example.net

##### First step

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

Delete all the rules except `php` and `Default`.

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

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

##### Second step

Remember to set up Drupal as custom error handler for the virtual server. Do so in the `Error Handler` tab, selecting the `Custom redirections` option and sending 404 errors to Drupal.

Error | URL
--- | ---
404 Not Found | /index.php

##### Third step

Next, we need to address the clean URLs matter. To do so, create another redirection rule.

Type | Regular Expression | Redirection
--- | --- | ---
Internal | ^/(.*)\?(.\*)$ | /index.php?q=$1&$2

##### Fourth step

After this we will go straight to another milestone: directly serving static files, which is an easy task to accomplish. Just set up a `File Exists`-type rule. Check the `Match any` checkbox, and manage it with the `Static file` handler. Remember to activate the `IO Cache` option and to specify whatever expiration period you see fit for these files. If you ever edit the configuration just remember that this rule should be located after the PHP rule. Otherwise you will end up statically serving them instead of processing them via PHP. In fact it is a good idea to keep your rules for dynamic contents in a high position on your list of rules.

##### Fifth step

Now to block bad paths, as specified by the htaccess file provided with Drupal. For this we will use an internal `Regular expression`-type rule matching the following expression:

    \.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$

Handle this with the `HTTP error` handler:

Error
403 Forbidden

##### Sixth step

The last thing to do on Cherokee’s side is to specify a sixth rule that fixes an issue with how requests for the root are managed having the `File exists` handler in place. Simply define yet another redirection rule for this regular expression:

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

All done. After this you should have six rules in your list. This configuration does work. Reorder your rules accordingly if you seem to have any trouble.

List of rules

Now, to install Drupal!

### Setting up Cherokee on an existing virtual server

You will also have to define a set of 6 rules, although in this case it will be a bit different.

We will be using the default virtual server, a web directory `/blog` and we will assume we are going to install Drupal under `/var/www/drupal` on our directory tree.

#### First step

Regular Expression internal redirection.

Redirection handler

Redirection handler
Type | Regular Expression | Redirection
--- | --- | ---
Internal | ^/blog/([0-9]+)$ | /blog/index.php?q=/node/$1

#### Second step

Regular Expression internal redirection.

Redirection handler

Redirection handler
Type | Regular Expression | Redirection
--- | --- | ---
Internal | /blog/index.php | ^/blog/$

#### Third step

`/blog` directory rule with custom document root set to `/var/www/drupal`

Custom document root

#### Fourth step

Now to block bad paths, as specified by the htaccess file provided with Drupal. For this we will use an internal `Regular expression`-type rule matching the following expression:

    \.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$

Handle this with the `HTTP error` handler:

HTTP error
Error
403 Forbidden

HTTP error

#### Fifth step

Send static files as such. For this you will define a complex rule using both a `Directory` (set to `/blog`), and a `File Exist` types.

Remember to enable caching, as in the screenshot.

Rule for static files

First sub-rule
Field | Value
--- | ---
Rule type | Directory
Web directory | /blog

AND

Second sub-rule
Rule type | File Exists
--- | ---
Match any file | Enabled
Use I/O cache | Enabled
Only match files | Enabled
If dir, check index files | Disabled

#### Sixth step

The last rule related to Drupal’s configuration should be a catch-all internal redirection for a couple of regular expressions.

Redirection handler

Redirection handler
Type | Regular Expression | Redirection
--- | --- | ---
Internal | ^/(.*)\?(.\*)$ | /blog/index.php?q=$1&$2
Internal | ^/(.*)$ | /blog/index.php?q=$1

At the end of the process you should end up with a list of 8 rules. Rearrange from top to bottom according to the order given in the steps if you seem something is wrong with your setup.

Rule list

The last one and any subsequent rules will belong to the previously defined virtual server.

As before, once you are done configuring Cherokee you can proceed to set up Drupal.

### Setting up Drupal

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

Log in to MySQL:

    mysql -u root -p

And create the database for Drupal. We will be using the name drupal, the user drupaluser and the password drupalpassword, but you should set up your own.

    CREATE DATABASE drupal;
    GRANT ALL PRIVILEGES ON drupal.* TO drupaluser@localhost IDENTIFIED BY 'drupalpassword';
    GRANT ALL PRIVILEGES ON drupal.* TO drupaluser@localhost.localdomain IDENTIFIED BY 'drupalpassword';
    FLUSH PRIVILEGES;
    quit;

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

You will need to copy the config file and change the permissions manually to proceed:

    cd /var/www/drupal/sites/default
    cp default.settings.php settings.php
    chmod 644 settings.php

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

Drupal in action

Note | As of Drupal 6.14, a problem has been reported related to gzip compression of multilingual contents. You are advised to disable gzip compression for the rule that manages PHP in your Drupal `Virtual Server`. If you are not using a multilingual Drupal or find another workaround for the issue, you will probably want to enable gzip encoding on the PHP rule to increase performance.