Isolate PHP versions on AWS EC2

I’m actually using PHP 5.3 on all my projects. But for all the reasons you know, I want to update to PHP 5.4 (or 5.5).

We’re also going to migrate on AWS EC2 soon, on a “normal” Linux, Debian Wheezy for example.

  • Elastic beanstalk with Docker Volumes pointing to files
  • Best practice using ALB
  • Deploying ASP.NET 5 app to EC2 in a Docker container
  • Error Docker deployment in Amazon EC2 - Docker container quit unexpectedly
  • How do you share volumes between Docker containers in an Elastic Beanstalk application?
  • Getting console output from Docker container
  • But the problem is that we’ve got some old projects we can’t migrate to PHP 5.3 for some reasons, and we can’t remove them either for some other reasons.

    So I was wondering what would be the best way to isolate those projects on our AWS EC2 instance, to use multiple versions of PHP/Apache.

    I was thinking about using Docker, so we can easily install an other PHP/Apache than on the main system. Plus knowing that it’s kind of a VM sounds good, so it won’t have any impact on the main “server”.

    Is it the best solution ?

    EDIT : Also, we can’t afford another EC2 instance for some cost reasons

  • Docker volume command line option mistaking files for directories
  • Docker: tail log file without hanging
  • Return code of a bash script being called from a Subprocess
  • Centos VM with Docker getting host unreachable when trying to connect to itself
  • Set the hostname of the host from WITHIN a docker container
  • What is a correct/better way to use docker stack deploy with independently updated services?
  • 2 Solutions collect form web for “Isolate PHP versions on AWS EC2”

    You did not mentioned OS but assuming that it is linux based best solution would be
    to create multiple applicative users and install different versions of php by compiling
    in the respective app user’s home directory.

    For example create users user1 (home directory:/home/user1/) and user2 (home directory:/home/user2/). Now switch to user1 and install php5.3 and apache by
    compilations under the path /home/user1/app/php and /home/user1/app/apache
    respectively. Do same for user2 but this time with another version of php.
    Remember apache must run on different ports to avoid port conflicts. You can
    install third apache to as a reverse proxy with multiple vhosts which will
    accept traffic on port 80 and will send them to different backend apaches
    based on request.

    Traffic will be like this

    client http request <--> apache rp <--->  app1 based on apache1 or app2 based on apache2


    Rajarshi Haldar

    Why not using php-fpm and install two of them ? Then you can decide which one to use with which vhost. So each vhost can have it’s own php version. And in that case, you have only 1 apache server running.

    It should be pretty easy to find tutorial on google about that.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.