Installing PHP as CGI

software development


I would like to compile PHP in my directory to use as a CGI. All of the instructions I have seen on the Web are a little spotty, or assume more knowledge of PHP and Apache then I possess.

Has anyone successfully installed PHP as a CGI? What issues did you encounter in doing it?


John Stevenson


Hi John

Not sure exactly what you are trying to do here. I have experience in using PHP to interact with a web server using CGI, yes.

What do you need assistance with?



He’s referring to actually compiling his own version of PHP in his home directory and running it as a CGI (this is a bit slower than using the PHP that’s compiled into Apache but is more secure and people can compile modules into PHP that we don’t offer).

I think there are a few customers who have done it successfully but it’s pretty tricky. I’m sorry that I’m not able to offer much help. There are some docs in the kbase if you haven’t read them yet which explain how to call it once you’ve compiled it and mentions a few snafus.

Compiling it shouldn’t actually be too difficult; getting it to work from the command line isn’t either. Getting it to play nice with suexec and execute via the web is another story altogether.


There are basically two ways to run PHP.

The standard way - which we support - is running PHP compiled into the web server itself.

The other way is to run PHP as a separate executable, which is launched every time a script uses it. As a general rule this is not preferable, at least if speed of execution is your priority. This is more or less how Perl works, and as much as I love Perl, it is slower than PHP (not counting mod_perl, which works similarly to embedded PHP, but we don’t support that for various reasons).

One advantage of running PHP as an executable is that it patches some security problems inherent to running it compiled into the web server. It’s also kind of nice for debugging things, or running stuff from cron (although there’s ways to do that with traditional PHP as well).

  • Jeff @ DreamHost
  • DH Discussion Forum Admin


Jeff, Will,

Thanks for clarifying that. I’m not very familiar with PHP and I honestly didn’t have a clue you could work it that way.

Surely this is a lot slower and takes up a lot more system resources, and therefore frowned upon by Dreamhost?




Surely this is a lot slower and takes up a lot more system resources, and therefore frowned upon by Dreamhost?

I’m not sure I would say frowned on, but we’re probably not going to go out of our way to encourage it. There’s a reason why most people use non-CGI-based PHP: It’s fast. 99% of the time you should probably go that route.

But we’re not going to ban it or anything. Anyone who knows how to compile and use PHP stand-alone probably understands the problems and will be careful not to overpower the server (it’s probably no worse than Perl, in any case).

  • Jeff @ DreamHost
  • DH Discussion Forum Admin