How to use separate php version for different php files

I have a website (based on ZEND) and hosted on server 1and1.

Server 1and1 uses PHP versions 5.2.17 and 5.4.5. I need to use PHP version 5.4.5 for only a few files. This is because some of my other files show errors if I use PHP 5.4.5, but they run fine using PHP 5.2.17.

In my .htaccess file, the line below was written earlier to use PHP 5.2.17

AddType x-mapp-php5 .php 

To use PHP 5.4.5, I have to use the line below (instructions for using this code will be found on page 1 and 1 faq)

 AddHandler x-mapp-php6 .php 

FAQ:

Can I use PHP 5.4.5 only for these specific files?

I tried using the line below in .htaccess, but it does not work:

 AddType x-mapp-php5 .php AddHandler x-mapp-php6 FilenameController.php 

EDIT

I tried to change the code 5.2. I use PEAR packages to create an Excel worksheet that works fine with PHP 5.2.17, but displaying the error below in PHP 5.4.5

Fatal error: Cannot override _PEAR_call_destructors ()

Adding

This is a change in the .htaccess file

 AddType x-mapp-php5 .php AddHandler x-mapp-php6 .php6 SetEnv APPLICATION_ENV development Options -MultiViews <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^FilenameController\.php$ FilenameController.php6 [L] RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] </IfModule> 

It generates 404 error "Page not found" if I change the file name FilenameController.php to FilenameController.php6 and when I try to visit the page with its creation.

+8
php .htaccess
source share
2 answers

Why not just

 AddHandler x-mapp-php6 .php6 

And rename your 5.4 scripts to php6? You can even hide it from the user by doing the following in your .htaccess file:

 RewriteEngine On RewriteBase / RewriteRule ^FilenameController\.php$ FilenameController.php6 [L] 

This is the internal direction of the .php6 extension for this script file .:-)

However, let me emphasize: you can choose which script engine to use for each request, and not for each file. For example: http:/yourdomain.com/FilenameController.php will be processed by PHP 5.4 RTS, and all included files will be compiled and executed using PHP 5.4; http:/yourdomain.com/index.php will be processed by PHP 5.2 RTS, and all included files will be compiled and executed using PHP 5.2.

You cannot use 5.4 to compile in a file in an application and 5.2 to compile the rest.

+5
source share

Server 1and1 uses PHP version 5.2.17 and PHP version 5.4.5.

I would be interested to know the details of this.

Assuming you are running php as an Apache module (mod_php), you can only have one version running on one Apache installation at a time. Are you sure your server even allows you to use both at the same time? Most likely, you can restart Apache and run it with a different version. If this is the case, you cannot configure your path from this, so as not to want to configure php on cgi.

+1
source share

All Articles