Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to configure Apache 2.2 and PHP 5.4 with PHP-FPM using WHM / cPanel and Easy  (Read 4868 times)

0 Members and 1 Guest are viewing this topic.

Haripriya H

  • Guest
PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

This guide assumes that you have a server with a default WHM / cPanel install.

Some WHM settings prior to PHP-FPM configuration

1. Go to Home » Service Configuration » Configure PHP and suEXEC and set the following options:

PHP 5 Handler: none
Apache suEXEC: off
Apache Ruid2: off

2. Add the PHP-FPM and FastCGI flags to EasyApache:

==> vi /var/cpanel/easy/apache/rawopts/all_php5

Add the following lines:

--enable-fastcgi
--enable-fpm

Rebuild EasyApache

Go to Home » Software » EasyApache (Apache Update) and click Start customizing based on profile.

 Make sure to check the following options:

1. Select Apache 2.2.x
2. Select PHP 5.4.x
3. Disable Frontpage
4. Disable Mod SuPHP
5. Disable Mod Ruid2
6. Select MPM Worker
7. Disable MPM Prefork and MPM Event

Click Save and build to start rebuilding EasyApache with selected options.

Configure PHP-FPM

Once the EasyApache build is successfully completed proceed with the following configurations:

1. Add php-fpm to init.d scripts:

cd /home/cpeasyapache/src/php-5.4.x/sapi/fpm/
cp init.d.php-fpm.in /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm

2. Configure /etc/init.d/php-fpm

vi /etc/init.d/php-fpm

Change the following options:

prefix=
exec_prefix=
php_fpm_BIN=/usr/local/sbin/php-fpm
php_fpm_CONF=/usr/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid

3. PHP-FPM configuration file

cd /home/cpeasyapache/src/php-5.4.x/sapi/fpm/
cp php-fpm.conf.in /usr/etc/php-fpm.conf

==> vi /usr/etc/php-fpm.conf

Change the following options:

user = nobody
group = nobody

In some cases /var/run/php-fpm.pid cannot be created so you need to "touch" it:

==> vi /usr/local/apache/conf/includes/post_virtualhost_global.conf

Add the following lines:

LoadModule fastcgi_module modules/mod_fastcgi.so

<IfModule mod_fastcgi.c>
FastCGIExternalServer /usr/local/sbin/php-fpm -host 127.0.0.1:9000
AddHandler php-fastcgi .php

#<LocationMatch "/status">
# SetHandler php-fastcgi-virt
# Action php-fastcgi-virt /usr/local/sbin/php-fpm.fcgi virtual
#</LocationMatch>

Action php-fastcgi /usr/local/sbin/php-fpm.fcgi
ScriptAlias /usr/local/sbin/php-fpm.fcgi /usr/local/sbin/php-fpm

<Directory /usr/local/sbin>
Options ExecCGI FollowSymLinks
SetHandler fastcgi-script
Order allow,deny
Allow from all
</Directory>
</IfModule>

Install mod_fastcgi

cd
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
tar -xzf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
vi Makefile

Set the following:

top_dir = /home/cpeasyapache/src/httpd-2.2.x

make
make install

Final Steps

Enable PHP-FPM at boot:

chkconfig php-fpm on

Restart services:

/etc/init.d/php-fpm restart
/etc/init.d/httpd restart

Finally check your phpinfo() file. It should look like in the image below: