I've created a PHP/Apache/MySQL development environment with Docker and would like to set variable that I can use with $_SERVER
in PHP.
Usually I will configure something like that in my virtual host
SetEnv ENV "developement"
Is there a way to do it with my docker_compose.yml file ?
I'll try by using environment: - ENV=developement
in my docker-compose file but it doesn't work.
Here is my Dockerfile
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
and my docker-compose.yml
version: '2'
services:
webserver:
build: ./docker/webserver
image: dev_web
ports:
- "80:80"
- "443:443"
volumes:
- /pathtodev/www:/var/www/html
links:
- db
environment:
- ENV=developement
db:
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=******
- MYSQL_DATABASE=db_dev
Consider the below Dockerfile
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
RUN echo 'PassEnv FIRST_NAME' > /etc/apache2/conf-enabled/expose-env.conf
RUN echo '<?php echo $_SERVER["FIRST_NAME"];' > /var/www/html/first.php && echo '<?php echo $_SERVER["LAST_NAME"];' > /var/www/html/last.php
Now run the container using
docker run -it -e FIRST_NAME=TARUN -e LAST_NAME=LALWANI -p 80:80 4ba2aa50347b
Testing
$ curl localhost/first.php
TARUN
$ curl localhost/last.php
$
As you can see the only FIRST_NAME
can be accessed, because we exposed the same using PassEnv
directive in our apache config insider the container
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