Wednesday, December 9, 2015

apache 2.2 - Multiple php versions simultaneously on Ubuntu

I want to be able to run multiple php versions on my development box running Ubuntu 12.04. What I want to accomplish is that when I use localhost as domain a default is used (let's say php 5.3.17). When I use 547.localhost as domain php 5.4.7 is used. I've seen some tutorials to get this working using fastcgi but until now I haven't been able to get it to work.
I've looked at these tutorials:




  1. http://dbforch.wordpress.com/2010/05/21/apache2-fastcgi-multiple-php-versions-ubuntulucid-10-04/

  2. http://www.metod.si/multiple-php-versions-with-apache-2-fastcgi-phpfarm-on-ubuntu/



For as far as I can see I have done everything that is needed. The problem is that php simply doesn't run. When I go to http://localhost/somephpfile.php it just outputs the source of the php file. The same for http://547.localhost/somephpfile.php.




I'll break down what steps I took in the hope that someone is able to spot what I missed.




  1. First I installed a default lamp stack using sudo apt-get install lamp-server^ phpmyadmin. After this I had a working development server running the repository version of php.

  2. Then I used phpfarm to create two php installs, one for 5.3.17 and one for 5.4.7. The localion of phpfarm is /etc/php/phpfarm, so the executables are in /etc/php/phpfarm/inst/php-{version}/bin

  3. Then I enable suaxec and fastcgi for apache and disabe mod_php with sudo a2enmod fastcgi actions suexec && sudo a2dismod php5

  4. Next, I edited /etc/apache2/mods-enabled/fastcgi.conf to read:



       
    FastCgiIpcDir /var/lib/apache2/fastcgi

    FastCgiWrapper /usr/lib/apache2/suexec FastCgiConfig -idle-timeout
    110 -killInterval 120 -pass-header HTTP_AUTHORIZATION -autoUpdate
    ScriptAlias /php-fcgi/ /var/www/cgi-bin/


  5. Then in /var/www/ I created a folder cgi-bin and in this folder two files, for each of the two php versions as follows (I show only the one for 5.3.17 /var/www/php5317.fcgi):



    #!/bin/sh
    # you can change the PHP version here.
    version="5.3.17"

    # php.ini file location, */php-5.2.13/lib equals */php-5.2.13/lib/php.ini.
    PHPRC=/etc/php/phpfarm/inst/php-${version}/lib/php.ini
    export PHPRC

    PHP_FCGI_CHILDREN=3
    export PHP_FCGI_CHILDREN

    PHP_FCGI_MAX_REQUESTS=5000
    export PHP_FCGI_MAX_REQUESTS


    # which php-cgi binary to execute
    exec /etc/php/phpfarm/inst/php-${version}/bin/php-cgi

  6. The last step was to create virtual hosts. In the end I have three files in /etc/apache2/sites-enabled: 000-default, php5.3.17 and php5.4.7 With the following contents:



    default:




    ServerName localhost
    DocumentRoot /var/www


    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    AddHandler php-cgi .php
    Action php-cgi /php-fcgi/php5317.fcgi





    php5.3.17:




    ServerName 5317.localhost
    DocumentRoot /var/www

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny

    allow from all
    AddHandler php-cgi .php
    Action php-cgi /php-fcgi/php5317.fcgi




    php5.4.7:





    ServerName 547.localhost
    DocumentRoot /var/www

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    AddHandler php-cgi .php
    Action php-cgi /php-fcgi/php547.fcgi




  7. Finally I changed /etc/hosts to read



    127.0.0.1   localhost
    127.0.0.1 547.localhost
    127.0.0.1 5317.localhost

    # The following lines are desirable for IPv6 capable hosts
    ::1 ip6-localhost ip6-loopback

    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters



Now I would expect things to work, but sadly they don't. Instead that a php files runs through php it just outputs the raw file.



There must be something I missed here, but I have gone through the process many times and I can't figure out where it goes wrong.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...