1

Is it possible to upgrade the version of PHP running on my server without any significant downtime?

What I want to avoid is my sites being down for minutes (or longer if something goes wrong) while I upgrade PHP. I don't mind if they're down for a few seconds.

Ideally I would like to have two versions of PHP installed on a server and just flick a switch to flip between them. That way if there are unforeseen problems with the new version I can flick the switch back again to go back to the old version.

The only way I can think of is to have two servers running different version of PHP and use DNS to choose which one users see. Is it possible with a single server?

Edit

I should have mentioned that I'm using an Ubuntu 10.04 server running Nginx and PHP-FPM/FastCGI.

4
  • 1
    You should mention how you're using PHP, are you using mod_php with Apache? Nginx and PHP-FPM etc? Or are you willing to change setups as required? Commented Mar 14, 2014 at 1:18
  • 1
    The short answer is of course it is possible. The long answer is that it is extremely dependent on the specifics of your setup, with setup configurations being very fragile, and some being really easy to upgrade. Commented Mar 14, 2014 at 6:18
  • 1
    Instead of using DNS for switching, I would recommend to use a LoadBalancer. Commented Mar 14, 2014 at 9:21
  • I'm using Ubuntu 10.04 server running Nginx and PHP-FPM/FastCGI. Commented Mar 15, 2014 at 16:41

2 Answers 2

5

Install each version of PHP to a different directory, switch between them using a symlink - in Unix, symlinks are atomic, meaning no downtime. Then simply restart your webserver to restart the worker threads thus using the new PHP version.

So:

/opt/php/5.1 /opt/php/5.2 /opt/php/live -> /opt/php/5.2 

This isn't zero downtime, but its seconds downtime - per your requirement.

1
  • Sounds great. That's exactly what I want but I can't find how to have two versions of PHP in different dirs on the same machine. Any pointers? Commented Mar 18, 2014 at 1:19
1

as Adam Gibbins and Zoredache have mentioned it is entirely dependent on your setup. If you use gentoo-linux for your server you can install each PHP version in different slots and then switch between them using eselect. You still have to restart the web-server, no getting around that but that's only seconds. Of course whatever method you use you'll need a test script to make sure everything is working AOK.

2
  • I'm using an Ubuntu 10.04 server running Nginx and PHP-FPM/FastCGI. Commented Mar 15, 2014 at 16:42
  • google tells me this: howtoforge.com/… Commented Apr 20, 2014 at 6:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.