Archive for the PHP Category

How to enable Custom php.ini for PHP FCGI

If you want to enable custom php.ini settings for PHP FCGI on your server then follow the below steps :

1 > Create a .htaccess file under the directory : /home/username/public_html

[email protected][#] cd /home/username/public_html
[email protected][/home/username/public_html]# vi .htaccess

And the below two lines at the top :

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi

save and quit.

2 > go to the cgi-bin directory : /home/username/public_html/cgi-bin

[email protected][#] cd /home/username/public-html/cgi-bin

and then copy the default php.ini here

[email protected][#] cp /usr/local/lib/php.ini /home/username/public_html/cgi-bin/

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

Please note that you should still be in /home/username/public_html/cgi-bin location.

[email protected][/home/username/public_html/cgi-bin] # vi php.fcgi

and then add the below code :

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

save and quit.

Now make the file php.cgi executable:

[email protected][/home/username/public_html/cgi-bin] # chmod + x php.fcgi

4 > Change ownership of files to correct user:

[email protected][/home/username/public_html/cgi-bin] chown username.username * -R

And if it still does not work for you then follow the below steps as well :

5 > Add paths to php.conf file

[email protected][#] vi /usr/local/apache/conf/php.conf

and add the below lines :

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

save and quit.

and after adding the above two lines the php.conf file should look like this :

[email protected][/usr/local/apache/conf] # cat php.conf

# 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

# End of autogenerated PHP configuration.

6 > Distill and rebuild Apache, then restart Apache

[email protected][#] /usr/local/cpanel/bin/apache_conf_distiller –update
[email protected][#] /scripts/rebuildhttpdconf
[email protected][#] /etc/init.d/httpd restart

And finally to test if the custom php.ini is working follow the steps :

[email protected][#] cd /home/username/public_html

[email protected][/home/username/public_html]# vi info.php

Add the below lines :

< ?php
phpinfo();
?>

save and quit.

Change the ownership of info.php file to user:user

[email protected][/home/username/public_html]# chown username:username info.php

Now browse the URL : http://domain.com/info.php

And search for the line : Loaded Configuration File

Loaded Configuration File /home/username/public_html/cgi-bin/php.ini


That’s all you are done.

How To Enable PHP MSSQL Extension on cpanel Linux Server

If you want to enable the PHP-MSSQL extension on a CPanel linux server then follow the below steps :

Module’s Required to be installed :

1) unixODBC :

UnixODBC is an open source project that implements the ODBC API.

ODBC is an open source project for providing application developers with a predictable API with which to access Data Sources. Data Sources include SQL Servers and any Data Source with an ODBC Driver.

2) freeTDS :

FreeTDS is a free application programming library, a re-implementation of the Tabular Data Stream protocol.

FreeTDS comes with a low level library (the TDS layer) along with a number of APIs (Application Programming Interfaces). The APIs are DB-Lib, CT-Lib, and ODBC.

3) PHP mssql.so

PHP-MSSQL is used to create the programs or applications with the MsSql database functionality.

Installation :

Install unixODBC package

[email protected][#] wget http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
[email protected][#] tar -zxf unixODBC-2.3.0.tar.gz
[email protected][#] cd unixODBC-2.3.0
[email protected][#] ./configure -prefix=/usr/local -enable-gui=no
[email protected][#] make
[email protected][#] make install

Install freeTDS package

You can install freeTDS either via yum or from a tar.gz file

Installation via yum

[email protected][#] yum install freetds*

Installation via tar.gz file

[email protected][#] wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
[email protected][#] tar -xvzf freetds-stable.tgz
[email protected][#] cd freetds-0.82/
[email protected][#] ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local
[email protected][#] make
[email protected][#] make install

Normally you don’t need to configure it, as it automatically takes the default structure, but still you can configure it as

Add entry in freetds.conf
[MyServerHOSTNAME]
host = MyServerHOSTNAME
port = 1433
tds version = 8.0

Now configure the mssql.so

[email protected][#] cd /home/cpeasyapache/src/php-5.2.13/ext/mssql
[email protected][#] phpize
[email protected][#] ./configure
[email protected][#] make
[email protected][#] make install

Then need to Enable the mssql extension in the php.ini

Usually it automatically enables the extension but if not then you can enable it manually as :

[email protected][#] echo “extension=mssql.so” >> /usr/local/lib/php.ini

Finally restart the Apache service

[email protected][#] /etc/init.d/httpd restart

That’s all you are done.

ALERT – script tried to increase memory_limit

If you are getting the above error in the apache error logs then it means the php is complied with “suhosin” on the sever.
To resolve the issue open the php.ini and remove the below lines :

extension = “suhosin.so”
suhosin.post.max_vars = 2048
suhosin.memory_limit = 32M
suhosin.session.encrypt = Off
suhosin.log.sapi = 511
suhosin.get.max_value_length = 2048

This will disable the suhosin extension .

That’s all you are done.