Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker apache2 will not consider new 000-default.conf

I am trying to dockerize Laravel 5.2 app. For this I am using following images,

php:apache
mysql:5.7

Below is my docker-compose.yml

web:
  build: .
  volumes:
    - ./:/var/www/html
  ports:
    - "9899:80"
  links:
    - db
  command : [/usr/sbin/apache2ctl, -D, FOREGROUND]

db:
  image: mysql:5.7
  volumes:
    - /home/data:/var/lib/mysql
  environment:
    MYSQL_DATABASE: custom
    MYSQL_ROOT_PASSWORD: custom

And my Dockerfile

FROM php:apache
RUN apt-get update && docker-php-ext-install pdo pdo_mysql
RUN rm -f /etc/apache2/sites-available/000-default.conf
ADD ./settings/000-default.conf /etc/apache2/sites-available

Both Dockerfile and docker-compose.yml are in the laravel root directory. To run laravel based app, server must point to public folder. So, you can see I am replacing apache2's default configuration file with below 000-default.conf file,

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Everything runs fine on docker-compose up command but, when I browse localhost:9899 I get Forbidden error, but localhost:9899/public launches laravel app correctly. That means my supplied 000-default.conf is not having effect and server still points to /var/www/html/ instead of /var/www/html/public.

So I tried, exec to get into running container to check the 000-default.conf. And I could see my file instead of default. I am not getting my head around this issue. I want apache to consider my 000-default.conf . I hope you guys can see what I am doing wrong.

like image 310
pinkal vansia Avatar asked Feb 16 '16 13:02

pinkal vansia


1 Answers

Apache does not look into the sites-available directory but rather in the sites-enabled directory. You can either ADD your config-file into the latter directory, or set up a symlink:

ADD ./settings/000-default.conf /etc/apache2/sites-available
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf
like image 66
Pit Avatar answered Sep 24 '22 07:09

Pit