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?


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

  • 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? – Adam Gibbins Mar 14 '14 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. – Zoredache Mar 14 '14 at 6:18
  • 1
    Instead of using DNS for switching, I would recommend to use a LoadBalancer. – neutrinus Mar 14 '14 at 9:21
  • I'm using Ubuntu 10.04 server running Nginx and PHP-FPM/FastCGI. – Nigel Alderton Mar 15 '14 at 16:41

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.


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

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

  • 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? – Nigel Alderton Mar 18 '14 at 1:19

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.