Muhammad Ibrahim
Muhammad Ibrahim

Reputation: 557

Docker container giving Internal Server Error on using .htaccess

When i run my app in docker contaner with out htaccess it works perfectly. But when i add .htaccess to the rewrite rule it is causing internal server here. I also granted permission to apache vhost but still the result is same.

Here is my dockerfile

FROM php:7.2-apache

RUN apt-get update

RUN apt-get install -y wget lsb-release gnupg2

RUN echo "deb http://packages.couchbase.com/ubuntu bionic bionic/main" | tee /etc/apt/sources.list.d/couchbase.list

RUN wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | apt-key  add -

RUN apt-get update

#RUN apt search libcouchbase

RUN apt-get install -y  libcouchbase2-libevent libcouchbase-dev

RUN apt-get update

RUN pecl install https://packages.couchbase.com/clients/php/couchbase-2.6.2.tgz 

COPY ./config/php/php.ini /usr/local/etc/php/

#WORKDIR /var/www/html/

#COPY ./pos/backend/ /var/www/html/pos/backend/

RUN chown www-data:www-data . -R

RUN a2enmod rewrite

EXPOSE 80

Here is my docker-compose

version: '3.1'

services:
  php:
    container_name: php_apache
    depends_on:
      - db
    build:
      context: .
    ports:
      - "80:80"
    restart: always  
    volumes:
      - ./config/vhosts:/etc/apache2/sites-enabled
      - ./backend/:/var/www/html/

  db:
    image: couchbase:community-6.6.0
    container_name: couchbase_server
    deploy:
      replicas: 1
    volumes:
      - ~/couchbase/node1:/opt/couchbase/var
    ports:
      - 8091:8091
      - 8092:8092
      - 8093:8093
      - 8094:8094
      - 11210:11210  

here is my htaccess file

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f   ls
  RewriteRule ^ index.php [QSA,L]  
</IfModule> 

vhost file apache default.conf

<Directory /var/www/>
        Require all granted
</Directory>  

Upvotes: 1

Views: 1331

Answers (1)

Muhammad Ibrahim
Muhammad Ibrahim

Reputation: 557

Dont know whats happening but i found this on google and it solved my issue . Incase if some face same

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

Upvotes: 1

Related Questions