Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have the following setup:

  • Plain-Server: Delivering php-files as plain text
  • Proxy-Server: Asking the Plain-Server for the php file and parsing it.

Now my question: How do I configure the Proxy-Server (a fully configurable apache 2.2 with PHP 5.3) to interpret the plain php files from Plain-Server?

Example: Given a small php script "hello.php" on Plain-Server (accessible through http://plainserver/hello.php):

echo "Hello World";

Plain-Server only outputs it as plain text, no parsing of php-code.

On the Proxy-Server the file "hello.php" does not exist. But when requesting hello.php from Proxy-Server it should get the hello.php from Plain-Server with mod_proxy (Reverse Proxy). It should also parse and execute the php, saying only "Hello World".

The Reverse Proxy is already running, but the execution of php code not working. I tried mod_filter, but couldn't make it work. Any ideas how to that? (Note: Also posted on

share|improve this question

4 Answers 4

You don't. Well, not with mod_proxy, anyway. You could have a proxy PHP script that requests the content and evals it, but... ugh.

Whatever you're doing, it's fair to say you're doing it wrong.

share|improve this answer

I found another way with mod_ext_filter. Add the following to your httpd.conf:

ProxyPass   /test/  http://localhost:9000/
<IfModule mod_ext_filter.c>
   ExtFilterDefine parse-php mode=output intype=text/html cmd="/usr/bin/php"
ProxyPassReverse   /test/  http://localhost:9000/
<LocationMatch "\.php">
    SetOutputFilter parse-php

So it runs the external application php which is found in /usr/bin/. Bad thing about it: starting a separate process and also parsing php-files which are not part of the folder /test/.

I tried also to use fast-cgi or mod_php to parse the php-file, but couldn't make it work. Any ideas how to use fast-cgi to interpret the php-file?

share|improve this answer

it is really bad solution... but on the proxy machine do not configure any proxying, instead add

ErrorDocument 404 /index.php

and in index.php put the logic that checks $_SERVER['REQUEST_URI'], downloads code from content server and executes it with eval.

but that's bad, includes will not work... womble is right. just try another approach. if you are really desperate maybe use webdav and davfs, but that's still ugly hack, nfs would be much more efficient if you insist on hosting code on one machine and interpreting on the other.

share|improve this answer

I had a similar issue—in my case the main “Plain Text” server could parse XQuery into HTML, but not PHP. So I decided to fill in the gap with Apache, but also wanted the whole site to be self-contained, for easy backups.

I solved this by setting Apache’s DocumentRoot to the same directory that the main server serves files out of, then used ProxyPassMatch to match against requests that end in .php, and told mod_proxy not to proxy those files, by adding a ! to the end of the directive statement:

DocumentRoot "/path/to/localhost.main/

ProxyRequests  off
ProxyPassMatch ^/(.*\.php)$ !
ProxyPass / http://localhost.main:8080/
ProxyPassReverse / http://localhost.main:8080/
ProxyPassReverseCookieDomain localhost.proxy localhost.main

This way, all PHP files get parsed (in my case via FastCGI, but should work with mod_php as well) and served by Apache, and the rest fall through to the main server.

I was also doing rewriting on top of this though, to map cool URIs to a processing script with query parameters, which requires another rule to work correctly, although here the logic is inverted, as it does the negation inside the regex itself (using negated lookbehind):

RewriteRule ^/(.*(?<!\.php))$ /path/to/script/$1 [L,PT,QSA]
share|improve this answer

Your Answer


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