8

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

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

On 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 the line below (instructions to use this code will be found on the 1and1 faq page)

AddHandler x-mapp-php6 .php

FAQ url(s):

Is there any way to use PHP 5.4.5 for those specific files only?

I tried to use the line below in .htaccess, but it's not working:

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

EDIT

I tried to edit the 5.2 code. I am using PEAR packages to create Excel sheet which is working fine with PHP 5.2.17 but displaying the error below on PHP 5.4.5

Fatal error: Cannot redeclare _PEAR_call_destructors()

Addendum

This change to 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>

generates 404 "Page not found" error if I change the filename of FilenameController.php to FilenameController.php6 and when I am trying to visit the page its generating.

4
  • 11
    Why don't you fix your PHP 5.2 code to work with a supported version of PHP instead? Commented Aug 17, 2012 at 13:01
  • I will require to work on 5-6 files to fix again. If i don't get any solution to use separate PHP version, i will have no other way but to work on those files. Commented Aug 17, 2012 at 13:06
  • I think you need nginx HTTP server. You may plug in different PHP using fastcgi or make proxy for 2 apache servrers and use them as backend. P.S. The best solution is to fix code. Commented Aug 17, 2012 at 13:11
  • This would be a bad idea even if your files were independent, but you're using a framework, meaning they depend on eachother. What happens if a request needs files from both of those groups? Fix your code to work with a single version. Commented Aug 17, 2012 at 13:14

2 Answers 2

5

Why not just

AddHandler x-mapp-php6 .php6

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

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

This does an internal direction to a .php6 extension for that one script file. :-)

However, let me emphasise: you can only choose which scripting engine to use on a per request basis not on a per file basis. For example: http:/yourdomain.com/FilenameController.php will be handled by the PHP 5.4 RTS and all included files will be compiled and executed using PHP 5.4; http:/yourdomain.com/index.php will be handled by the PHP 5.2 RTS and all included files will be compiled and executed using PHP 5.2.

You can't use 5.4 to compile on file within an application and 5.2 to compile the rest.

Sign up to request clarification or add additional context in comments.

3 Comments

Did not succeed in this way. Added these line one on htaccess codeAddType 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>
After changing the filename of FilenameController.php to FilenameController.php6, whenever i am trying to visit the page its generating 404 error and displaying "Page not found".
@Debashis, see updates to your Q and my A. As Leigh correctly says: if you want use all files in a single application you have to work at 5.4 (or 5.2) so you need to bite the bullet and convert up (or down) the odd files.
1

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

I'd be curious as to the details of this.

Assuming you run php as an Apache module (mod_php), you can only have one version running on the same installation of Apache at a time. Are you sure that your server even allows to use both at the same time? More likely, you can restart Apache and have it run with a different version. If that is the case, you can't really configure your way out of this, lest you want to set up php over cgi.

2 Comments

OK. They appear to run php through cgi (Server API: CGI/FastCGI). In that case it's possible, although I don't know what the specifics would be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.