English 中文(简体)
Multiple PHP versions on the same box
原标题:

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 )

最佳回答

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

问题回答

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.

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)





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签