Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

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>
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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