Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Multiple php versions

How do I use AddHandler to run multiple php versions on apache?

11:08 am on Apr 11, 2014 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 19, 2011
posts: 42
votes: 0

I have Apache 2.4 and php 5.4 installed on Windows for development. I do not use Virtual Hosts for my projects since I tend to work on different machines and keeping the hosts file synced is a bit of a hassle, besides, typing [localhost...] works just fine for me.

I have had some problems with doing projects that required different php versions on the production server, so now I have multiple php versions installed in different directories and simply rename php/ to php54/ and php53/ to php whenever I need another version. But this is tedious, esp. when working on more than one project at a time.

I noticed on one of my client's web hosting that they allow you to set:

<FilesMatch "\.php$">
AddHandler x-httpd-php53 .php

in the htaccess. Effectively changing from php 5.2 to 5.3. Now that is a perfect solution. That way i can just set the version I need in the htaccess file on a per project basis.
But I cannot find anywhere how to set this up? Perhaps partly because I am not very proficient with Apache configurations.
Can someone explain how to set this up like this where I use php5.4 as default, and being able to switch to 5.3 and 5.5 in htaccess.
11:17 am on Apr 11, 2014 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 61

someone asked a similar question here last year.

Can I run multiple versions of PHP on Apache?:
http://www.webmasterworld.com/apache/4590425.htm [webmasterworld.com]
11:33 am on Apr 11, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
votes: 439

What's the FilesMatch for? It seems redundant: "if the filename ends in .php, then use php5.3 for php files". What you want to do instead is constrain the rule to a particular directory, either by putting the rule in a <Directory> section or by a supplementary htaccess file, whichever is more convenient.

I see that I said last year what I was about to say today, so no need to repeat it ;)
12:17 pm on Apr 11, 2014 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 19, 2011
posts: 42
votes: 0

@phranque: None of those threads really answer this question.

@lucy: You are right, the FilesMatch is redundant, I just copy/pasted it from the web hosting's website.

As I keep searching I get the feeling this is done with suphp, however that is something which does not run on Windows, so perhaps this is impossible? It seems to me the solution would be to 'define' the different handlers x-httpd-php53 and x-httpd-php55 and then just use them in htaccess as the apache docs say that AddHandler overrides any previous instances. So the question is really, can I 'define' these handlers on windows?

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members