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.
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
make install
/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.
The version will be shown by the php binary
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.
cp /usr/local/php-5.3/bin/php-cgi /home/user/php-cgi
chown user.user /home/user/php-cgi
We need to specify this binary in the apache VH. In the file /usr/local/apache/conf/httpd.conf go to the Virtualhost section of domain domain.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/user/domain.com/*.conf"
Create a custom config file
mkdir -p /usr/local/apache/conf/userdata/std/2/user/domain.com/*.conf
touch /usr/local/apache/conf/userdata/std/2/user/domain.com/custom_php.conf
Add the following line to custom_php.conf
FCGIWrapper /home/user/php-cgi .php
Restart apache
If a case appear like custom PHP is to be enabled for a subdomain where the handler is fcgi, follow the below steps,
Copy the php-cgi file to the sub-domain. Now, this binary can be specified in .htaccess. An example is specified below,
=---
[root@server joomla30]# cat .htaccess
FCGIWrapper /home/<acctname>/public_html/joomla30/php-cgi .php
[root@server joomla30]#
=--=-=
Here, the subdomain is joomla30 .domain.com. So main domain's PHP version remain will remain intact whereas sub-domain PHP version will get change. This can be verified by accessing,
joomla30.domain.com/info.php . where info.php corresponds to phpinfo page.
Done
Note-: Verify that the apache is upgraded using phpinfo page
Above steps is when the server is cPanel. For server without any panel, do the below steps:-
How to install mod_fcgid module.
1. Install epel repo using the command:-
#rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
OR
#yum install wget
#wget dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6-8.noarch.rpm
Step 2: Now install the mod_fcgid
2. Install apache module using yum.
#yum install mod_fcgid
To confirm mod_fcgi package is installed
Run the command –
#rpm -qa|grep mod_fcgid
#httpd -M | grep fcgi
Custom PHP compilation when handler is fcgi
Custom script:-
./configure --prefix=/usr/local/php5.6 --enable-cli --enable-cgi --enable-fastcgi --enable-zend-multibyte --enable-bcmath --enable-json --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gettext --with-gmp --with-iconv --enable-mbstring --with-mcrypt --enable-memory-limit --with-mhash --enable-hash --with-ming --with-ncurses --with-openssl --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-zlib --disable-debug --with-cdb --with-gdbm --with-inifile --enable-dbx --enable-gd-native-ttf --with-jpeg --with-png --with-gd --with-xsl=shared --enable-soap=shared --enable-pdo=shared --with-sqlite=shared --with-pdo-sqlite=shared --with-pdo-mysql=shared --with-mysql --with-mysqli=shared --enable-mbstr-enc-trans --enable-mbregex --enable-magic-quotes --enable-discard-path --with-pear --enable-safe-mode --enable-track-vars --with-ttf --enable-zip=shared --enable-hts=shared --enable-htscanner=shared --enable-adodb=shared --enable-ew=shared --enable-ea=shared --with-imagick=shared --with-kerberos --with-pdo-odbc-dir
Frequest errors :-
1.configure: error: in `/usr/local/src/php-5.6.11':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
Fix:-yum install gcc*
2.configure: error: jpeglib.h not found.
For all the errors with package.h not found, use the command (yum install package-devel). In the above case, use the command:-
#yum install libpng-devel
--with-jpeg-dir=/usr - --with-jpeg
3. configure: error: Cannot find MySQL header files under /usr/bin/mysql
# yum install mysql-devel
# find / -name mysql.h
/usr/include/mysql/mysql.h
If ./confugure ....--with-mysql=/usr fails, use the following switch "--with-mysql".
Once everything is fine, use the commands.
#make
#make install
Now copy php-cgi file from the location:
"/usr/local/php5.6/bin/php-cgi" to "/home/<techmesrv>/"
If you want php-5.6 for a subdomain, add the fcgiwrapper entry as below:-
[root@techmesrv ~]# cat /home/user/public_html/<subfolder>/.htaccess
FCGIWrapper /home/<user>/php-cgi .php
[root@techmesrv ~]#
Check with info page.
Note: Fcgiwrapper
FcgidWrapper Directive
Description: The CGI wrapper setting
Syntax: FcgidWrapper command [ suffix ] [ virtual ]
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: External
Module: mod_fcgid
The given command is used to spawn FCGI server processes. If this directive is not used, the file pointed to by the request URL will be used instead. Options for the command can be included using quotation marks surrounding the command and options.
The optional suffix argument restricts the use of this FCGI server to all URLs with the given exact path suffix. A suffix needs to start with '.'.
The virtual flag signals that there will be no check whether the request URL actually points to an existing file. The only file which needs to exist is the wrapper itself.
The directive can be used multiple times. A wrapper defined without a suffix is used as a default in case no suffix matches.
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.
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
make install
/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.
The version will be shown by the php binary
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.
cp /usr/local/php-5.3/bin/php-cgi /home/user/php-cgi
chown user.user /home/user/php-cgi
We need to specify this binary in the apache VH. In the file /usr/local/apache/conf/httpd.conf go to the Virtualhost section of domain domain.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/user/domain.com/*.conf"
Create a custom config file
mkdir -p /usr/local/apache/conf/userdata/std/2/user/domain.com/*.conf
touch /usr/local/apache/conf/userdata/std/2/user/domain.com/custom_php.conf
Add the following line to custom_php.conf
FCGIWrapper /home/user/php-cgi .php
Restart apache
If a case appear like custom PHP is to be enabled for a subdomain where the handler is fcgi, follow the below steps,
Copy the php-cgi file to the sub-domain. Now, this binary can be specified in .htaccess. An example is specified below,
=---
[root@server joomla30]# cat .htaccess
FCGIWrapper /home/<acctname>/public_html/joomla30/php-cgi .php
[root@server joomla30]#
=--=-=
Here, the subdomain is joomla30 .domain.com. So main domain's PHP version remain will remain intact whereas sub-domain PHP version will get change. This can be verified by accessing,
joomla30.domain.com/info.php . where info.php corresponds to phpinfo page.
Done
Note-: Verify that the apache is upgraded using phpinfo page
Above steps is when the server is cPanel. For server without any panel, do the below steps:-
How to install mod_fcgid module.
1. Install epel repo using the command:-
#rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
OR
#yum install wget
#wget dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6-8.noarch.rpm
Step 2: Now install the mod_fcgid
2. Install apache module using yum.
#yum install mod_fcgid
To confirm mod_fcgi package is installed
Run the command –
#rpm -qa|grep mod_fcgid
#httpd -M | grep fcgi
Custom PHP compilation when handler is fcgi
Custom script:-
./configure --prefix=/usr/local/php5.6 --enable-cli --enable-cgi --enable-fastcgi --enable-zend-multibyte --enable-bcmath --enable-json --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gettext --with-gmp --with-iconv --enable-mbstring --with-mcrypt --enable-memory-limit --with-mhash --enable-hash --with-ming --with-ncurses --with-openssl --enable-shmop --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-zlib --disable-debug --with-cdb --with-gdbm --with-inifile --enable-dbx --enable-gd-native-ttf --with-jpeg --with-png --with-gd --with-xsl=shared --enable-soap=shared --enable-pdo=shared --with-sqlite=shared --with-pdo-sqlite=shared --with-pdo-mysql=shared --with-mysql --with-mysqli=shared --enable-mbstr-enc-trans --enable-mbregex --enable-magic-quotes --enable-discard-path --with-pear --enable-safe-mode --enable-track-vars --with-ttf --enable-zip=shared --enable-hts=shared --enable-htscanner=shared --enable-adodb=shared --enable-ew=shared --enable-ea=shared --with-imagick=shared --with-kerberos --with-pdo-odbc-dir
Frequest errors :-
1.configure: error: in `/usr/local/src/php-5.6.11':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
Fix:-yum install gcc*
2.configure: error: jpeglib.h not found.
For all the errors with package.h not found, use the command (yum install package-devel). In the above case, use the command:-
#yum install libpng-devel
--with-jpeg-dir=/usr - --with-jpeg
3. configure: error: Cannot find MySQL header files under /usr/bin/mysql
# yum install mysql-devel
# find / -name mysql.h
/usr/include/mysql/mysql.h
If ./confugure ....--with-mysql=/usr fails, use the following switch "--with-mysql".
Once everything is fine, use the commands.
#make
#make install
Now copy php-cgi file from the location:
"/usr/local/php5.6/bin/php-cgi" to "/home/<techmesrv>/"
If you want php-5.6 for a subdomain, add the fcgiwrapper entry as below:-
[root@techmesrv ~]# cat /home/user/public_html/<subfolder>/.htaccess
FCGIWrapper /home/<user>/php-cgi .php
[root@techmesrv ~]#
Check with info page.
Note: Fcgiwrapper
FcgidWrapper Directive
Description: The CGI wrapper setting
Syntax: FcgidWrapper command [ suffix ] [ virtual ]
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: External
Module: mod_fcgid
The given command is used to spawn FCGI server processes. If this directive is not used, the file pointed to by the request URL will be used instead. Options for the command can be included using quotation marks surrounding the command and options.
The optional suffix argument restricts the use of this FCGI server to all URLs with the given exact path suffix. A suffix needs to start with '.'.
The virtual flag signals that there will be no check whether the request URL actually points to an existing file. The only file which needs to exist is the wrapper itself.
The directive can be used multiple times. A wrapper defined without a suffix is used as a default in case no suffix matches.