Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
986 views
in Technique[技术] by (71.8m points)

php - Apache docker container - Invalid command 'RewriteEngine'

I use docker compose. However, when I run "docker-compose up", I came across an error : /var/www/html/.htaccess: Invalid command 'RewriteEngine'.

Can you tell me where I fails ??

Project architecture :

project-name /
             / docker-compose.yml
             / Dockerfile
             / apache.conf
             / php.ini
             / src /
                   / index.php
                   / .htaccess

docker-compose.yml :

web:
    build: .
    ports:
        - "80:80"
    volumes:
        - ./src:/var/www/html
        - php.ini:/usr/local/etc/php/conf.d/30-custom.ini
        - apache.conf:/etc/apache2/sites-enabled
    environment:
        - ALLOW_OVERRIDE=true

Dockerfile :

FROM php:7.0-apache

RUN a2enmod rewrite

RUN service apache2 restart

ADD ./src /var/www/html

php.ini :

display_errors=1
error_reporting=E_ALL

apache.conf (with my ip address) :

<VirtualHost *:80>
    ServerName xxx.xxx.xx.xxx
    DocumentRoot /var/www/html
</VirtualHost>

I type in the command line :

docker@default:/blabla/project-name$ docker-compose up

it returns me :

AH00558: apache2: Could not reliably determine the server's fully 
qualified domain name, using xxx.xx.x.x. Set the 'ServerName' directive 
globally to suppress this message

and

/var/www/html/.htaccess: Invalid command 'RewriteEngine', 
perhaps misspelled or defined by a module not included in the server
configuration

and in the browser, in my ip address (http://xxx.xxx.xx.xxx/) :

500 Internal servor error

my .htaccess :

<files .htaccess>
    Require all denied
</files>
Options +FollowSymlinks -Indexes -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$   /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

I'm on windows and i use Oracle VM Virtual Box.

Thank you in advance !

EDIT : I should say that if I delete rewrite rules, everything works.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works for me:

# Dockerfile
FROM php:5.6-apache

MAINTAINER Raphael M?der <me@randm.ch>

RUN a2enmod rewrite

ADD . /var/www/html

Don't forget to run your docker-compose up command with --build if you have already built the image previously, otherwise it will run the old image which may have not included the RUN a2enmod rewrite statement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...