Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:

    <IfModule mod_fastcgi.c>   
        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/ 
    </IfModule>
    
  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:

    <VirtualHost *:80>
      ServerName localhost
      DocumentRoot /var/www
      <Directory "/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
      </Directory>
    </VirtualHost>
    

    php5.3.17:

    <VirtualHost *:80>
      ServerName 5317.localhost
      DocumentRoot /var/www
      <Directory "/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
      </Directory>
    </VirtualHost>
    

    php5.4.7:

    <VirtualHost *:80>
      ServerName 547.localhost
      DocumentRoot /var/www
      <Directory "/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
      </Directory>
    </VirtualHost>
    
  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.

share|improve this question

migrated from stackoverflow.com Sep 25 '12 at 19:08

This question came from our site for professional and enthusiast programmers.

    
1 thing I encountered was that if I named the cgi files like you did it did not work. Try renaming /var/www/cgi-bin/php-cgi-5.4.7 to /var/www/cgi-bin/php54.fcgi for example or just /var/www/cgi-bin/php.fcgi. Can u check if that helps? Just for the 5.4.7 version. –  smottt Sep 25 '12 at 12:14
    
I have checked and unfortunately this doesn't help. I have changed the virtualhost to reflect this change as well so the the action line read Action php-cgi /php-fcgi/php547.fcgi –  SeeDoubleYou Sep 25 '12 at 12:21
    
I've updated the post to reflect these changes since I think is good to have it like that anyway –  SeeDoubleYou Sep 25 '12 at 12:31
    
Hmm, I'll check for other posibilities then. :) –  smottt Sep 25 '12 at 12:32
    
I was wondering, probably I don't need the suexec stuff since I don't need different users for each php version right? –  SeeDoubleYou Sep 25 '12 at 13:34

1 Answer 1

In your virtualhosts you added a handler, but you didn't set the handler which is why it isn't processed. Add:

<FilesMatch "\.php$">
    SetHandler php-cgi
</FilesMatch>

before </Directory> in each virtual hosts file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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