Hiawatha is a web server with simplicity, ease of use, and security. It’s the perfect solution for smaller servers, older hardware, or embedded machines – but it also runs great on high-powered servers as well. When combining the Hiawatha web server with PHP-FPM and MySQLYou can have a powerful web server that is both lightweight and secure. In this tutorial, I’ll show you how to install Hiawatha MySQL on Debian. By the end of the tutorial, you’ll have a fully functional Hiawatha web server that you can use PHP-FPM and MySQL to accomplish your needs!
This article was written for Debian Wheezy (64-bit), but it may work with other versions of Debian with minor adjustments.
Please note that you need to either be root or have root access via su / sudo to perform all the steps in this tutorial.
The first thing you’ll need to do is to set up the repository for the Hiawatha Webserver. You may also compile it on your own if you wish, but for this tutorial, we’ll be using the pre-compiled binaries.
First, get and install the repository’s public key:
apt-key adv --recv-keys --keyserver keys.gnupg.net 79AF54A9Open up and edit sources.list with:
nano /etc/apt/sources.listAdd the following to sources.list:
deb http://mirror.tuxhelp.org/debian/ squeeze mainSave the changes that you have made, then exit.
Now, update with:
apt-get updateInstall Hiawatha by entering:
apt-get install hiawathaMake sure that Hiawatha works by opening your web browser and entering:
http://YOURAKLWEBHOSTIPGOESHEREAnd you should see an Installation Successful webpage on your brand new Hiawatha web server.
Install MySQL by running the following command:
apt-get install mysql-serverDuring the installation, you’ll be presented with an option to set the root password for MySQL. Make sure to pick a secure password and enter it in, then enter it in again when it asks you to confirm your new root MySQL password.
Once the MySQL Installation has finished, run:
mysql_secure_installationThis will go through some simple steps to secure your new MySQL server, which are:
What is the current MySQL root password? (enter that in)
Change the root MySQL password? (enter N for no)
Remove anonymous users? (Select Y for yes)
Disallow root login remotely? (Select Y for yes)
Remove any test databases? (Select Y for yes)
Reload privilege tables? (Select Y for yes)
Your MySQL Server is now installed and secured!
Install PHP-FPM and some extra extensions by entering:
apt-get install php5-fpm php5-mysql php5-gd php5-curlEdit php.ini…
nano /etc/php5/fpm/php.ini… and find the line where it says: cgi.fix_pathinfo=1. Uncomment this line and change the value to 0 so that it matches:
cgi.fix_pathinfo=0Save and exit.
Edit www.conf…
nano /etc/php5/fpm/pool.d/www.conf… and uncomment the line that says ;listen.mode = 0660, so that it matches:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660Save and exit.
Restart PHP-FPM so that the changes you have made take effect:
service php5-fpm restartIn this part, you’ll be configuring Hiawatha and setting it up to serve PHP and/or your website files. First, open up hiawatha.conf.
nano /etc/hiawatha/hiawatha.confFind the line that says #CGIhandler = /usr/bin/php-cgi:php. Uncomment this line so that it matches the following:
CGIhandler = /usr/bin/php-cgi:phpNow, uncomment the entire FastCGI lines and replace 127.0.0.1:2005 them with /var/run/php5-fpm.sock so that it looks exactly like this:
FastCGIserver {
FastCGIid = PHP5
ConnectTo = /var/run/php5-fpm.sock
Extension = php
}Go down to the section that says VIRTUAL HOSTS and uncomment the entire section. Replace your-domain-goes-here.com with the website domain that you will be using.
Change the Hostname field to your domain www.your-domain-goes-here.com
Change the WebsiteRoot field to /var/www/your-domain-goes-here.com/public_html
Change the AccessLogFile field to /var/www/your-domain-goes-here.com/logs/access.log
Change the ErrorLogFile field to /var/www/your-domain-goes-here.com/logs/error.log
Remove the line that says UseToolKit = banshee
It will look like this when you are finished:
VirtualHost {
Hostname = www.your-domain-goes-here.com
WebsiteRoot = /var/www/your-domain-goes-here.com/public_html
StartFile = index.php
AccessLogfile = /var/www/your-domain-goes-here.com/logs/access.log
ErrorLogfile = /var/www/your-domain-goes-here.com/logs/error.log
TimeForCGI = 5
UseFastCGI = PHP5
}Save and exit.
Create the directories needed for your website files.
mkdir -p /var/www/your-domain-goes-here.com/public_html
mkdir /var/www/your-domain-goes-here.com/logsRestart Hiawatha.
service hiawatha restartAt this point, you’re ready to begin uploading your PHP files to /var/www/your-domain-goes-here.com/public_html. Enjoy Hiawatha!
There are many possible security combinations and tuning commands that you can use with Hiawatha. Visit the Hiawatha manpage (or website) for a list of different commands and additional HOWTOs.
Now that you have a working Hiawatha web server with PHP and MySQL, perhaps you would like to install WordPress? To get WordPress working with Hiawatha, you’ll need to make a small change to hiawatha.conf.
nano /etc/hiawatha/hiawatha.confAdd the following line to the inside of your virtual host section (below the UseFastCGI = PHP5 line).
UseToolkit = wordpressAdd this configuration outside of your virtualhost config (preferably in the UrlToolKit section in hiawatha.conf).
UrlToolkit {
ToolkitID = wordpress
RequestURI exists Return
Match .*\?(.*) Rewrite /index.php?$1
Match .* Rewrite /index.php
}Save and exit.
With the URL Toolkit rewrites for WordPress in place, you can install WordPress in the same fashion as you would for any other web server. You will want to make sure that the permissions of all WordPress files in /var/www/your-domain-goes-here.com/public_html are set to www-data:www-data so that WordPress can make the changes for themes and plugins.