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.

  • Pulling image from Amazon ECR using docker-java
  • Unable to access jarfile - Docker on Elastic Beanstalk
  • Docker unable to connect AWS EC2 cloud
  • AWS Docker deployment
  • Elastic Beanstalk Docker images failing to pull
  • Can't push image to Amazon ECR - fails with “no basic auth credentials”
  • 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 run command error
  • How to run docker builds from Jenkins on a Mac?
  • OSError: [Errno 28] No space left on device Docker, but I have space
  • Why doesn't the container start?
  • Why do I get “not a tty” when running “tty” in Docker?
  • Share directory or volume with container from host
  • 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
    

    Regards

    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.