Docker setup for an Apache webserver with PHP (versions 7.1 and 5.4) and MySQL Server
Rename apache/vhosts-sample.json to apache/vhosts.json and edit it to add your own vhosts.
Run docker-compose up to launch the containers.
There is a tool to generate apache virtual hosts configuration files for each entry in apache/vhosts.json file.
The options available are:
- name: The name for the project. It will be prepended to the log filename and configuration filename.
- document_root: The path to the project relative to /var/www.
- server_name: the domain for the project.
- php_host (optional): which version of PHP to use. At the moment the only options are
php
orphp5
. Default value isphp
for PHP 7.1. - server_aliases: array for the server aliases.
- ssl: true if you want to enable ssl.
- cert_filename: required if you enable ssl, the filename must match the cert file in
apache/ssl
without the extension.
Run with node node apache/vhost-generator.js
to generate the vhost configuration files.
To enable a SSL Vhost you will need to generate a certificate for it. Edit apache/ssl-config-sample.json
adding the hosts you would like yo have SSL support and rename it to apache/ssl-config.json
.
Then run node node apache/cert-generator.js
.
This will create the certificate files inside apache/ssl
. You will need to install the certificate in your system.
There is a sample site with the domain localhost.test. After you have the docker images running you can access it by entering http://localhost.test or https://localhost.test in your browser. You will see a PHPInfo page.
To run the docker containers inside a VM you can use vagrant to spin up a VM and run the containers:
Steps:
- Install VirtualBox
- Install Vagrant
- Install vagrant plugin vbguest with
vagrant plugin install vagrant-vbguest
- Install vagrant plugin vagrant-docker-compose with
vagrant plugin install vagrant-docker-compose
- Run
vagrant up
Vagrant will install docker inside the VM and run docker-compose to run the containers.