HowTo – Selecting The PHP Version

Filed under: Web Design

phpPHP is a Server Side programming language that you can use to develop Internet applications.Some applications will still work best with PHP Version 4 but because not all of the new options are available you will have to make a choice how your scripts are executed

For Customers with access to both PHP 4.x and 5.x the easiest way to select the processing of your script is to modify the file extension to match the version of PHP that you need to run.

file.php4 will execute PHP version 4.x
file.php5 will execute PHP version 5.x
file.php will execute the default version of PHP

To find out which version of PHP is your default Version place the following lines of text in a file and upload it to your account.

<?php // Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>

PHP will run phpinfo and provide you with the default version.
To see the options for other versions rename the file extension.

If you need to override the default version of PHP running your scripts
you can place a .htaccess file in your directory with the following line

AddHandler application/x-httpd-php5 .php

This tells the server to process all files with the .php extension with PHP version 5

Setting The Default PHP version in cPanel

Although you may already know this if you are using cPanel or another control panel you can set the default php version for your site and then override it with htaccess files in directories that scripts need other versions.