Docker - Build a PHP with Apache HTTP Server

I can't stop play with Docker 🐳.

Let setup and configure PHP development environment.

Can you imagine using docker build PHP and apache environment need how long ?

1. First let Create a folder call docker_dev_php.

2. Create a Dockerfile with below configuration

FROM php:7.3.0-apache  
COPY src/ /var/www/html  
EXPOSE 80  

FROM php:7.3.0-apache Download official php 7.3.0 version Images with Apache HTTP Server from docker hub'

COPY src/ /var/www/html Create a main working directory inside docker container '

EXPOSE 80 Used to expose port 80 (HTTP) from the docker container to the host machine.

2. Create local folder for our PHP script folder name let call it src.

3. Create a PHP script

index.php

<?php  
    echo 'Hello World';
?>

Let print put the php info to verify PHP and Apache.

4.Build the image by Dockerfile

docker build -t php_env .

6 Run the Docker container Image

docker run -p 8080:80 php_env

Run Docker container and map a port 8080 from the host computer to container port 80.

7 Check on Browser

Open a browser and with URL http://localhost:8080 ,

You should see the Hello World message on the browser.

Is cool right! Setup and configuration a PHP development environment

less than 10 minutes.

8. Create a PHP script for Mount a local directory

info.php

<?php  
   phpinfo();
?>

9 Run the PHP script on local directory

docker run -p 8080:80 -v /Users/jack/Desktop/code/docker/docker_dev_php/src/:/var/www/html php_env

Open a browser with URL http://localhost:8080 ,

You should see the php info function print out all the PHP configuration information on the page

This is extreme Fast to build-up a PHP Apache environment on any platform. And less painful and happy! If you have install a PHP apache on a local machine experience.

Wonderful Life ~