Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to execute PHP as an older version than the one installed?

Tags:

php

version

I need to support some legacy code on a server where I need to be on the latest stable PHP version at all times. I can't possibly update the code base every time I upgrade so I'm wondering if there is a way to run this specific site with an older version of PHP than the one installed.

Example: I'm running PHP 5.3.3 and my code for an old site is broken. It was running perfectly on 5.2.x. Can I simply put a command in at the top of the script(s) to run it as 5.2.x so that I don't have to fix broken code the next time I upgrade to 5.4, 5.5, etc?

TL;DR: Is there a function like this:

exec_as_php_version('5.2.14');//?

like image 624
Joel Mellon Avatar asked Oct 25 '10 20:10

Joel Mellon


People also ask

How can I run two versions of PHP?

To run two or more PHP versions for different sites on the same LAMP stack by using mod_fcgid to create a . fcgi wrapper script. The script forwards all the PHP requests which were made from php-cgi binary. Considering a server running on PHP 7.2 where a specific site requires an older PHP version (eg PHP 5.6).

Can I run several versions of PHP at the same time?

Yes we can run several versions of php. To do that we must have to check the INSTALL file, if it is included in PHP source distribution.


2 Answers

No, there isn't. Welcome to version dependence hell.

Edit: Now, 10 years later, this would not be terribly difficult - just run different PHP versions in separate Docker containers. It's still a bad idea to run really old PHP versions for security reasons, though.

like image 97
Michael Borgwardt Avatar answered Oct 17 '22 07:10

Michael Borgwardt


it is never forward compatible.

this is one solution i have seen earlier, but it is a VERY BAD IDEA: http://blog.dynom.nl/archives/Multiple-PHP-versions-on-one-webserver_20091103_53.html (link does not work)

like image 41
zerodin Avatar answered Oct 17 '22 06:10

zerodin