Tuesday, August 23, 2011

Confgure custom php for a particular domain

php 5.3.6 is currently not available in the easy apache script. So if any user want to use thi version in a shared cpanel server, we can manually compile and then enable this version for that user using an htaccess rule.

==============
cd /usr/src

wget http://in2.php.net/get/php-5.3.7.tar.gz/from/us.php.net/mirror

tar -zxf php-5.3.7.tar.gz

cd php-5.3.7

use the same configure option as of 5.3.6 and give the prefix as say for example /usr/local/jibin/php5.3/

=================
./configure --prefix=/usr/local/jibin/php5.3 --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-mbstring --enable-pdo=shared --enable-sockets --enable-wddx --enable-zend-multibyte --enable-zip --with-curl=/opt/curlssl/ --with-curlwrappers --with-freetype-dir=/usr --with-gd --with-gettext --with-imap=/opt/php_with_imap_client/ --with-imap-ssl=/usr --with-jpeg-dir=/usr --with-kerberos --with-libexpat-dir=/usr --with-libxml-dir=/opt/xml2/ --with-mcrypt=/opt/libmcrypt/ --with-mhash=/opt/mhash/ --with-mysql --with-mysqli --with-openssl=/usr --with-openssl-dir=/usr --with-pcre-regex=/opt/pcre --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-png-dir=/usr --with-pspell --with-sqlite=shared --with-tidy=/opt/tidy/ --with-xmlrpc --with-xpm-dir=/usr --with-xsl=/opt/xslt/ --with-zlib --with-zlib-dir=/usr
=================

make

make install

copy the php.ini file from the location /usr.local/lib/php.ini.

cp /usr/local/lib/php.ini /usr/local/jibin/php5.3/lib/

NOTE: Please edit the file php.ini i.e extensions and change the path to /usr/local/jibin/php5.3/lib/php/extensions

Once compiled you can check the version using the command

/usr/local/php-5.3.7/bin/php-cgi -v

add the following line in the section “handlers” in the suphp.conf file if the default php in the server is compiled as suphp

vi /opt/suphp/etc/suphp.conf

application/x-httpd-php5.3=”php:/usr/local/jibin/php5.3/bin/php-cgi”

Now add the rule to the file “pre_main_2.conf” for enabling this version for any particulkar domain.

vi /usr/local/apache/conf/includes/pre_main_2.conf


Allow from All


suPHP_AddHandler application/x-httpd-php5.3
AddType application/x-httpd-php5.3 .php


To remove first 10 lines

tail -n +11 filename

To change the gateway

to delete the current gateway:sudo route -n del default
to add the new gateway : sudo route add gw default IP

To change env

PATH=$PATH:/usr/local/sbin

cpanel restart error

=============
Starting tailwatchd: Can't locate Getopt/Param/Tiny.pm in @INC (@INC contains: /usr/local/cpanel /usr/local/cpanel/Cpanel/CPAN/overload/__Time /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/cpanel/Cpanel/TailWatch.pm line 17.
BEGIN failed--compilation aborted at /usr/local/cpanel/Cpanel/TailWatch.pm line 17.
Compilation failed in require at /usr/local/cpanel/libexec/tailwatchd line 14.
BEGIN failed--compilation aborted at /usr/local/cpanel/libexec/tailwatchd line 14.
[FAILED]
Starting cPanel Log services: Can't locate Unix/PID.pm in @INC (@INC contains: /usr/local/cpanel/3rdparty/lib/perl/5.8.8/x86_64-linux-thread-multi/auto /usr/local/cpanel/3rdparty/lib/perl/5.8.8/x86_64-linux-thread-multi /usr/local/cpanel/3rdparty/lib/perl/5.8.8 /usr/local/cpanel/3rdparty/lib/perl /usr/local/cpanel /usr/local/cpanel/3rdparty/lib/perl /usr/local/cpanel/Cpanel/CPAN/overload/__Time /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/cpanel/libexec/cpanellogd line 13.
BEGIN failed--compilation aborted at /usr/local/cpanel/libexec/cpanellogd line 13.
================


root@server1 [~]# ls -alh /usr/bin/perl
-rwxr-xr-x 2 root root 19K Jun 13 05:58 /usr/bin/perl*
root@server1 [~]# ls -alh /usr/local/bin/perl
-rwxr-xr-x 2 root root 1.2M Aug 10 18:26 /usr/local/bin/perl*


One should be a binary file, and the other should be a symlink to the binary file. To fix the problem, I moved the perl from /usr/local/bin to /root and created a symlink to /usr/bin/perl in its place:


root@server1 [~]# mv /usr/local/bin/perl /root/
root@server1 [~]# ln -s /usr/bin/perl /usr/local/bin/perl

To check the total running time of proces

ps -eo pid,etime,args

Script to split a column into multiple columns

awk '{a[NR%14+1]=a[NR%14+1]" "$0} END {for (i in a){print a[i]}}