I'm trying to containerize an existing web application that runs on Apache and PHP. I have it running locally on macOS's built-in Apache server and provided PHP, but I'm trying to move to Docker.
I have separate Apache and PHP containers defined in the repo root's docker-compose.yml as follows:
version: '3'
services:
apache:
build: .docker/apache
container_name: redactedname_apache
ports:
- 8080:80
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled
- .:/home/wwwroot
depends_on:
- php
php:
build: .docker/php
container_name: redactedname_php
volumes:
- .:/home/wwwroot
The existing repo is a hodgepodge of 2 Symfony versions (1 and 3) and a bunch of other stuff. It has a .htaccess
file in its root to direct requests to the appropriate version of Symfony. Each Symfony directory also has its own .htaccess
:
├── redacted-repo-name/
│ ├── .htaccess
│ ├── symfony/ # Symfony 1 repo
│ │ └── .htaccess
│ └── redactedname/ # Symfony 3 repo
│ └── .htaccess
Running docker-compose up --build
builds and runs the Docker containers without a hitch. However, going to localhost:8080
gives me the message "File not found." which I understand is a thing vhost or htaccess issue.
My vhost looks like this:
<VirtualHost *:80>
Define server_name redactedname.local
Define docrootweb /home/wwwroot
Define logdir /var/log/apache2/
DocumentRoot ${docrootweb}
ServerName ${server_name}
ServerAlias wwww.${server_name}
ErrorLog ${logdir}/error.log
CustomLog ${logdir}/access.log Combined
DirectoryIndex index.php
SetEnv APPLICATION_ENV dev
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
<Directory ${docrootweb}>
AllowOverride All
Allow from All
Require all granted
DirectoryIndex index.php index.html
</Directory>
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<FilesMatch .php$>
SetHandler "proxy:fcgi://redactedname_php:9000"
</FilesMatch>
Undefine server_name
Undefine docrootweb
Undefine logdir
</VirtualHost>
And the .htaccess
in the application's root includes this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [redirect=503,last]
# Symfony 3 Redirects
RewriteRule ^json/platform/(.*)$ /redactedname/web/app.php/json/platform/$1 [QSA,L]
RewriteRule ^json/like/(.*)$ /redactedname/web/app.php/json/like/$1 [QSA,L]
RewriteRule ^json/el2/(.*)$ /redactedname/web/app.php/json/el2/$1 [QSA,L]
#...
# End of Symfony 3 Redirects#
RewriteRule ^symfony - [L]
RewriteRule ^redactedname - [L]
RewriteRule ^index.php(.*) /symfony/web/index.php/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /symfony/web/index.php [QSA,L]
</IfModule>
The RewriteRule ^index.php(.*) /symfony/web/index.php/$1 [QSA,L]
should handle localhost:8080/, but I see "File not found."
If I direct my browser to localhost:8080/symfony/web/index.php
I do get served the correct page.
Perhaps of note, the .htaccess
files in the root of Symfony 1 and Symfony 3 look like this:
symfony/.htaccess (Symfony 1):
RewriteEngine On
RewriteRule ^(.*)$ /symfony/web/$1 [L]
redactedname/.htaccess (Symfony 3):
RewriteEngine On
RewriteRule ^(.*)$ /redactedname/web/$1 [L]
Thank you for any help! I'm trying to push Docker/containers at my organization and getting this working is a prerequisite, so any help is greatly appreciated!