简体   繁体   中英

How to install PHP 5.4 without overwriting existing older PHP version?

How do I create a portable version of PHP 5.4 without upgrading / affecting the existing PHP, since there are live websites running on that server.

It's like running 2 instances of PHP?

In other words, how do I build PHP such that it won't replace the old one when I run make install ?

UPDATED based on clarified question

First, you want to build the new PHP version so that it installs to a different location without overwriting the existing version. To do this, follow the PHP build instructions with the following change:

When you execute ./configure , add the following argument: --prefix=/opt/php54

This will put your new PHP version in /opt/php54/... instead of wherever it goes by default.


ORIGINAL ANSWERS

A single Apache web server can only use one mod_php version at a time. If you want to use multiple versions, the easiest way is probably to set up the second PHP version using CGI and use a modified version of Scott's answer.

Set up the CGI in your main Apache config file:

ScriptAlias /php54-cgi /usr/lib/cgi-bin/php54-cgi
Action application/x-httpd-php54 /php54-cgi

Next, you need to set up a Virtual Host bound to port 8080 and tell it to use this version of PHP :

<VirtualHost [IP]:8080>
  DocumentRoot [DOCUMENT_ROOT]
  DirectoryIndex index.php
  ServerName [HOSTNAME]:8080
  <Directory [DOCUMENT_ROOT]>
    AllowOverride All
    Allow from All
  </Directory>

  <FilesMatch "\.php">
    SetHandler application/x-httpd-php52
  </FilesMatch>
</VirtualHost>

(Note: this is off the top of my head, without checking that the syntax is correct, so it may need some tweaks.)

With this configuration, PHP scripts in the Virtual host will be executed using the specified version of PHP.


Another way to do this, probably harder, but also more flexible in the long run, would be to run two completely separate instances of Apache (or one Apache and one other server, such as nginx), each with its own PHP version.

Apache has some documentation for doing this , but it isn't complete.

The hard part is that Ubuntu tries to help set up your Apache configuration, but it makes assumptions about where things are so you will have problems managing the two. Using a different server, such as one Apache and one nginx, or one Apache and one Lighttpd, will be much easier because their configuration files don't conflict with each other. Just set one to port 80 and the other to port 8080 and start them both.

Have you looked at something like Webtatic ? It might do the job for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM