I am facing the following legacy setup with php-7.4
and libapache2-mod-php7.4
installed and enabled:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/var/www/html/project1
-> Apache 2.0 Handler / PHP 7.4 ->example.com/project1
/var/www/html/project2
-> Apache 2.0 Handler / PHP 7.4 ->example.com/project2
I am new to the company and I now have to implement /var/www/html/project3
, accessible via example.com/project3
. The legacy projects are not able to run on recent PHP versions but I like to run project3
with recent PHP 8.2. Therefore I thought of installing php8.2-fpm
and let Apache handle just the requests to /var/www/html/project3
via SetHandler [...]php8.2-fpm.sock
.
See in the comments of the above snippet how I tried to achieve this without success:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
# This works, but sets php8.2-fpm globally for the whole /var/www/html directory
# this breaks project1 and project2
<FilesMatch \.php$>
SetHandler proxy:unix:/var/run/php/php8.2-fpm.sock|fcgi://dummy
</FilesMatch>
# This has no effect at all (but I guess my intent is clear)
<Directory /var/www/html/project3>
<FilesMatch \.php$>
SetHandler proxy:unix:/var/run/php/php8.2-fpm.sock|fcgi://dummy
</FilesMatch>
</Directory>
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I thought of using another VirtualHost
with different DocumentRoot
, but I have two requirements that made me believe I have to use the same VirtualHost
as for the legacy projects:
- the final URL has to be of the same kind as for the legacy projects (
example.com/project3
) - due to CI/CD, the project's location must be
/var/www/html/project3
. The only thing I can do is placing a symlink somewhere else in the file system
So if you either have an idea how to solve this in the existing VirtualHost
defintion or can help me with a solution for a second VirtualHost
that satisfies the two requirements + sets the php-fpm
handler, I would greatly appreciate.