Custom php5 install for multiple domains

I maintain several websites in my account, and I’d like to have the control that comes with managing my own php5 install. However, I don’t want to have to install and maintain a separate version of php5 in each separate website directory.

In order to do a custom php5 install, it appears that you install the CGI within the site directory and then modify .htaccess to use that CGI to process .php files as follows:

/home/username/ [php.cgi goes here]

Then in .htaccess:
AddHandler php-file .php
Action php-file /cgi-bin/php.cgi

I’ve read the Apache mod_actions documentation and I believe that the URI in the Action directive can only refer to directories below the webroot for the given domain.

What I want to know: is there a way to have my .php scripts handled by a php.cgi that is outside of the webroot. If this were possible then I could install php5 once in a location such as:


and then for each of my websites e.g.:


I could in the .htaccess file in each domain specify something like:
AddHandler php-file .php
Actino php-file /home/username/php/php.cgi

Does anyone know if this is possible?


No, it’s not possible. If your domains are on the same server, you can just copy over the binary to each other’s cgi-bin directory. I know a softlink doesn’t work but I do think a softlink on the directory could work. A cgi-crosslink directory to link across multiple sites. I hadn’t tried that part yet, myself. I’ve just done the pre-mentioned copying of the physical binary.

Thanks guice,

I will give the softlink idea a shot and post my results back here.

Guice was right. Here’s how to set up your account so that you can install php once and use it across all sites you host.

  1. Follow the instructions in the wiki to install php BUT instead of your domain name, use ‘php5’ (or whatever you want the folder in the root folder of your account to be that holds you php install).

This will install the php files into a folder in your account like:


and your php.cgi file will then reside in:


  1. In EACH account that you want to use your new php install you need to add a symlink (short for “symbolic link” and also known as a “soft link”–if you’re a newbie to unix like me, then this info will help) that points to the cgi-bin directory in your php5 directory:

cd ~/
ln -s /home/username/php5/cgi-bin cgi-bin

Then in your .htaccess file in each website directory add:

AddHandler phpFive .php
Action phpFive /cgi-bin/php.cgi

as it says in the website above.

You could actually install several versions of php in this manner and use a different one in each directory.

Thanks guice!

Sure thing! Glad it worked for ya.

You think it’s a bad idea to remap subdirectories instead of the softlink? I just figured it out how to do this but with remapping through my panel.

Everything seems to work okay but I’m not sure if I’ll run into anything later.

{ dvessel }

Oh, didn’t even notice that feature was in there. Shouldn’t be a problem at all. Actually, could be concidered more secure since that method will be adding a Alias directive to the conf file, thus keeping out softlinks which point outside your web directory.

Good catch!
Looks like this’ll even work across servers, which makes things even better.

Hum, but this does make me wonder: Note, CGI will not work in this directory if you change the user when remapping.

I’ve have to test a few things before I commet it to work across servers/users/websites. CGI needs to work for PHP.

Cool, hehe… That wasn’t intentional.

As far as cgi not working… I think that note says it all. If you remap it to another server /w a different user it just won’t have proper privileges.

I’m just glad I can get one install working on all my domains. :slight_smile: Previously, I installed twice having no clue. -well, actually more since I’m such a newb.

{ dvessel }

The permission thing is easy to get around. The best and prefered route is to add the other users in your main account’s group and just insure group has read and execute permission on the file.

Thus makes me wonder if the notice is more of a new user notice or if they really did a change that could stop it from working…

Ah, didn’t realize that. Good to know.

Back to making it more secure… What you said got me thinking. I just redid how things map out. I don’t like the idea of having a shared cgi-bin folder so I took the cgi-bin in the url out completely. Instead I did this. Poor mans security perhaps?

I took the results of this Password generator and placed it into the end of my redirected address. Then remapped it to my cgi-bin directory of my php install.

maps out to:

then just place that same pass into the .htaccess file like this.

AddHandler phpFive .php Action phpFive /RANDOMPASSWORD/php.cgi

Don’t use punctuation from the generator of course. Or maybe you can since it’s just being mapped.

I don’t know if this would really be secure but I’m guessing it would help out.

Actually, I just tried a 24 character password with punctuation and everything else. It works most of the time. Just some characters cause errors. Dunno which it is though.

{ dvessel }

yeah, it would work, depending on the character. Things like / and ~ have special meaning in Unix and can cause problems.