Install and Setup PHP5-fpm and MariaDB for Hiawatha Webserver on CentOS 7

I’m currently having great curiosity about Hiawatha (also a bit in love with). Being an alternative webserver for Apache, it is actually not very popular but recently it gets its own increasing numbers of fans. Thanks to its lightweight design, built-in security features and simplicity. There are many reasons to ditch Apache but it needs no reason to switch to Hiawatha. I’ve introduced about it in my previous post and you can read awesome review with great reasons of why you should use Hiawatha here.

This post is the next part of my Hiawatha tutorial series. So I’ll cut the “bla bla bla” part and start with the steps directly.

How to Install PHP5

Just like Nginx, Hiawatha also works nicely with PHP-fpm. And here’s how to get it installed and configured properly:

Step 0Install Hiawatha web server.

Step 1 – Login (back) to your VPS as root (or a user with sudo privilege):

Step 2 – Install PHP5 with fpm along with necessary PHP modules you love. Use command below:

1
yum install php php-fpm php-common php-cli php-devel php-gd php-imap php-intl php-mysql php-process php-xml php-xmlrpc php-zts -y

Once done, you’ll see something similar like this:

hiawatha-php-1

Setup PHP5-fpm

Step 3 – As we’ll use php-fpm module, so there are few configuration you have to adjust. First, let’s edit php.ini file using your favorite text editor like Nano:

1
nano /etc/php.ini

then find and edit ;cgi.fix_pathinfo then change it to look like this:

1
cgi.fix_pathinfo=0

Before:

After:

Once done, save and exit the editor (Control+O then Control+X).

Step 4 – Now we need to set FastCgi to work, edit php-fpm configuration file:

1
nano /etc/php-fpm.d/www.conf

and edit the line Listen = 127.0.0.1:9000 replace whit this:

listen = /var/lib/hiawatha/php-fcgi.sock

hiawatha-php-2

Step 5 – Scroll down the page a little bit and find pm = dynamic and change that to static.

hiawatha-php-3

Step 6 – You may also need to change pm.max_children value to desired lesser value:

hiawatha-php-4

Step 7 – Change chdir value to /.

hiawatha-php-5

Once done, save changes and exit (Control+O then Control+X).

Setting Server PHP Configuration

Step 8 – Now edit Hiawatha .conf file:

1
nano /etc/hiawatha/hiawatha.conf

and find this line: #CGIhandler = /usr/bin/php-cgi:php then remove the # part.

hiawatha-php-6

Step 9 – Also, replace these lines:

1
2
3
4
5
#FastCGIserver {
#   FastCGIid = PHP5
#   ConnectTo = 127.0.0.1:9050
#   Extension = php
#}

with:

1
2
3
4
5
FastCGIserver {
   FastCGIid = PHP5
   ConnectTo = /var/lib/hiawatha/php-fcgi.sock
   Extension = php
}

hiawatha-php-7

Step 10Again, you have to also edit your Virtual Host setting (still inside the same file). Look for it and remove the # symbol before the UseFastCGI = PHP5 line. It Should look like this:

hiawatha-php-8

Now you can save changes (Control+O) then exit (Control+X).

Step 11 – Restart Hiawatha and php-fpm:

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

hiawatha-php-9

How to install MariaDB

Step 1 – Issue command below:

1
yum install mariadb-server mariadb -y

Step 2 – Start MariaDB service using systemctl command (get used to it):

1
systemctl start mariadb.service

Also issue this one to make MariaDB run automatically each time your server reboot:

1
systemctl enable mariadb.service

Step 3 – So its service is now running but there is one thing you should do immediately: configuring MariaDB setup for the very first time like setting up your mysql root password. Issue this command:

1
mysql_secure_installation

Then you’ll see a series of question, just answer it accordingly. The main important part is to define your root password while everything else is just up to you or you can simply hit the “ENTER” key through each prompt to accept the default values.

You may also need to test your newly installed MariaDB by logging in as root:

1
mysql -u root -p

That’s it.

p.s: I honestly suggest you not to follow this tutorial in production server. Play with it for a while until you’re in love with it. Enjoy..

 

http://www.servermom.org/install-php5-fpm-mariadb-hiawatha-centos-7/1954/

Leave a Reply

Your email address will not be published. Required fields are marked *