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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With