How to setup Apache webserver in Docker containers
In our previous post on Docker web hosting, we saw the benefits of Docker that makes it suitable for specialized hosting at low costs.
In web hosting, there are many key components such as web server, email server, dns server, etc. that are required for the website functioning.
Today, we’ll discuss how to setup an Apache webserver in Docker container.
1. Create Apache Docker container
The first step is to create a Docker container with the Apache image ‘httpd’. This can be done using the command ‘docker run’, giving the Apache directory as parameter:
docker run -dit --name apache-web -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
A container with the Apache webserver image was created, and listed, as seen from the ‘docker ps’ command.
2. Edit the Apache configuration file
Once the webserver container is created, the Docker container can be accessed using ‘docker exec’ command to generate a bash session.
The configuration file for the webserver would be in the folder ‘/usr/local/apache2/conf/’ and can be edited further to suit your requirements.
[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]
3. Enable PHP support in Apache
To enable PHP support in the Apache webserver, you would have to use an image with Apache and PHP support, say ‘
Also, other relevant modules such as php-mysql and tools such as curl, would have to be installed.
The apache webserver would be now running inside the container and can be verified from within the bash session.