Docker - how to set up Apache + PHP in docker-compose.yml Docker - how to set up Apache + PHP in docker-compose.yml apache apache

Docker - how to set up Apache + PHP in docker-compose.yml


I would choose webdevops dockerized apache, because it has simple configuration:

version: '2'services:    php:        build: php        expose:            - 9000        volumes:            - ./php/www:/var/www/html    apache2:        image: webdevops/apache:latest        args:            - PHP_SOCKET=php:9000        volumes:            - ./php/www:/var/www/html        ports:            - 80:80            - 443:443        links:            - php


Since the example above does not work, here is a different approach:docker-compose.yml

version: '3.1'services:  php:    image: php:7.4-apache    ports:      - 80:80    volumes:      - ./php/www:/var/www/html/

Launch the server with

docker-compose up


  1. We need to create a new folders /php/www in current path

  2. Create a file under php folder save as "Dockerfile" which contains as below without quote

"FROM php:5.6-apacheRUN docker-php-ext-install mysqli"

  1. Copy your docker-compose.yml file in your current folder where your "php" folder has.

  2. Create a sample file "index.php" under www folder (/php/www/index.php)

  3. Run in command prompt docker-compose up -d

  4. Open your browser type "localhost" you can see your sample file results.

Note: Above steps as per above mentioned docker-compose.yml file.