Main problem:
http://localhost/mysite/source/aphpfile.php works.
http://localhost/mysite/aphpfile does not work despite a rewrite rule to run aphpfile.php.
I tried with the server placed in containers run from php:7.2-apache and php:7.4-apache container images from docker.io/library/. I had the same problem in both. When I try locally, the RewriteRule works perfectly. I want it to work in a container.
Folder structure on the disk (inside container):
/var/www/html/mysite/source/aphpfile.php
No .htaccess files included.
Configuration:
- Unmodified
/etc/apache2/apache.conffile. a2enmod rewritea2ensite mysite.confa2enmod info
With http://localhost/server-info loading correct configuration is confirmed:
Current Configuration: (from server-info page)
In file: /etc/apache2/sites-enabled/mysite.conf
1: <Directory "var/www/html/mysite/">
7: RewriteEngine On
9: RewriteCond %{REQUEST_FILENAME} !-d
10: RewriteCond %{REQUEST_FILENAME} !-f
11: RewriteRule ^aphpfile /var/www/html/mysite/source/aphpfile.php [L]
: </Directory>
Also the file /etc/apache2/sites-enabled/mysite.conf:
<Directory "var/www/html/mysite/">
Options +Indexes
AllowOverride All
Order allow,deny
Allow from all
Require all granted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^aphpfile /var/www/html/mysite/source/aphpfile.php [L] # <---- this line works in non-container server despite starting with /var/...
#to be sure, I tried also with ^/aphpfile ^mysite/aphpfile
# ^/mysite/aphpfile in additional lines seperately to point
# to /var/www/html/mysite/source/aphpfile.php [L]
# edit1, include exact lines I tried
# RewriteRule ^aphpfile /var/www/html/mysite/source/aphpfile.php [L] # <---- this line works in non-container server despite starting with /var/...
# RewriteRule ^aphpfile source/aphpfile.php [L] # <---- this I tried today after comment from @Daniel Farrell but no change in the result
# RewriteRule ^/aphpfile /var/www/html/mysite/source/aphpfile.php [L]
# RewriteRule ^source/aphpfile /var/www/html/mysite/source/aphpfile.php [L]
# RewriteRule ^/aphpfile /var/www/html/mysite/source/aphpfile.php [L]
</Directory>
Logs:
/var/log/apache2/access.log:
127.0.0.1 - - [31/Oct/2020:14:01:36 +0000] "GET /mysite/aphpfile HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
/var/log/apache2/error.log: shows no error related this particular request.
Extra details:
- Using
podman(not docker) podman exec -it <containername> bashto access/modify a container.- Took care of restarting
apache2service, verifying site and mod are enabled.
edit2
Not a solution to the problem but I'm moving on with alternative:
This way all functionality along with rewrite rule works.
Created new image:
#Dockerfile
FROM debian:buster-slim
RUN apt update -y \
&& apt install -y apache2 php php-<many extensions> \
&& apt clean all
#COPY <source> <dest>
#RUN <a2enmod, a2ensite>
CMD apachectl -D FOREGROUND
Still don't know why the official php:7.x-apache images are not working. (Bug?)