Apache 2.4 + php-fpm + mod_proxy_fcgi + alias

aliasapache-2.4mod-proxy-fcgiphp-fpm

I have the following config:
Apache 2.4, php-fpm, mod_proxy_fgci.
The problem is that my config is not working with the alias directive:
I've installed phpredmin, but the alias directive is not working with ProxyPass.
Can someone push me in the right direction?

This is the config:

<VirtualHost *:80>
  ServerName default


# Directory
DocumentRoot /var/www/default/wwwroot
<Directory /var/www/default/wwwroot>
  Options +FollowSymLinks +ExecCGI +Includes
  AllowOverride All
  Require all granted
</Directory>

# PHP-FPM Server
<LocationMatch "^/(.*\.php(/.*)?)$">
  ProxyPass fcgi://127.0.0.1:9000/var/www/default/wwwroot/$1
</LocationMatch>

# Directory indexes
<IfModule dir_module>
  DirectoryIndex index.htm index.html index.shtml index.php index.phtml
</IfModule>


Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory "/var/www/default/wwwroot/phpredmin/">
        AllowOverride All
        require ip 127.0.0.1
</Directory>


</VirtualHost>

Update

I've created an extra vhost and I've got phpredmin working with this config:

<VirtualHost *:80>

ServerName phpredmin.example.com
DocumentRoot /var/www/default/wwwroot/phpredmin

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel alert
DirectoryIndex index.php
ServerSignature Off

RewriteEngine on

<Directory /var/www/default/wwwroot/phpredmin>
    Options -Indexes
            require ip 192.168.2.0/24
            require ip 192.168.10.0/24
</Directory>


Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory /var/www/default/wwwroot/phpredmin/public>
         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteRule . fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/index.php [P,L]


         RewriteRule ^/?(.*\.php)$ fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/$1 [P,L]
         RewriteCond %{REQUEST_FILENAME} -d
         RewriteRule ^/?(.*)$ fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/$1 [P,L]

         DirectoryIndex disabled
         ProxyErrorOverride on
</Directory>

Best Answer

Apache reads configuration file from top to bottom.

If a matching command is found (like your proxypass) it is executed and the rest of file is discarded.

In order to have your Alias command executed before ProxyPass, you need to put it on top of file.

<VirtualHost *:80>
  ServerName default


# Directory
DocumentRoot /var/www/default/wwwroot
<Directory /var/www/default/wwwroot>
  Options +FollowSymLinks +ExecCGI +Includes
  AllowOverride All
  Require all granted
</Directory>

Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory "/var/www/default/wwwroot/phpredmin/">
        AllowOverride All
        require ip 127.0.0.1
</Directory>


# PHP-FPM Server
<LocationMatch "^/(.*\.php(/.*)?)$">
  ProxyPass fcgi://127.0.0.1:9000/var/www/default/wwwroot/$1
</LocationMatch>

# Directory indexes
<IfModule dir_module>
  DirectoryIndex index.htm index.html index.shtml index.php index.phtml
</IfModule>
</VirtualHost>