Cherokee on UbuntuCherokee is a smoking hot up-and-coming web server capable of hanging with Apache while consuming exponentially less resources than its older sibling. As we wrote earlier, Cherokee saved TechMiso from Apache scalping all available RAM, ultimately allowing us to continue to provide the same service we provide today but with far better memory consumption. Learn how to install and configure Cherokee, MySQL, PHP and WordPress on Ubuntu 9.04 Jaunty Jackalope for a lean, mean, efficient web serving machine.

As an aside, TechMiso is currently operating on a 256 slice at SliceHost. If you are a SliceHost user then the following HOWTO should work without the need for any peculiar tweaks. This should work right out the box.

1. Install MySQL

# sudo apt-get install mysql-server mysql-client

The above merely installs MySQL with the defaults, which is entirely insecure out the box. Since we take security seriously we need to set a root password and perform additional security checks before proceeding. Execute the following command and follow the on-screen prompts.

# mysql_secure_installation

MySQL is now installed and should operate fairly smooth and without issue. However, if the goal is to strictly use WordPress then the MySQL daemon should be tweaked a bit in order to save on memory consumption.

# sudo vi /etc/mysql/my.cnf

Ensure the following entries have similar options set in the MySQL configuration file:

key_buffer = 16M
max_allowed_packet = 8M
thread_stack = 64K
thread_cache_size = 4
skip-innodb

The last entry is an important one and will lower MySQL memory consumption considerably.

2. Install PHP

WordPress relies upon the PHP scripting language and MySQL database storage to perform just about every ounce of its magic. For this reason it is imperative that not only the plain vanilla PHP be installed but the ability for PHP to interface with MySQL as well.

Additionally, since Cherokee is not compatible with Apache modules it is necessary to install the CGI version of PHP rather than mod_php. This is an important distinction between Apache and Cherokee. Although in most testing mod_php outperforms php-cgi, the speed differences are so negligible that most folks will never notice.

# sudo apt-get install php5-cgi php5-mysql

3. Install Cherokee

Cherokee can be installed in a variety of ways. By default, Ubuntu has support for Cherokee in its existing repositories. However, development on Cherokee is happening at breakneck speeds. Since the default Ubuntu repositories are incapable of keeping up with this type of rapid development, that leaves only two real options: compile from source or use an alternative repository. For the sake of this HOWTO we opted for the latter, since using apt is the preferred Ubuntu installation method.

The first thing we need to do is modify the apt sources.list file to point to a repository where Cherokee can be found.

# sudo vi vi /etc/apt/sources.list

Add the following lines to the end of /etc/apt/sources.list.

deb http://ppa.launchpad.net/cherokee-webserver/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/cherokee-webserver/ppa/ubuntu jaunty main

Before being able to download the files in the repository the security key used to sign the packages needs to be added to the operating system. This effectively ensures you the Cherokee files being downloaded from Launchpad have not been modified since they were built and that you are downloading Cherokee from a trusted repository.

To make things easy for our readers, simply execute the following command. If you want to verify the accuracy of the key then please double-check the data against that provided on this page. Otherwise, just perform the following:

# sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0x0ad0b667b67daa477f5ff89f51bb8e83eba7bd49

Now that Ubuntu is configured to read from the proper repository and is capable of ensuring the authenticity of files downloaded from said repository, we need to run an update and pull the latest list of available files. Perform an update with the following:

# sudo apt-get update

Upon completion Cherokee can be easily installed with apt, just like any other application install on Ubuntu.

# sudo apt-get install cherokee

This will complete a basic installation and configuration of Cherokee web server on Ubuntu. Test the installation by starting Cherokee to ensure it is capable of executing without issue.

# sudo /etc/init.d/cherokee start

Assuming everything went as planned then Cherokee should start. Surf to your server to ensure a basic static page can be served without any problems. If you are able to load a page in your browser then the next step is ensuring PHP parsing is functioning properly.

# vi /etc/www/test.php

Once in the editor, paste the following PHP code in to the file:

<?php echo phpinfo(); ?>

Surf to http://domain.com/test.php and presumably a PHP information page should be displayed in the browser if everything is functioning as expected. If PHP is not properly parsing the file then it may be necessary to do a little digging to see what the problem may be. During the Wordpress installation phase of this HOWTO we will cover a Cherokee configuration option which may help reconcile any potential PHP roadblocks at this juncture. It might be worthwhile to place your troubleshooting in a holding pattern until that area is covered.

If you previously installed Apache and would like to run Cherokee instead of Apache then you need to ensure the latter no longer automatically starts upon system reboot. Perform the following to remove Apache from the different runlevel startup links:

# sudo update-rc.d -f apache remove

At this point the hard part is done. MySQL, PHP and Cherokee are all installed and should be completely functional.

4. Installing WordPress – Configuring Cherokee for WordPress

Cherokee is the perfect medicine for serving up a WordPress site. It is not only perfect for small sites but large ones as well, generally outperforming Apache in most respects. WordPress is not that complicated but does present a few challenges for Cherokee and will not function right out the box.

Before installing and configuring WordPress there are some modification to the Cherokee configuration to be completed. These changes facilitate ensuring WordPress is completely functional.

As with most Ubuntu-based web servers, the document root is in /var/www. For the sake of the WordPress installation portion of the HOWTO we are going to make a couple of assumptions:

  • The document root will remain /var/www and not be moved elsewhere.
  • WordPress will be installed in the document root as opposed to a subdirectory. Rather than install in /var/www/wordpress we are placing the WordPress installation in the document root. There is no specific reason for using either method, though the former does add additional unnecessary complication to the equation. Our intent is to keep this as simple as possible.

As mentioned in our initial Cherokee write-up, one of the exciting features of the product is the web-based administration tool, cherokee-admin. Rather than fiddling around with text files which may not mean much to an administrator new to Cherokee, the server can be entirely setup from cherokee-admin. Just about every feature of Cherokee can be set from with this beautiful utility.

Cherokee was built with security in mind so by default cherokee-admin does not allow connections from the world. The easy way to fix this is to setup an SSH tunnel using your favorite SSH client.

Mac and Linux SSH tunnels are very easy to setup. PuTTY on Windows is more than capable of handling SSH tunneling so the configuration should not be much different than the following command-line SSH client:

# ssh -L 9090:127.0.0.1:9090 domain.com

Once logged in, execute the following command to launch cherokee-admin:

# sudo cherokee-admin

Cherokee-admin should launch and present you with both a username (admin) and one-time password. Copy the password to the clipboard and fire up http://127.0.0.1:9090/ in a web browser. When prompted with the HTTP authentication dialog merely enter those same credentials. Assuming the authentication was successful, the browser should be illuminated by the beauty and simplicity of cherokee-admin.

Now that cherokee-admin is functioning it is time to configure Cherokee to handle WordPress. For the sake of this HOWTO we are going to make some minor modifications to the default Cherokee virtual host rather than setup a brand new one. Though if desired, you may configure a new virtual host with the following rules and WordPress should function just fine.

  • Surf to Virtual Servers and then click on default so we can configure the catch-all virtual host.
  • Once there, you should be presented with a page with seven configuration tabs. Select Behavior.
  • Delete all the rules except for default and php (if it exists) by clicking the icon to the very right of each rule. Do not delete the default rule.
  • Modify the default rule to force all traffic to WordPress by clicking on default and selecting the Handler tab.
  • On the Handler tab, change the handler setting to Redirection, Show to Internal, Regular Expression to ^(.+)$ and Substitution to /index.php and hit Enter to confirm the modification.

If everything went as planned then the configuration should look like so:

cherokee-admin-default-handler.jpg

As mentioned on the Cherokee WordPress cookbook, it is a smart idea to add a few additional rules to fine tune Cherokee’s handling of WordPress. Take a look at the following image and create a similar set of rules, carefully not changing the handler defaults once selecting the proper handler type. It is all pretty straightforward and easy to do, especially since cherokee-admin is such a good facilitator for configuring Cherokee.

Essentially, the idea is to add a List & Send handler for the following directories: /wp-includes, /wp-content and /wp-admin. If you are running Mint then you should add the same for that directory as well.

cherokee-admin-wordpress-handlers-small.jpg

At this point, now that all the configuration changes have been prepared, it is necessary to save them and restart Cherokee so they take affect. Merely click the Save Changes button on the left-hand side of the cherokee-admin interface and if all went well you should see a message at the top stating, “Configuration saved. Graceful restart performed.”

Cherokee is now prepared for WordPress and should allow the content management system to function without issue, assuming all directions until this point have been followed.

5. Installing WordPress – Preparing MySQL

Prior to installing WordPress it is necessary to prepare the MySQL database and user permissions. It is good practice to create a database and user specifically for WordPress use rather than reusing existing ones. To perform these actions it is necessary to launch the MySQL command-line client as such.

# mysql -u root -p

Use the root password specified in Step 1 when MySQL was installed and the mysql_secure_installation command was executed. Once in MySQL, a database and user need to be created using the following commands.

CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress_user@localhost IDENTIFIED BY 'some_password';
FLUSH PRIVILEGES;
quit;

The database name wordpress, user wordpress_user and password some_password can all be substituted with values you feel more comfortable using. At this point, MySQL is prepped and ready for WordPress.

6. Installing WordPress

Download a copy of WordPress and unzip it to /var/www. The root WordPress files should reside directly in /var/www rather than a subdirectory like /var/www/wordpress. Remember, we decided to install WordPress in our document root and not elsewhere.

In your web browser surf to http://your-domain.com and and follow the on-screen instructions for setting up WordPress. When asked, ensure you enter the proper MySQL database, user and password as specified in Step 5. Do not use the root user and password for WordPress otherwise you risk getting your entire setup owned. Who wants that?

7. Success!

Assuming all went well, and this HOWTO was properly followed, you should now have a completely functioning Cherokee, MySQL, PHP and WordPress installation. This setup is not only perfect for a server with minimal resources but any server and for just about any reason. By opting for Cherokee, you ultimately support a small yet vibrant community of exceptional developers and users who are interested in this wicked little web server.

8. Resources