#1 2013-11-25 17:29:52

ZEROF
Trusted Member
From: http://backbox.org
Registered: 2013-10-24
Posts: 124
Website

Setting FastCGI and vhost with Hiawatha webserver !

Hi all,

After writing about "How to install Hiawatha web server, PHP5 and MariaDB", here, now i will show you how to set PHP and vhost with Hiawatha webserver. We will start with php settings, but you need to know, and i will explain after, that you may have issues with some settings and you will need to check Hiawatha manual to fix them.

System OS: Debian 7
Server LES
Settings in this tutorial are for RainLoop mail client ( i will write about install soon, wordpress install etc.., i can write a book smile )

First we will set php5 config files:

nano /etc/php5/fpm/php.ini

Find and edit:

cgi.fix_pathinfo = 0 
cgi.rfc2616_headers = 1

If you have any issue with your php script, disable cgi.rfc2616_headers. With RainLoop developer we worked out to resolve this issue this weekend (you can see script was updated 23/11/2013), and now RainLoop will run smoothly with this settings.

This settings are my personal choice, not needed, but compressing files is always good for site load speed:

# Enable GZip content encoding
zlib.output_compression = On
zlib.output_compression_level = 6

Basic security settings:

# Security settings
expose_php = Off
display_errors = Off
allow_url_include = Off

Now we need to set FastCgi to work:

nano /etc/php5/fpm/php-fpm.conf

Go all down and add (ctrl+v for faster navigation):

[www]
user = www-data
group = www-data
listen = /var/lib/hiawatha/php5-fcgi.sock
pm = static
pm.max_children = 3
chdir = /

Next step is setting Hiawatha configuration file to use FastCGI (php-fpm) and setting vhost. Before doing something make hiawatha.conf backup (do same for files above):

cp /etc/hiawatha/hiawatha.conf bak.hiawatha.conf

Hiawatha configuration file have a lot of options, and for now we will just make server to run php pages. We are going to make out site folder and standard php info page. Just copy and run this command, and you will have you first index.php page inside /var/www/mysite folder.

cd /var/www/;mkdir -p mysite;chown -R www-data.www-data mysite;cd mysite;touch index.php; echo '<? phpinfo(); ?>' > index.php;chown -R www-data.www-data index.php

Setting server PHP configuration

nano /etc/hiawatha/hiawatha.conf

Find:

#CGIhandler = /usr/bin/php-cgi:php

Replace with:

CGIhandler = /usr/bin/php5-cgi:php,php5

Find:

#FastCGIserver {
#   FastCGIid = PHP5
#    ConnectTo = 127.0.0.1:9050
#    Extension = php
#}

Replace with:

FastCGIserver {
        FastCGIid = PHP5
        ConnectTo = /var/lib/hiawatha/php5-fcgi.sock
        Extension = php
}

Setting vhost in hiawatha.conf file

Inside hiawatha.conf file you will see default vhost setting, don't change them just copy them, like that you will always have default setting if you need them.

After:

# VIRTUAL HOSTS
# Use a VirtualHost section to declare the websites you want to host.
#
#VirtualHost {
#        Hostname = www.my-domain.com
#        WebsiteRoot = /var/www/my-domain/public
#        StartFile = index.php
#        AccessLogfile = /var/www/my-domain/log/access.log
#        ErrorLogfile = /var/www/my-domain/log/error.log
#        TimeForCGI = 5
#        UseFastCGI = PHP5
#        UseToolkit = banshee
#}

Add this (options with # are not active):


VirtualHost {
       Hostname = www.my-domain.com or server ip if you are doing test
       WebsiteRoot = /var/www/mysite
       StartFile = index.php
#      AccessLogfile = /var/www/my-domain/log/access.log
#      ErrorLogfile = /var/www/my-domain/log/error.log
#      TimeForCGI = 5
       UseFastCGI = PHP5
#      UseToolkit = banshee
}

Now you need to restart php-fpm and Hiawatha server.

service hiawatha stop;service hiawatha start;service php5-fpm restart

And we are done. Now you can open you first page and you will see:

capture10.png

This tutorial was made for LES members by ZEROF !

Last edited by ZEROF (2013-12-13 13:06:07)

Offline

#2 2013-11-26 09:58:31

5n1p
Trusted Member
Registered: 2013-04-02
Posts: 235
Website

Re: Setting FastCGI and vhost with Hiawatha webserver !

Thanks for posting this, haven't tried Hiawatha (first time I hear about it) but will do when I get time. smile

Offline

Board footer