Jump to content



Photo

Setting FastCGI and vhost with Hiawatha webserver! - Posted By france


  • Please log in to reply
No replies to this topic

#1 Cryo Kinesis

Cryo Kinesis

    Haphost Staff

  • Moderators
  • 128 posts
  • LocationGridania, Eorzea

Posted 05 August 2014 - 05:15 PM

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.


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


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/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


Have fun, security and speed with Hiawatha !

Cryo%20Kinesis%20Haphost%20Sig2.png





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users