yii2: Do not work any redirect in docker

What steps will reproduce the problem?

  1. install docker CE
  2. build image and up it:

docker-compose.yml

version: '2'
services:
    php:
        #image: php:7.1-apache
        build: ./php-apache2
        volumes:
            - ./:/var/www/html/
            - ./apache_conf:/etc/apache2/sites-enabled/
        ports:
            - "8080:8080"

Dockerfile

FROM php:7.1-apache
RUN a2enmod rewrite

#Add Microsoft repo for Microsoft ODBC Driver 13 for Linux
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update
#Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
    unixodbc \
    unixodbc-dev \
    libgss3 \
    odbcinst \
    msodbcsql \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
#Install PHP extensions
RUN pecl install \
        pdo_sqlsrv-4.3.0 \
        sqlsrv-4.3.0 \
    && docker-php-ext-install \
        pdo \
        pdo_mysql \
    && docker-php-ext-enable \
        pdo_sqlsrv \
        sqlsrv

virtualhost config

Listen 8080
<VirtualHost *:8080>
        ServerName localhost
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html/frontend/web/
	LogLevel debug
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
	# Set up rewrites so that all requests go to index.php
       RewriteEngine on
</VirtualHost>
  1. download and install yii2 advance
  2. try any redirect

What is the expected result?

Redirect

What do you get instead?

Nothing Redirect do not work

Additional info

Q A
Yii version 2.0.12
PHP version 7.1
Operating system debian 9
Web server Apache2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (17 by maintainers)

Most upvoted comments

I’ve tried config from the first post with some adjustments:

composer create-project --prefer-dist yiisoft/yii2-app-advanced@dev yii-docker-application
cd yii-docker-application
docker pull php:7.1-apache
cat <<EOF > php-apache2
FROM php:7.1-apache                                                                                                                                                                                                                            
RUN a2enmod rewrite
EOF
cat <<EOF > docker-compose.yml
version: '2'
services:
    php:
        build:
          context: ./
          dockerfile: php-apache2
        volumes:
            - ./:/var/www/html/
            - ./apache_conf:/etc/apache2/sites-enabled/
        ports:
            - "8080:8080"
EOF
mkdir apache_conf
cat <<EOF > apache_conf/site.conf
Listen 8080
<VirtualHost *:8080>
        ServerName localhost
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html/frontend/web/
	LogLevel debug
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
	# Set up rewrites so that all requests go to index.php
       RewriteEngine on
</VirtualHost>
EOF
./init --env=Development
docker-compose up

In this environment redirect works exactly as it should, so I’m closing the issue.