How to enable custom php in cPanel server with PHP CGI?

How to enable custom php in cPanel server with PHP CGI?

What is cPanel?

cPanel is a Web Hosting Control Panel which works in Linux OS. The basic work of cPanel is to provide graphical interface and automatic designing tools for hosting any website. cPanel uses a three level structure which provides abilities for administrators, resellers, and website end-users to control the various parts of website and server administration through any of the standard web browser. In addition to the interface section, cPanel has command line and API based access too which allows the third party software vendors, web hosting organizations, and other developers to automate the standard system administration process.

What is PHP CGI?

When it's about PHP, then the language PHP is a combination of CLI & CGI program and it can be used for any kind of CGI processing. When we use CGI version of PHP then it enables all the users to run different different PHP Enabled pages under different different user id.

Here are the steps which makes it possible for the user to custom php.ini file :

1. Copy and Edit default php.ini

Code:
cd /home/user/public-html/cgi-bin
cp /usr/local/lib/php.ini /home/user/public_html/cgi-bin
vi php.ini


2. As a test change one of the variables like register_globals from:

Code:
register_globals = Off
To:
Code:
register_globals = On

3. Create php.fcgi file to load custom php.ini

Code:
vi php.fcgi

Note : You must still be in /home/user/public_html/cgi-bin location.

4. Put into file:

Code:
#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=10
exec /usr/local/cpanel/cgi-sys/php5


5. Save file, then made executable:

Code:
chmod +x /home/user/public_html/cgi-bin/php.fcgi
Change ownership of files to correct user:


Code:
chown -R user:user /home/user/public_html/cgi-bin/
Edit .htaccess to point to php.fcgi wrapper


Code:
cd /home/user/public_html
vi .htaccess


Put at top of file:
Code:
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi


6. Add paths to php.conf file

Add the following lines to /usr/local/apache/conf/php.conf file:

Code:
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php


Yours will probably look similar to the following after those lines are added:

Code:
# Fastcgi configuration for PHP5
LoadModule fcgid_module modules/mod_fcgid.so
MaxRequestsPerProcess 500
AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
Action php5-fastcgi /cgi-bin/php.fcgi
AddType application/x-httpd-php .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml


7. Distill and rebuild Apache, then restart Apache

Run these commands:
Code:
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
Author
bhawanisingh
Views
3,772
First release
Last update
Rating
0.00 star(s) 0 ratings
Top