UnixServerAdmin

Server Administration & Management

How to running PHP 4 and PHP 5 on the same cPanel

Here is following process to install and run on the same server php 4 and 5. Users will be allowed to choose what version to use for their scripts.
Although I personally don’t recommend this as it has many performance implications it’s something that small webhosts use so that they don’t have to have different servers for different php versions.

1. Compiler check

# /scripts/checkccompiler
# rm -rvf /home/cpphpbuild
# mkdir /home/cpphpbuild
# cd /home/cpphpbuild

2. Download and extract php

# wget http://us2.php.net/downloads.php
# tar -xzf php-5.2.4.tar.gz
# cd php-5.2.4

3. Configure and build the php installation (credits go to elix for an excellent work)

# echo “#define HAVE_SENDMAIL 1? >> /home/cpphpbuild/php-5.2.4/main/php_config.h
# wget http://www.elix.us/tutorials/php5.gen.cpanel
# chmod 700 php5.gen.cpanel
# ./php5.gen.cpanel
# make
# make install

4. Moving the files and finishing the configuration

# cp -f /usr/local/php5/bin/php5 /usr/local/cpanel/cgi-sys/php5
# chown root:wheel /usr/local/cpanel/cgi-sys/php5
# cp -p /home/cpphpbuild/php-5.2.4/php.ini-recommended /usr/local/php5/lib/php.ini
# chown root.root /usr/local/php5/lib/php.ini
# chmod 644 /usr/local/php5/lib/php.ini
# echo “cgi.fix_pathinfo = 1 ; needed for CGI/FastCGI mode” >> /usr/local/php5/lib/php.ini

5. Now we have to add a few lines to the httpd.conf file

# vim /usr/local/apache/conf/httpd.conf

6. Add in the section – “index.php5″ before index.php4 and Add after “AddType application/x-httpd-php .phtml”

—————————————————————————
Action application/x-httpd-php5 “/cgi-sys/php5″
AddHandler application/x-httpd-php5 .php5
—————————————————————————

7. Test the installation

# service httpd configtest

8. If you get any errors please check that you done all the steps properly. If everything is ok you can now restart apache.

# service httpd restart

October 29, 2012 Posted by | Apache, PHP | , | Leave a comment

How to install XCache

XCache is a open-source opcode cacher, which means that it accelerates the performance of PHP on servers. It optimizes performance by removing the compilation time of PHP scripts by caching the compiled state of PHP scripts into the shm (RAM) and uses the compiled version straight from the RAM. This will increase the rate of page generation time by up to 5 times as it also optimizes many other aspects of php scripts and reduce serverload.

The XCache project is lead by mOo who is also a developer of Lighttpd. Lighttpd is one of the fastest webserver programs and outperforms Apache and many other open source webserving projects so the same is being done to XCache.

If you are on cpanel server then installing Xcatche is very simple, you will just need to run easy apache and select xcache under php module and give it some time to funish the easy apache process.But when it comes to Plesk there is no such automatic installation you will neeed to manuly install Xcache. Refer to following steps for manulal installation.

1) Download source file.

# wget http://xcache.lighttpd.net/pub/Releases/2.0.1/xcache-2.0.1.tar.gz

2) Extracting file.

# tar -xzf xcache-2.0.1.tar.gz

# cd xcache

# phpize

# ./configure –enable-xcache

# make

# make install

3) Now edit php.ini and add following extension

# vim /etc/php.ini
extension=xcache.so

Now check your phpinfo it should show XCache

July 6, 2012 Posted by | PHP | | Leave a comment

How to check php configuration on shell for cPanel server

We can check the Php versions and configurations like suphp, phpsuexec or dso on a cPanel based servers on shell using below command :

# /usr/local/cpanel/bin/rebuild_phpconf –current
Available handlers:
suphp dso cgi none
DEFAULT PHP: 5
PHP4 SAPI: suphp
PHP5 SAPI: suphp
SUEXEC: enabled

June 10, 2012 Posted by | cPanel, PHP | , , | Leave a comment

PHP accelerator

A PHP accelerator is an extension is basically created to improve the performance of software applications using the PHP programming language. PHP accelerators work by caching and its compiled bytecode of PHP scripts to keep away from the transparency of parsing and compiling source code on each an every request.It gives best result, if caching is to basically shared memory with direct execution from the shared memory and the minimum of memory copying at runtime. A PHP accelerator typically reduces server load and increases the speed.

The list of PHP accelerators is as follows.

1) Alternative PHP Cache or APC
2) eAccelerator
3) XCache
4) Zend Optimizer
5) Zend Platform

May 12, 2012 Posted by | PHP | | Leave a comment

How to parse php pages in html page using .htaccess

You can use following code in .htaccess file to parse php pages in html pages

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

To can check above code is working ir not? by creating one test page with following code

# vim test.html

< html>
< head>
< body>
< h1>
< ?php echo “WORKING FINE!”; ?>
< /h1>
< /body>
< /html>

April 22, 2012 Posted by | htaccess, PHP | , , | Leave a comment

How to enable private PHP error logging by using .htaccess

To hide the PHP errors from visitors insert the following code in .htaccess file

# Disable php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off

Once disable the error logs for visitors enable the private PHP error logging by using following code in the .htaccess file

# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log

The PHP_errors.log file needs to be permission 755 or 777

April 18, 2012 Posted by | htaccess, PHP | , , | Leave a comment

How to change php for single hosting account using .htaccess

We can change the php for single hosting account by using following code in .htaccess file. There are few good values which should be change for specific script. Use following code in .htaccess to changes the values as per your requirement.

php_flag register_globals On
php_flag magic_quotes_gpc off
php_flag session.use_trans_sid off
php_flag session.use_only_cookies 1
php_flag session.bug_compat_warn off
php_flag session.use_only_cookies on

php_admin_flag safe_mode Off

php_value engine off
php_value magic_quotes_gpc off
php_value session.use_cookies 1
php_value post_max_size 20971520
php_value max_execution_time 600
php_value upload_max_filesize 12M
php_value magic_quotes_runtime Off

April 16, 2012 Posted by | htaccess, PHP | , , | Leave a comment

How to Resolve FrontPage Problem

1. If anyone facing problems with the FrontPage installation then first uninstall the installed FrontPage from shell /home/<username>/public_html  and Then run the following commands one by one.

# rm -rf .htaccess.*

# rm -rf _vti_pvt/

# rm -rf _derived

# rm -rf _private

# rm -rf _vti_*

2. If server is SuExec enabled then first disable it from the WHM And install FrontPage for the specific domain where you have seems the problem and then try to publish site by using Frontpage. If you are still facing the problem then remove all the .htaccess.* from/home/<username>/public_html and remove all _* (private,vti,etc)one by one carefully.

3. Now try to install it and check for the permission and ownership of public_html folder

# chown -R username:username public_html

# chmod -R 755 public_html

4. If the problem still persists then check whether the permission of public_html/_vti_pvt/service.pwd is 600 or not? (try even setting an attr and set the permission to 600)

# chmod 600 service.pwd

# chattr +i service.pwd

# chattr -i service.pwd

It will sort out your problem enjoy !

November 27, 2011 Posted by | Apache, PHP | , , , | Leave a comment

How to enable PHP MsSQL extension on cPanel

You can enable mssql extension for php on cPanel server. For this you will need to first install some supporting modules. You will need root access to install it. Before you proceed for installation it is important that you backup your php.ini, http.conf and php.conf file.

1. Below are the required module

i) Txt2man
ii) unixODBC
iii) freeTDS
iv) PHP mssql.so

2. Install unixODBC package

# cd /usr/local/src/

# wget http://www.unixodbc.org/unixODBC-2.2.14-p2.tar.gz

# tar -xvzf unixODBC-2.2.14-p2.tar.gz

# cd unixODBC-2.2.14-p2

# ./configure -prefix=/usr/local -enable-gui=no

# make

# make install

3. Install freeTDS package

# cd /usr/local/src/

# wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz

# tar -xvzf freetds-stable.tgz

# cd freetds-stable

# ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local

# make

# make install

Once installation is completed it will show you configuration file path for freetds.conf note down this path in note pad.

4. Configuration freeTDS, Open file freetds.conf and add following to the bottom.

# vi freetds.conf

[MSHOSTNAME]
host = localhost
port = 1433
tds version = 8.0

5. Generating mssql.so file

# cd /home/cpeasyapache/src/php-x.x.x/ext/mssql/

# phpize

# ./configure

# make

# make install

6. Above steps will create a copy of mssql.so in the installed extension directory. Now locate your php.ini file and add extension as

# vi /etc/php.ini

extension = “mssql.so”

7.  Restarting apache service for php changes to take effect.

# /etc/init.d/httpd restart

Now executing php -m or create phpinfo file you will see mssql is listed in the list.

# php -m

November 20, 2011 Posted by | cPanel, PHP | , , | 1 Comment

How to monitor bandwidth usage with vnStat PHP based web frontend

You may find it inconvenient to have to login to your server every time you want to see your server’s bandwidth statistics. To make it easier to see bandwidth stats one kind soul made a PHP frontend that uses vnStat to obtain the necessary data and display it with pretty graphs.

vnStat php frontend requires that you have apache, php and the php-gd image processing library installed. Installing the latter is as easy as running the following command as root:

1. Install Apache Web server, php and php-gd

# yum install httpd

# yum install php

# yum install php-gd

2. Download vnStat PHP for Installation

# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.4.1.tar.gz

# tar -xzf vnstat_php_frontend-1.4.1.tar.gz

3. place it in a web accessible place like /var/www/html

# mkdir /var/www/html/vnstat

# mv vnstat_php_frontend/* /var/www/html/vnstat

4. Edit the config.php file: Just set the correct binary name:

# vi /var/www/html/vnstat/config.php

———————————
$vnstat_bin = ‘vnstat’;
———————————

October 16, 2011 Posted by | PHP, Tips & Tricks, Unix/Linux | , , , , | Leave a comment

How to install Zend Optimizer

1) Install zend optimizer by using following steps :-

# wget http://downloads.zend.com/optimizer/3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz

# cd ZendOptimizer-3.0.1

# ./install.sh

2) Follow the instructions on the screen you will receive after ./install.sh

3) Restart the Apache service

# /etc/init.d/httpd restart

4) To check zend optimizer run

# php  -v

October 11, 2011 Posted by | Apache, cPanel, PHP | , , , , | Leave a comment

How to install pdo_pgsql in cPanel server

Its that easy to add the php module pdo_pgsql in a cPanel server. Just use the command

# pecl install pdo_pgsql

Then go for a Apache restart.

# /etc/init.d/httpd restart

It will be shown up in your phpinfo page.

October 10, 2011 Posted by | Apache, cPanel, PHP | , , | Leave a comment

Install pdo_mysql

1. Basically, you will need to compile pear and mysql from your Apache. Run the command as below to get it updated.

# yum install php-devel php-pear mysql-devel httpd-devel

# pecl install pdo

# PHP_PDO_SHARED=1 pecl install pdo_mysql

2. Open your php.ini file and insert the line as below.

extension=pdo.so
extension=pdo_mysql.so

3. Restart the Apache services.

# /etc/init.d/https restart

August 23, 2011 Posted by | MySQL, PHP | , , | Leave a comment

How to Enable PHP function for a one account

IF you disable PHP function in php.ini file and if you want to enable any particular function only one account . Then You can however use suhosin to enable a function for one domain only.

After installing suhosin, remove all functions from disable_functions in php.ini and add in php.ini suhosin.executor.func.blacklist = “exec,passthru,shell_exec” and all the functions that you want to disable globally.

After that for each domain in the virtual host section you can add suhosin.executor.func.blacklist again, but without the function that you need to enable. And so you will enable that function only for one domain.

Example:
————————————————————————————————–
<VirtualHost 127.0.0.1>
………..
………..
<IfModule mod_php4.c>
php_admin_value open_basedir “/usr/lib/php”
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir “/usr/lib/php”
php_admin_value suhosin.executor.func.blacklist = “passthru,shell_exec”
</IfModule>
…….
……
</VirtualHost>
————————————————————————————————–

In this example exec has been enabled for the VirtualHost. This way it will be better as you do not neet to modify all the virtual hosts only the ones that you need to enable one or more functions.

July 27, 2011 Posted by | Apache, PHP | , , | Leave a comment

SoftException in Application.cpp:303 UID of script is small than min_uid

If you see the below error in your logs then that means that the script is owned by a user (generally root) instead of the actual user.

SoftException in Application.cpp:303: UID of script “/location/path/.php” is smaller than min_uid

You can receive similar error when you have a wrong group name, in this case instead of UID, you  will have GID in the error.

To fix this issue, make sure you have correct user and group ownership for the file that you are trying to access. Ownership can be changed using the below:

# chown usernmame:groupname filename.php

June 19, 2011 Posted by | PHP | | 1 Comment

Core Files in pache/php

You may come across core files which gets generated within your accounts. The possible reason for the core files getting generated is when a php process is killed, apache creates core files under your account. On phpSuexec servers this may cause due to incorrect php.ini file placed in your account and if it is caused due to php/apache then you can get rid off those core files by editing the httpd startup file on the server end.

Follow the steps below to stop the core file creation on the server.

# vi /etc/init.d/httpd

Search for ulimit lines. For eg : you can see these lines

ulimit -n 1024
ulimit -n 4096
ulimit -n 8192
ulimit -n 16384

You need to add ulimit -c 0 at the end. Which will look like :

ulimit -n 1024
ulimit -n 4096
ulimit -n 8192
ulimit -n 16384
ulimit -c 0

Save changes and quit. Now kill / stop apache service and then start apache service on the server .

# service httpd stop

# service httpd start

June 17, 2011 Posted by | Apache, PHP | , | Leave a comment

How to URL forwarding in PHP

<html>
<?php
//this will NOT work, the browser received the HTML tag before the script
header( ‘Location: http://www.yoursite.com/new_page.html&#8217; ) ;
?>

June 9, 2011 Posted by | PHP | , | 4 Comments

How to enable php global registry using .htaccess

Please follow these steps to enable php global registry for your domain using .htaccess file :-

1. Open .htaccess
2. include these lines

==========================
php_value register_globals 1
php_value session.save_path /tmp
==========================

May 26, 2011 Posted by | htaccess, PHP | , | 3 Comments

How to enable .zip file import in PhpMyAdmin

If you have cPanel server and you are not able to import .zip file in PhpMyAdmin then just  make the below changes :

# vi /var/cpanel/easy/apache/profile/makecpphp.profile.yaml

Search for following line

Cpanel::Easy::PHP5::Zip: 0=0

Change it to

Cpanel::Easy::PHP5::Zip: 1

Save the file  and run the command :

# /scripts/makecpphp

That’s all  you are done.

May 23, 2011 Posted by | PHP | , , | 4 Comments

PhpMyAdmin Socket Error

If you are webmaster who using the web interface database management, you shall be familiar with PhpMyAdmin. Then you might get these error from your PhpMyAdmin when you logged into the PhpMyAdmin.

#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

To overcome this error, you could have 2 ways to solve the problem.

Method 1:

1. Check if your mysql.sock file missing from /tmp.

2. If it is really missing from /tmp, you may create a symbolic link from /var/lib/mysql/ to /tmp.

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

3. You might ask why must do this, you may check the file from /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php and you need to check for the setting of cfg[‘Server’][‘socket’],  and you will see the setting set to /tmp/mysql.sock.

Method 2:

1. Edit the following file.

# vi /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php

2. Find $cfg[‘Servers’][$i][‘host’], change the value from localhost to 127.0.0.1

May 20, 2011 Posted by | cPanel, PHP | , , , | 3 Comments