Tuesday, June 18, 2013

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

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
wget http://us.php.net/get/php-5.3.8.tar.gz/from/this/mirror
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" (manoj.com)

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 manoj.com, 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/manoj.com/*.conf"
Create a custom config file

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

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


  1. It's going to be end of mine day, however before ending I am reading this impressive post to improve my know-how.

  2. Very good post. I certainly appreciate this site. Keep it up!

  3. Whats up very cool website!! Man .. Excellent .. Wonderful .
    . I'll bookmark your web site and take the feeds additionally? I'm satisfied to
    seek out a lot of useful information here within
    the put up, we want develop extra strategies in this regard, thank you for sharing.
    . . . . .

  4. I am no longer positive where you're getting your info, however good topic. I needs to spend some time studying more or figuring out more. Thanks for excellent info I was searching for this info for my mission.

  5. We're a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable information to work on. You have done an impressive job and our whole community will be thankful to you.