docker httpd php .htacces加载但php文件没有 [英] docker httpd php .htacces load but php files do not
问题描述
我正在尝试使用docker-compose加载以.htaccess引导的php应用程序.
I am trying to use docker-compose to load a php application which boot with a .htaccess.
如果我使用proxypassmatch起作用,但仅适用于一条路由,一旦url更改,文件就找不到了(我读到proxypass/reverseproxy/proxypassmatch)不能与.htaccess一起使用...?
If i use a proxypassmatch it works, but only for one route, as soon as the url change, the file is unfound (i read that proxypass/reverseproxy/proxypassmatch) can't be use with .htaccess ...?
如果我在虚拟主机上使用传统设置,则.htaccess可以正常工作,但php文件无法加载,而是其内容显示在屏幕上(无论使用哪种路由).
If i use the traditional setting, with a virtualhost, the .htaccess is working but the php file do not load, unstead its content appear on the screen (whatever the route).
我已经花了很多时间无所事事地四处寻找...或者为单个容器php-httpd更改图像?但我喜欢将它们分开的想法.
I have spent so many hours looking everywhere without any answer... Or maybe changing the image for a single container php-httpd ? but i like the idea to separate them.
如果有人知道如何修复它,那将非常感谢.
If someone know how to fix it, it would be great thank you.
查看docker-compose文件
See the docker-compose file
version: "3.2"
services:
php:
build: './php/'
volumes:
- ./MediterPourGrandir/:/var/www/html/
apache:
build: './apache/'
depends_on:
- php
- mysql
ports:
- "80:80"
volumes:
- ./MediterPourGrandir/:/var/www/html/
mysql:
image: mysql:5.6.40
#restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=monsupersite
- MYSQL_PASSWORD=root
ports:
- "3306:3306"
Apache Dockerfile
the apache Dockerfile
FROM httpd:2.4.33-alpine
RUN apk update; \
apk upgrade;
# Copy apache vhost file to proxy php requests to php-fpm container
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf && \
sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
>> /usr/local/apache2/conf/httpd.conf
apache配置文件
the apache config file
serverName localhost
<VirtualHost *:80>
DocumentRoot /var/www/html/
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Send apache logs to stdout and stderr
CustomLog /proc/self/fd/1 common
ErrorLog /proc/self/fd/2
</VirtualHost>
和php Dockerfile
and the php Dockerfile
FROM php:7.2.7-fpm-alpine3.7
RUN apk update; \
apk upgrade;
RUN apk update --no-cache \
&& apk add --no-cache $PHPIZE_DEPS \
&& apk add --no-cache mysql-dev \
&& docker-php-ext-install pdo pdo_mysql
推荐答案
我最终更改了图像(我不喜欢,但似乎没人知道如何处理这个图像,即使在Docker论坛上也是如此...),我使用php:7.2.1-apache
则效果很好.请参阅docker文件的配置: running-virtual-hosts-in-apache- docker-container
I finally change the image (i liked not but it looks like nobody knows how to do with this one, even on Docker forum... ), i use php:7.2.1-apache
then it works great. See the config of the docker file: running-virtual-hosts-in-apache-docker-container
我使用docker-compose将其连接到mysql的映像(就像以前一样).
I connect it to the mysql's image (like it was previously) using docker-compose.
version: "3.2"
services:
php-apache:
build:
context: ./apache-php
ports:
- 80:80
volumes:
- ./MediterPourGrandir/:/var/www/html/
mysql:
image: mysql:5.6.40
#restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=monsupersite
- MYSQL_PASSWORD=root
ports:
- "3306:3306"
#volumes:
#- ./var/www/html/'monsupersite (1).sql':/docker-entrypoint-initdb.d/'monsupersite (1).sql'
这篇关于docker httpd php .htacces加载但php文件没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!