Archive for the ‘PHP’ Category

To enable private PHP error logging, First disable PHP errors. To do it, add following lines into .htaccess file.

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

Once you disable errors, Add following lines in to .htaccess file in order to enable private PHP error logging.

php_flag log_errors on
php_value error_log /home/user/public_html/php_errors.log

change the permission of php_errors.log file to 777 or 755 using following line.

chmod 755 /home/user/public_html/php_errors.log

or

chmod 777 /home/user/public_html/php_errors.log

Now your PHP errors will logged in to /home/user/public_html/php_errors.log file.


To hide PHP errors from your webiste, You will have to first check that your server is SUEXEC or not. If it is SUEXEC enabled server then you can create php.ini file and add follwing lines in to it.

display_startup_errors off
display_errors off
html_errors off

Or if you have server root access then you can copy server php.ini file to the document root and make above changes. To find out the path of server php.ini , just run following command on shell.

root@server [~]# /usr/local/cpanel/bin/rebuild_phpconf –current

Output is:

Available handlers: dso cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: suphp
SUEXEC: enabled

If the server is not SUEXEC then you can add following lines in to .htaccess file to disable PHP errors.

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off


Following is the command to install any pear package on cPanel server

pear install pear-package-name

You can check all the PEAR packages that are available with

pear list-all

You can check installed PEAR packages on your server using following command

pear list

Installing ioncube is very easy if you use following steps.

Installing ioncube in just two command.

If you have cpanel server then ssh server as root.

1) Check available php extension

[root@~]/scripts/phpextensionmgr list

EAccelerator
Zendopt
SourceGuardian
PHPSuHosin

2) As you see output of above command shows php extensions which are EAccelerator, Zendopt, SourceGuardian and PHPSuHosin.

Now install ioncube

/scripts/phpextensionmgr install ioncubeloader

3) Now check php -m or php -v on server it should show ioncube loader.

That’s it.

If your php script is not showing correct date and time then it means your script is using date and time zone configured on your server.

If you want to set your own date and time zone for your domain then it can be done in a very simple manner.

You will need to create php.ini in document root of your domain.

nano php.ini

and enter following line.

date.timezone =Asia/Jakarta

save and exit from file.

Now create phpininfo page and open it in browser and you will see that date and time zone hve been enabled.

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

How can you do that ?

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.

<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 need to modify all the virtual hosts only the ones that you need to enable one or more functions.


You will have to create a simple php mail form by using following code..

<?
$to      = ’supp0rt@123.com’;
$subject = ‘The test for mail function’;
$message = ‘Hello’;
$headers = ‘From: test@abc.com’ . “\r\n” .
‘Reply-To: test@test123.com’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
mail($to, $subject, $message, $headers);
?>

If you are not able to receive the E-mail then you need to check whether your server is allowing to send an E-mail by using phpmail() or not?’ if you have root login then check the main php.ini file of the server.

root@server []# php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

root@server[]# cat /usr/local/lib/php.ini | grep disable_function
disable_functions=”system,passthru,popen,proc_close,proc_get_status,proc_nice,

proc_open,proc_terminate,shell_exec,highlight_file,phpmail”

and remove the phpmail() from server main php.ini file and restart the Apache web server.

Or

If you do not have root login details then contact your hosting provider and ask them to enable the phpmail() for your hosting account.

XCache is a fast, stable PHP opcode cacher that has been tested and is now running on production servers under high load. It is tested (on linux) and supported on all of the latest PHP cvs branches such as PHP_4_3,PHP_4_4,PHP_5_1,PHP_5_2 HEAD(6.x). ThreadSafe/Windows is also supported. It overcomes a lot of problems that has been with other competing opcachers such as being able to be used with new PHP versions.

Download source file.

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

Extract it.

tar -zxf xcache-1.2.1.tar.gz

make install

cd xcache-1.2.1

make

phpize

./configure –enable-xcache

Now edit global php.ini file and add extension.

extension=xcache.so

Now you should see Xcache module in phpinfo.

That is it.

The phpSHIELD is a software which is used to encode the php pages, It is an excellent product for encoding php files if you don’t require any time limiting, IP/Domain locking or the powerful licensing features contained within SourceGuardian . phpSHIELD protects your PHP Source Code with a powerful, easy to use encoder, which creates a native byte code version of the script and then encrypts it.

Most of application require  the phpSHIELD loaders like the phpmotion.

Visit following URL and download the appropriate package of phpshield.

http://www.phpshield.com/loaders/

Then execute following commands

cd /usr/src

wget http://www.phpshield.com/loaders/phpshield.loaders.linux.zip

unzip phpshield.loaders.linux.zip

It will extract phpshield loader files.

You will need to determine the path to your php “extensions library” use a phpinfo() file to check this. It will look something like this /usr/local/lib/php/extensions/no-debug-non-zts-20060613(example only)

Or

you can use following command on ssh shell to check extension library path

php –i |grep extension_dir

check the php version then you will then need to copy 1 file to this “extension library” folder. If php 5.2.X version is running on server then copy the phpshield.5.2.lin (for Linux server) OR phpshield.5.2.win (for Windows server) file to the “extensions library” location.

Open  the php.ini configuration file (located in /usr/local/lib/ or you can use php -i |grep php.ini command to find exact running php.ini file location ), and add the following line below extension_dir line

extension=”phpshield.5.2.lin”

That’s it , phpSHIELD Loaders is successfully installed on your server, You can verify it by creating php info file under your public_html folder,if it is sucessfully installed you will see phpSHILED information  in php info file.




If you are getting following error while checking apache logs.

” PHP Parse error: syntax error, unexpected T_STRING”

Just add following line in to .htaccess file

php_flag short_open_tag X

or if your server is SUEXEC snabled then create php.ini file under /home/user/[public_html and add following code in it.

short_open_tag = X