D
D
Dmitry Baskakov2019-09-11 05:39:56
Apache HTTP Server
Dmitry Baskakov, 2019-09-11 05:39:56

How to activate mod_rewrite in php:7.2-apache in Docker?

There is such a docker-compose.yml file

spoiler

version: '2.3'

services:
  web:
    image: php:7.2-apache
    ports:
      - 8181:80
    volumes:
      - ./src:/var/www/html
  db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - ./db_data:/var/lib/mysql
    ports:
      - 3307:3306
    environment:
      MYSQL_DATABASE: login
      MYSQL_USER: login
      MYSQL_PASSWORD: root
      MYSQL_RANDOM_ROOT_PASSWORD: '1'

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    ports:
      - 8282:80
    environment:
      PMA_HOST: db


There is such .htaccess
spoiler
# Включаем mod_rewrite
RewriteEngine On

# Убираем последний слеш
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Преобразуем /pages/about.php в /about
RewriteRule ^(\w+)$ /pages/$1.php [L,NC]

And there was an attempt to make such a Dockerfile:
spoiler
# Dockerfile
FROM php:7.2-apache

RUN a2enmod rewrite

Everything was started by the teamdocker-compose up --build

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Baskakov, 2019-09-13
@dmitrybascacov

If someone has the same question, then here is the solution:
You need to create your own php, apache images via Dockerfile, like this instruction .
In my case, there was also phpmyadmin and some mysql settings for it

V
Vitaly Karasik, 2019-09-11
@vitaly_il1

This is not ubuntu,
try following
https://stackoverflow.com/questions/49809748/add-m...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question