dourao3960
dourao3960
2019-07-27 02:39

如何在Docker容器中安装PHP的mod_rewrite模块?

  • apache
  • php
  • docker

docker-compose.yml

version: "3.7"
services:

  php:
    build: './php/'
    volumes:
      - ./public_html/www/:/var/www/html/

  apache:
    build: './apache/'
    depends_on:
      - php
      - mysql
    ports:
      - "8080:80"
    volumes:
      - ./public_html/www/:/var/www/html/
      #- ./log:/var/log/apache2

  mysql:
    image: mysql:5.6.40
    ports:
      - "3306:3306"
    environment:
      - MYSQL_DATABASE=el-cigarette
      - MYSQL_ROOT_PASSWORD=root

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    links:
      - mysql
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
    ports:
      - '8081:80'



php/Dockerfile

FROM php:7.0-apache
MAINTAINER Webgriffe Srl <support@webgriffe.com>
RUN docker-php-ext-install mysqli && a2enmod rewrite

apache/demo.apache.conf

ServerName localhost

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so



<VirtualHost *:80>
    # Proxy .php requests to port 9000 of the php-fpm container
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
    DocumentRoot /var/www/html/

    DirectoryIndex index.php

    <Directory /var/www/html/>
        Options All
            AllowOverride All
        Order allow,deny
        Allow from all
            Require all granted
    </Directory>

    # Send apache logs to stdout and stderr
    CustomLog /var/www/1 common
    ErrorLog /var/www/2
</VirtualHost>

I inputted next commands docker-compose build docker-compose up -d

And I get that output Creating docker-local2_mysql_1 ... done Creating docker-local2_php_1 ... done Creating docker-local2_phpmyadmin_1 ... done Creating docker-local2_apache_1 ... done

Farther I write this
docker exec -it docker-local2_php_1 sh
# php -m

But I didn't see mod_rewrite module
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

My .htaccess file doesn't work Where did I go wrong? And what I need do to fix this trouble?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答