Monday 18 March 2013

Compiling custom php for a domain in the Apache mod fcgid environment

See if the server has got mod_fcgid installed. You can verify this by checking the following line in the file /usr/local/apache/conf/php.conf

FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php

If it is enabled, to create a custom php for a domain follow the steps below.

Download the latest version of php. As of now the latest version of php is php-5.3.8.

cd /usr/src
tar -zvxf php-5.3.8.tar.gz
cd php-5.3.8

Collect the configuration options from the remote server and configure it using those options on the new server. Make sure the prefix is set as /usr/local/php-5.3.8 and the existing prefix option is removed from the compiling options.

./configure --prefix=/usr/local/php-5.3.8 --other-options
make install

Now,check the binaries using the following command:

 /usr/local/php-5.3/bin/php-cgi -v
 PHP 5.3.8 (cgi-fcgi) (built: Jan 12 2012 01:33:10)
 Copyright (c) 1997-2011 The PHP Group
 Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    with the ionCube PHP Loader v4.0.12, Copyright (c) 2002-2011, by ionCube Ltd.
Once the php binary has been created, copy it to the home directory of the user. This is to be done as the apache server will be having suexec enabled. In this case if we are going to execute a binary fro inside a VH entry, it needs to have the user permission.

Eg: To enable custom php for the user "manoj" (

cp /usr/local/php-5.3/bin/php-cgi /home/manoj/php-cgi
chown manoj:manoj /home/manoj/php-cgi

We need to specify this binary in the apache Virtual Host.
vi /usr/local/apache/conf/httpd.conf

 go to the Virtualhost section of domain, you can see the following line. For  any VH entry modification, you need to create a config file in the path and add it there. The directory itself may be absent.
Include "/usr/local/apache/conf/userdata/std/2/manoj/*.conf"
Create a custom config file

mkdir -p /usr/local/apache/conf/userdata/std/2/manoj/
touch /usr/local/apache/conf/userdata/std/2/manoj/

Add the following line to custom_php.conf
FCGIWrapper /home/manoj/php-cgi .php

No comments:

Post a Comment

Note: only a member of this blog may post a comment.