I'm using PHP as an Apache module, not CGI. Every request made to a particular virtual host should result in a PHP script's execution ('/srv/web/init.php'), and I do this like so:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /srv/web/

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/init\.php$
    RewriteRule .* /init.php [L]
</VirtualHost>

This virtual host serves no other purpose besides executing init.php and returning its output to Apache for the response. My question is whether there is a cleaner way to do this - ie. bypassing Apache's filesystem emulation so that a "public" folder isn't required and so mod_rewrite isn't necessary. Much like calling a CGI script, it would go like this:

<VirtualHost *:80>
    ServerName example.com

    PHPScript /srv/web/init.php
</VirtualHost>

I've removed the DocumentRoot directive above since what I'm proposing would render it useless. Am I just trying to turn the Apache module into CGI, and should I just use CGI?

link|improve this question

33% accept rate
feedback

3 Answers

No, you can't directly call a PHP script. What you can do is something like:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /srv/web/
    DirectoryIndex init.php
</VirtualHost>
link|improve this answer
feedback

No,

PHPScript isn't an Apache Directive you can use. http://httpd.apache.org/docs/2.2/mod/directives.html

You have to make that file default index or mod_rewrite to it.

link|improve this answer
feedback

You need to make that php file the default index file that then operates as a front controller to everything else on that site, so that all url's would then be example.com/index.php/whatever - you could make a rewrite that hides the index.php part to end users, but it would still be there directing things.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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