<p>Use <code>ProxyFCGISetEnvIf</code> to set the <code>SCRIPT_FILENAME</code>:</p>
<pre><code>    &lt;FilesMatch .php$&gt;
        ProxyFCGISetEnvIf &quot;true&quot; SCRIPT_FILENAME &quot;/var/task%{reqenv:SCRIPT_NAME}&quot;
        SetHandler &quot;proxy:fcgi://myapp-php-fpm:9000&quot;
    &lt;/FilesMatch&gt;
</code></pre>

CC BY-SA 4.0
2023-05-23T16:45:55.747Z
2023-05-23T16:45:55.747Z
amacrobert
<p>I'm developing my application with 2 containers: <strong>apache</strong> and <strong>php-fpm</strong>.</p>
<p>Apache serves requests, and delegates PHP execution to the php-fpm container in its vhost:</p>
<pre><code>    &lt;FilesMatch .php$&gt;
        SetHandler &quot;proxy:fcgi://myapp-php-fpm:9000&quot;
    &lt;/FilesMatch&gt;
</code></pre>
<p>The two containers share a single volume that contains the application code.</p>
<p>The location of that volume is different in each of the containers:</p>
<ul>
<li>apache mounts the app code volume at <code>/home/wwwdata/myapp</code></li>
<li>php-fpm mounts the app code volume at <code>/var/task</code></li>
</ul>
<p>How can I change the script path that Apache sends to the php-fpm container, so that it matches where the volume is mounted in the php-fpm container?</p>
<hr />
<p>I can do this in nginx by setting <code>SCRIPT_FILENAME</code> and <code>DOCUMENT_ROOT</code>:</p>
<pre><code>        location ~ ^/index\.php(/|$) {
          fastcgi_pass myapp-php-fpm:9000;
          fastcgi_split_path_info ^(.+\.php)(/.*)$;
          include fastcgi_params;

          fastcgi_param SCRIPT_FILENAME /var/task/$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT /var/task;

          internal;
        }
</code></pre>
<p>but I haven't been able to replicate this behavior in Apache.</p>

<docker><php><apache-httpd>
Set the base path of an Apache proxy handler
amacrobert
# Set the base path of an Apache proxy handler

(Asked by: username_0 on 2023-05-19)

I'm developing my application with 2 containers: apache and php-fpm.
Apache serves requests, and delegates PHP execution to the php-fpm container in its vhost:
    
        SetHandler "proxy:fcgi://myapp-php-fpm:9000"
    

The two containers share a single volume that contains the application code.
The location of that volume is different in each of the containers:

apache mounts the app code volume at /home/wwwdata/myapp
php-fpm mounts the app code volume at /var/task

How can I change the script path that Apache sends to the php-fpm container, so that it matches where the volume is mounted in the php-fpm container?

I can do this in nginx by setting SCRIPT_FILENAME and DOCUMENT_ROOT:
        location ~ ^/index\.php(/|$) {
          fastcgi_pass myapp-php-fpm:9000;
          fastcgi_split_path_info ^(.+\.php)(/.*)$;
          include fastcgi_params;

          fastcgi_param SCRIPT_FILENAME /var/task/$fastcgi_script_name;
          fastcgi_param DOCUMENT_ROOT /var/task;

          internal;
        }

but I haven't been able to replicate this behavior in Apache.

**Tags:** docker, php, apache-httpd


---

## 1 answers

### Answer by username_0 on 2023-05-23. Score: 0

Use ProxyFCGISetEnvIf to set the SCRIPT_FILENAME:
    
        ProxyFCGISetEnvIf "true" SCRIPT_FILENAME "/var/task%{reqenv:SCRIPT_NAME}"
        SetHandler "proxy:fcgi://myapp-php-fpm:9000"


---

