Using auto_prepend_file under PHP-as-CGI

software development

#1

I’d like to continue running PHP-as-CGI because I’m using exec() in a couple of places, but I also want to start using auto_prepend_file and auto_append_file to insert code into every page on my site. It is my understanding that under Dreamhost’s setup, the only way to use these functions is if you run as PHP as an Apache module.

There were a few mentions in the KBase about ways to selectively run PHP as Apache, such as adding this line to htaccess:

AddType application/x-httpd-php .php

… which apparently turns on PHP-as-Apache in selected directories.

Or this line:

AddType php-cgi .php

… which apparently turns on PHP-as-CGI in selected directories.

Soooooooooo… is the best way to achieve what I want to achieve simply running PHP as Apache sitewide and then adding the “AddType php-cgi .php” line to the directories where I need to use things like “exec()”? These are generally just directories of images which don’t require my auto_prepends and auto_appends.


#2

You could also use a different extension for the files that need to be run in a different mode.

AddType application/x-httpd-php .phpmod
AddType php-cgi .phpcgi

(extensions are up to you, of course)

You can use the same trick to enable PHP 5 on a per-file (or per-directory) basis.