Multiple PHP versions on the same box

橙三吉。 提交于 2019-11-27 07:03:21

问题


Is it possible to have multiple versions of PHP running on the same box ( like rails ) . Here is my problem , I need to start development on a new project and was planning to use PHP 5.3 for it so that I can use the latest Zend framework and active record with it .
However the machine where I need to host my application has PHP 4.4 and there are several other applications hosted there . I do not want to upgrade the PHP version on the server as in the past I have faced a lot of issues while upgrading the PHP version and deprecated functions .
I was wondering if it is possible to have multiple version of PHP on the same box and then somehow specify the version that you want your application to load ( similar to rails )


回答1:


Yes, it is possible. In fact, many servers operate this way. You may see .php4 and .php5 extensions from time to time indicating which version that particular script should be handled with.

ServerFault addressed this question

Running php4 and php5 along side each other




回答2:


You can run multiple PHP versions on the same box using Docker.

An example command would be:

sudo docker run -d -p 8055:80 -v /var/www:/var/www \
  -v /etc/apache2/sites-available:/etc/apache2/sites-available \
  -v /etc/apache2/sites-enabled:/etc/apache2/sites-enabled \
  codeyourdream/apache-sendmail-php55

Here's what this command does:

  • It forwards your local /var/www, /etc/apache2/sites-available and /etc/apache2/sites-enabled to the corresponding folders of Docker container. If your local websites and/or apache configs are located in different folders, replace the first part of -v value. I.e. the format is: docker run -v /host/directory:/container/directory -other -options image_name command_to_run
  • It forwards port 8055 of your local machine to port 80 of Docker container
  • It runs the container from "codeyourdream/apache-sendmail-php55" image

If you run this command, all your local websites should be available via port 8055 (i.e. via URLs like http://localsite:8055) and processed by PHP 5.5

See https://codeyourdream.com/blog/how-run-multiple-php-versions-apache-one-linux-machine-using-docker for more details. Affiliation note: this is my team's blog.




回答3:


A possiblity is using one version of PHP as an Apache module, and the other version as a CGI ; but an idea I kind of like better is to have :

  • Several distinct instances of Apache,
  • Each one listening on a different port (for instance, PHP 4.4 on port 44000, and PHP 5.3.1 on port 53100)
  • And each one using a different version of PHP

This way, you have totally different environments, that works independantly of each other, and you can configure/modify anything you want in each environment without risking breaking any of the others.

(And if you don't want to have port numbers in your URLs, I suppose you can put a proxy in front of your distinct Apache instances, so it seems there is only one)



来源:https://stackoverflow.com/questions/1905548/multiple-php-versions-on-the-same-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!