Tiger Technologies Technical Support

How do I choose whether my account uses PHP 4 or PHP 5?

This page is showing a generic answer. To see a more
specific answer, please type your domain name below:

We have two different versions of the PHP scripting language installed on our servers: PHP 4 and PHP 5 (the exact version numbers are currently 4.3.10 and 5.2.0, with Debian patches applied for security).

By default, our customer Web sites use PHP 4 for PHP scripts. PHP 4 is the most widely used and tested version of PHP. However, some customers may have scripts that require the newer PHP 5.

On this page:

Are the two versions configured identically?

For technical reasons, the settings used by the two versions are a little different, and you should take this into account when choosing which version to use. You can view phpinfo output from sample accounts configured to use the different versions: see phpinfo for PHP 4 and phpinfo for PHP 5.

(Remember that you can override most of the php.ini settings; the sample pages are useful for showing what modules we have installed and what defaults we use.)

Changing the default PHP version

You can use your account management control panel to easily choose which PHP version your site uses:

Your Web site will immediately begin using that version of PHP to run ".php" files.

(Note that if you're a technically advanced user who has enabled FastCGI for PHP scripts, you also need to edit the FastCGI wrapper script to switch between PHP 4 and PHP 5. If you don't know what FastCGI is, this almost certainly doesn't apply to you.)

Using different versions of PHP based on the file name

The instructions above explain how you can use the control panel to make all ".php" scripts on your account use a certain version. But what if you need to run some scripts with PHP 4 and others with PHP 5?

One way to do this is to explicitly give some of your scripts names ending in ".php4" or ".php5". Doing so will force those scripts to be run with PHP 4 or PHP 5, overriding the default PHP version chosen in the control panel.

Using different versions of PHP based on .htaccess settings

(A mild warning: the information below gets more and more technical as this page continues. It's really intended for advanced users who are familiar with Apache options; if it doesn't make sense and you need to run two different PHP versions and you can't rename any of the files, you'll probably want to contact us for assistance.)

In some cases, renaming your PHP files files may not be possible. There's actually another way for advanced users to control the version of PHP on a per-directory basis, using .htaccess files.

To explain this, we first need to explain how our servers really run PHP files. Our servers actually understand three separate MIME types:

application/x-httpd-php
application/x-httpd-php4
application/x-httpd-php5

The MIME types are what actually control which version of PHP is run for a given file type. If the file has MIME type "application/x-httpd-php" (which is the default for ".php" files), our servers will use the version of PHP that you've chosen in your control panel. Files of type "application/x-httpd-php4" (the default for ".php4" files) are always run using PHP 4, and files of type "application/x-httpd-php5" (the default for ".php5" files) are always run using PHP 5.

In other words, when you change a file name suffix from, say, ".php" to ".php5", what that really does is change the MIME type that our servers associate with the file, which in turn changes the version of PHP that the servers use to handle it.

This is useful information because the Apache Web server actually gives you complete control of MIME types. In particular, you can use Apache's AddHandler command in .htaccess files to associate a file suffix with a MIME type for an entire directory. If you force a certain file suffix to use the "application/x-httpd-php4" or "application/x-httpd-php5" MIME types, those files will be run using PHP 4 or PHP 5, regardless of your PHP control panel setting (because the control panel setting only affects files of type "application/x-httpd-php").

For example, if you put this line into a .htaccess file in a directory:

AddHandler application/x-httpd-php5 .php

... then any file in that directory with a name ending in ".php" will be run using PHP 5, even if ".php" files in all your other directories are using PHP 4. You could even do this to make all ".html" files be handled by PHP 5:

AddHandler application/x-httpd-php5 .html

In summary, the MIME type is really what makes our servers choose a particular version of PHP. By default, changing the name to use ".php4" or ".php5" changes the MIME type, which forces a different version to run. But you can have complete control over this process by changing the MIME type for any kind of file yourself with Apache's "AddHandler" command.

For the truly geeky: using a custom PHP version

So far, this page has focused on choosing between the two versions of PHP that we have preinstalled. We should also mention that if you compile and install your own version of PHP, though, there is a way to make the system use that.

You'd just need to set an environment variable named "USE_PHP_BINARY" containing the path of the PHP binary that you compiled and installed. For example, you could do this in a .htaccess file:

SetEnv USE_PHP_BINARY /home/ex/example.com/custom-php5-cgi

If you do that (and leave the file's MIME type set to "application/x-httpd-php"), all PHP files in that directory would be run using your "custom-php5-cgi" binary. (Note that our servers always use PHP in CGI mode; you can't make them use PHP as a module by installing your own version.)

Search


Related Topics

PHP Scripts

Control Panel Login

Contacting Tiger Technologies

Apache .htaccess Files

FastCGI