Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 1bb730a

Browse files
committed
Merge pull request #35 from jdeathe/issue/31
ISSUE 31: Updated README ready for release 1.3.1.
2 parents 1501e88 + 9841ee5 commit 1bb730a

File tree

1 file changed

+119
-78
lines changed

1 file changed

+119
-78
lines changed

README.md

Lines changed: 119 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
centos-ssh-apache-php-fcgi
22
==========================
33

4-
Docker Image including CentOS-6 6.6 x86_64, Apache 2.2, PHP 5.3, PHP memcached 1.0, PHP APC 3.1, Composer.
4+
Docker Image including CentOS-6 6.6 x86_64, Apache 2.2, PHP 5.3, PHP memcached 1.0, PHP APC 3.1.
55

6-
Apache (mod_fcgid) loads only a minimal set of modules by default. Supports custom configuration via a configuration data volume.
6+
Apache PHP web server, loading only a minimal set of Apache modules by default. Supports custom configuration via environment variables and/or a configuration data volume.
77

88
## Overview & links
99

1010
The [Dockerfile](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/Dockerfile) can be used to build a base image that can be run as-is or used as the bases for other more specific builds.
1111

12-
Included in the build is the EPEL repository and SSH, vi, elinks (for fullstatus support), APC, Memcache and Composer are installed along with python-pip, supervisor and supervisor-stdout.
12+
This build of [Apache](https://httpd.apache.org/), (httpd CentOS package), uses the [mod_fcgid](https://httpd.apache.org/mod_fcgid/) module to run [PHP](http://php.net/) as a [FastCGI](http://www.fastcgi.com/) process.
1313

14-
[Supervisor](http://supervisord.org/) is used to start httpd (and optionally the sshd) daemon when a docker container based on this image is run. To enable simple viewing of stdout for the sshd subprocess, supervisor-stdout is included. This allows you to see output from the supervisord controlled subprocesses with `docker logs <docker-container-name>`.
14+
Included in the build are the [EPEL](http://fedoraproject.org/wiki/EPEL) and [IUS](https://ius.io/) repositories. Installed packages include [OpenSSH](http://www.openssh.com/portable.html) secure shell, [vim-minimal](http://www.vim.org/), [elinks](http://elinks.or.cz) (for fullstatus support), PHP [APC](http://pecl.php.net/package/APC), PHP [Memcached](http://pecl.php.net/package/memcached) are installed along with python-setuptools, [supervisor](http://supervisord.org/) and [supervisor-stdout](https://github.com/coderanger/supervisor-stdout).
1515

16-
SSH is not required in order to access a terminal for the running container the preferred method is to use Command Keys and the nsenter command. See [command-keys.md](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/command-keys.md) for details on how to set this up.
16+
Supervisor is used to start httpd.worker daemon when a docker container based on this image is run. To enable simple viewing of stdout for the sshd subprocess, supervisor-stdout is included. This allows you to see output from the supervisord controlled subprocesses with ```docker logs <docker-container-name>```.
1717

1818
If enabling and configuring SSH access, it is by public key authentication and, by default, the [Vagrant](http://www.vagrantup.com/) [insecure private key](https://github.com/mitchellh/vagrant/blob/master/keys/vagrant) is required.
1919

20+
### SSH Alternatives
21+
22+
SSH is not required in order to access a terminal for the running container. The simplest method is to use the docker exec command to run bash (or sh) as follows:
23+
24+
```
25+
$ docker exec -it <docker-name-or-id> bash
26+
```
27+
28+
For cases where access to docker exec is not possible the preferred method is to use Command Keys and the nsenter command. See [command-keys.md](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/command-keys.md) for details on how to set this up.
29+
2030
## Quick Example
2131

2232
Run up a container named ```apache-php.app-1.1.1``` from the docker image ```jdeathe/centos-ssh-apache-php-fcgi``` on port 8080 of your docker host.
@@ -25,12 +35,12 @@ Run up a container named ```apache-php.app-1.1.1``` from the docker image ```jde
2535
$ docker run -d \
2636
--name apache-php.app-1.1.1 \
2737
-p 8080:80 \
28-
--env SERVICE_UNIT_APP_GROUP=app-1 \
29-
--env SERVICE_UNIT_LOCAL_ID=1 \
30-
--env SERVICE_UNIT_INSTANCE=1 \
31-
--env APACHE_SERVER_NAME=app-1.local \
32-
--env APACHE_SERVER_ALIAS=app-1 \
33-
--env DATE_TIMEZONE=UTC \
38+
--env "SERVICE_UNIT_APP_GROUP=app-1" \
39+
--env "SERVICE_UNIT_LOCAL_ID=1" \
40+
--env "SERVICE_UNIT_INSTANCE=1" \
41+
--env "APACHE_SERVER_ALIAS=app-1" \
42+
--env "APACHE_SERVER_NAME=app-1.local" \
43+
--env "DATE_TIMEZONE=UTC" \
3444
-v /var/services-data/apache-php/app-1:/var/www/app \
3545
jdeathe/centos-ssh-apache-php-fcgi:latest
3646
```
@@ -67,21 +77,50 @@ $ docker run \
6777

6878
### Running
6979

70-
To run the a docker container from this image you can use the included [run.sh](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.sh) and [run.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.conf) scripts. The helper script will stop any running container of the same name, remove it and run a new daemonised container on an unspecified host port. Alternatively you can use the following.
80+
To run the a docker container from this image you can use the included [run.sh](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.sh) and [run.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.conf) scripts. The helper script will stop any running container of the same name, remove it and run a new daemonised container on an unspecified host port. Alternatively you can use the following methods to make the http service available on ports 8080 of the docker host.
81+
82+
#### Using environment variables
83+
84+
*Note:* Settings applied by environment variables will override those set within configuration volumes from release 1.3.1. Existing installations that use the apache-bootstrap.conf saved on a configuration "data" volume will not allow override by the environment variables. Also apache-bootstrap.conf can be updated to prevent the value being replaced by that set using the environment variable.
7185

7286
```
7387
$ docker stop apache-php.app-1.1.1 && \
7488
docker rm apache-php.app-1.1.1
7589
$ docker run -d \
7690
--name apache-php.app-1.1.1 \
7791
-p 8080:80 \
78-
-p 8580:8443 \
79-
--env SERVICE_UNIT_INSTANCE=app-1 \
80-
--env SERVICE_UNIT_LOCAL_ID=1 \
81-
--env SERVICE_UNIT_INSTANCE=1 \
82-
--env APACHE_SERVER_NAME=app-1.local \
83-
--env APACHE_SERVER_ALIAS=app-1 \
84-
--env DATE_TIMEZONE=UTC \
92+
--env "SERVICE_UNIT_INSTANCE=app-1" \
93+
--env "SERVICE_UNIT_LOCAL_ID=1" \
94+
--env "SERVICE_UNIT_INSTANCE=1" \
95+
--env "APACHE_SERVER_ALIAS=app-1" \
96+
--env "APACHE_SERVER_NAME=app-1.local" \
97+
--env "APACHE_LOAD_MODULES=authz_user_module log_config_module expires_module deflate_module headers_module setenvif_module mime_module status_module dir_module alias_module rewrite_module" \
98+
--env "APACHE_MOD_SSL_ENABLED=false" \
99+
--env "APP_HOME_DIR=/var/www/app-1" \
100+
--env "DATE_TIMEZONE=UTC" \
101+
--env "SERVICE_USER=app" \
102+
--env "SERVICE_USER_GROUP=app-www" \
103+
--env "SERVICE_USER_PASSWORD=" \
104+
-v /var/services-data/apache-php/app-1:/var/www/app-1 \
105+
jdeathe/centos-ssh-apache-php-fcgi:latest
106+
```
107+
108+
#### Using configuration volume
109+
110+
The following example uses the settings from the optonal configuration volume volume-config.apache-php.app-1.1.1 and maps a data volume for persistent storage of the Apache app data on the docker host.
111+
112+
```
113+
$ docker stop apache-php.app-1.1.1 && \
114+
docker rm apache-php.app-1.1.1
115+
$ docker run -d \
116+
--name apache-php.app-1.1.1 \
117+
-p 8080:80 \
118+
--env "SERVICE_UNIT_INSTANCE=app-1" \
119+
--env "SERVICE_UNIT_LOCAL_ID=1" \
120+
--env "SERVICE_UNIT_INSTANCE=1" \
121+
--env "APACHE_SERVER_ALIAS=app-1" \
122+
--env "APACHE_SERVER_NAME=app-1.local" \
123+
--env "DATE_TIMEZONE=UTC" \
85124
--volumes-from volume-config.apache-php.app-1.1.1 \
86125
-v /var/services-data/apache-php/app-1:/var/www/app \
87126
jdeathe/centos-ssh-apache-php-fcgi:latest
@@ -99,109 +138,111 @@ The output of the logs should show the Apache modules being loaded and auto-gene
99138

100139
There are several environmental variables defined at runtime these allow the operator to customise the running container which may become necessary when running several on the same docker host, when clustering docker hosts or to simply set the timezone.
101140

102-
##### 1. SERVICE_UNIT*
141+
##### 1. SERVICE_UNIT_INSTANCE, SERVICE_UNIT_LOCAL_ID & SERVICE_UNIT_INSTANCE
103142

104-
The ```SERVICE_UNIT``` environmental variables are used to set a response header named ```X-Service-Uid``` that lets you identify the container that is serving the content. This is useful when you have many containers running on a single host using different ports (i.e with different ```SERVICE_UNIT_LOCAL_ID``` values) or if you are running a cluster and need to identify which host the content is served from (i.e with different ```SERVICE_UNIT_INSTANCE``` values). The three values should map to the last 3 dotted values of the container name; in our case that is "app-1.1.1"
143+
The ```SERVICE_UNIT_INSTANCE```, ```SERVICE_UNIT_LOCAL_ID``` and ```SERVICE_UNIT_INSTANCE``` environmental variables are used to set a response header named ```X-Service-Uid``` that lets you identify the container that is serving the content. This is useful when you have many containers running on a single host using different ports (i.e with different ```SERVICE_UNIT_LOCAL_ID``` values) or if you are running a cluster and need to identify which host the content is served from (i.e with different ```SERVICE_UNIT_INSTANCE``` values). The three values should map to the last 3 dotted values of the container name; in our case that is "app-1.1.1"
105144

106145
```
107146
...
108-
--env SERVICE_UNIT_APP_GROUP=app-1 \
109-
--env SERVICE_UNIT_LOCAL_ID=1 \
110-
--env SERVICE_UNIT_INSTANCE=1 \
147+
--env "SERVICE_UNIT_APP_GROUP=app-1" \
148+
--env "SERVICE_UNIT_LOCAL_ID=1" \
149+
--env "SERVICE_UNIT_INSTANCE=1" \
111150
...
112151
```
113152

114-
##### 2. APACHE_SERVER*
153+
##### 2. APACHE_SERVER_NAME & APACHE_SERVER_ALIAS
115154

116155
The ```APACHE_SERVER_NAME``` and ```APACHE_SERVER_ALIAS``` environmental variables are used to set the VirtualHost ```ServerName``` and ```ServerAlias``` values respectively. In the following example the running container would respond to the host names ```app-1.local``` or ```app-1```:
117156

118157
```
119158
...
120-
--env APACHE_SERVER_NAME=app-1.local \
121-
--env APACHE_SERVER_ALIAS=app-1 \
159+
--env "APACHE_SERVER_ALIAS=app-1" \
160+
--env "APACHE_SERVER_NAME=app-1.local" \
122161
...
123162
```
124163

125164
from your browser you can then access it with ```http://app-1.local:8080``` assuming you have the IP address of your docker mapped to the hostname using your DNS server or a local hosts entry.
126165

127-
##### 3. DATE_TIMEZONE
128-
129-
The default timezone for the container, and the PHP app, is UTC however the operator can set an appropriate timezone using the ```DATE_TIMEZONE``` variable. The value should be a timezone identifier, like UTC or Europe/London. The list of valid identifiers is available in the PHP [List of Supported Timezones](http://php.net/manual/en/timezones.php).
166+
##### 3. APACHE_LOAD_MODULES
130167

131-
To set the timezone for the UK and account for British Summer Time you would use:
168+
The variable ```APACHE_LOAD_MODULES``` defines all Apache modules to be loaded from */etc/httpd/conf/http.conf*. The default is the minimum required so you may need to add more as necessary. To add the "mod\_rewrite" Apache Module you would add it's identifier ```rewrite_module``` to the array as follows.
132169

133170
```
134171
...
135-
--env DATE_TIMEZONE=Europe/London \
172+
--env "APACHE_LOAD_MODULES=authz_user_module log_config_module expires_module deflate_module headers_module setenvif_module mime_module status_module dir_module alias_module rewrite_module"
136173
...
137174
```
138175

139-
### Custom Configuration
176+
##### 4. APACHE_MOD_SSL_ENABLED
140177

141-
If using the optional data volume for container configuration you are able to customise the configuration. In the following examples your custom docker configuration files should be located on the Docker host under the directory ```/etc/service-config/<container-name>/``` where ```<container-name>``` should match the applicable container name such as "apache-php.app-1.1.1" in the examples.
178+
By default SSL support is disabled but a second port, (mapped to 8443), is available for traffic that has been been through upstream SSL termination (SSL Offloading). If you want the container to support SSL directly then set ```APACHE_MOD_SSL_ENABLED=true``` this will then generate a self signed certificate and will update Apache to accept traffic on port 443.
142179

143-
#### [httpd/apache-bootstrap.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/apache-bootstrap.conf)
180+
*Note:* The included helper script [run.sh](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.sh) will automatically map the docker host port 8580 to 443 but if you are running docker manually can use the following.
144181

145-
The bootstrap script initialises the app. It sets up the Apache service user + group, generates passwords, enables Apache modules and adds/removes SSL support.
182+
```
183+
$ docker stop apache-php.app-1.1.1 && \
184+
docker rm apache-php.app-1.1.1
185+
$ docker run -d \
186+
--name apache-php.app-1.1.1 \
187+
-p 8080:80 \
188+
-p 8580:443 \
189+
--env "SERVICE_UNIT_APP_GROUP=app-1" \
190+
--env "SERVICE_UNIT_LOCAL_ID=1" \
191+
--env "SERVICE_UNIT_INSTANCE=1" \
192+
--env "APACHE_SERVER_ALIAS=app-1" \
193+
--env "APACHE_SERVER_NAME=app-1.local" \
194+
--env "APACHE_MOD_SSL_ENABLED=true" \
195+
--env "DATE_TIMEZONE=UTC" \
196+
-v /var/services-data/apache-php/app-1:/var/www/app \
197+
jdeathe/centos-ssh-apache-php-fcgi:latest
198+
```
146199

147-
##### 1. Service User
200+
##### 5. APP_HOME_DIR
148201

149-
Use the ```SERVICE_USER*``` variables in your custom apache-bootstrap.conf file to override this and to also define a custom username and/or group.
202+
The home directory of the service user and parent directory of the Apache DocumentRoot is /var/www/app by default but can be changed if necessary using the ```APP_HOME_DIR``` environment variable. It is also necessary to change the target of the data volume mapping accordingly as in the following example where /var/www/app-1 is used.
150203

151204
```
152-
SERVICE_USER=apacheUser
153-
SERVICE_USER_GROUP=apacheGroup
154-
SERVICE_USER_PASSWORD=userPassword123
155-
SERVICE_USER_GROUP_PASSWORD=userGroupPassword123
205+
...
206+
--env "APP_HOME_DIR=/var/www/app-1" \
207+
-v /var/services-data/apache-php/app-1:/var/www/app-1 \
208+
...
156209
```
157210

158-
##### 2. Apache Modules
211+
##### 6. DATE_TIMEZONE
159212

160-
The variable ```APACHE_LOAD_MODULES``` defines all Apache modules to be loaded from */etc/httpd/conf/http.conf*. The default is the minimum required so you may need to add more as necessary. To add the "mod\_rewrite" Apache Module you would add it's identifier ```rewrite_module``` to the array as follows.
213+
The default timezone for the container, and the PHP app, is UTC however the operator can set an appropriate timezone using the ```DATE_TIMEZONE``` variable. The value should be a timezone identifier, like UTC or Europe/London. The list of valid identifiers is available in the PHP [List of Supported Timezones](http://php.net/manual/en/timezones.php).
214+
215+
To set the timezone for the UK and account for British Summer Time you would use:
161216

162217
```
163-
APACHE_LOAD_MODULES="
164-
authz_user_module
165-
log_config_module
166-
expires_module
167-
deflate_module
168-
headers_module
169-
setenvif_module
170-
mime_module
171-
status_module
172-
dir_module
173-
alias_module
174-
rewrite_module
175-
"
218+
...
219+
--env "DATE_TIMEZONE=Europe/London" \
220+
...
176221
```
177222

178-
##### 3. SSL Support
179-
180-
By default SSL support is disabled but a second port, (mapped to 8443), is available for traffic that has been been through upstream SSL termination (SSL Offloading). If you want the container to support SSL directly then set ```APACHE_MOD_SSL_ENABLED=true``` this will then generate a self signed certificate and will update Apache to accept traffic on port 443.
223+
##### 7. SERVICE_USER, SERVICE_USER_GROUP & SERVICE_USER_PASSWORD
181224

182-
*Note:* The included helper script [run.sh](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/run.sh) will automatically map the docker host port 8580 to 443 but if you are running docker manually can use the following.
225+
Use the ```SERVICE_USER```, ```SERVICE_USER_GROUP``` and ```SERVICE_USER_PASSWORD``` environment variables to define a custom service username, group and password respectively. If the password is left an empty string then it is automatically generated on first run which is the default.
183226

184227
```
185-
$ docker stop apache-php.app-1.1.1 && \
186-
docker rm apache-php.app-1.1.1
187-
$ docker run -d \
188-
--name apache-php.app-1.1.1 \
189-
-p 8080:80 \
190-
-p 8580:443 \
191-
--env SERVICE_UNIT_APP_GROUP=app-1 \
192-
--env SERVICE_UNIT_LOCAL_ID=1 \
193-
--env SERVICE_UNIT_INSTANCE=1 \
194-
--env APACHE_SERVER_NAME=app-1.local \
195-
--env APACHE_SERVER_ALIAS=app-1 \
196-
--env DATE_TIMEZONE=UTC \
197-
--volumes-from volume-config.apache-php.app-1.1.1 \
198-
-v /var/services-data/apache-php/app-1:/var/www/app \
199-
jdeathe/centos-ssh-apache-php-fcgi:latest
228+
...
229+
--env "SERVICE_USER=apacheUser" \
230+
--env "SERVICE_USER_GROUP=apacheGroup" \
231+
--env "SERVICE_USER_PASSWORD=userPassword123" \
232+
...
200233
```
201234

235+
### Custom Configuration
236+
237+
If using the optional data volume for container configuration you are able to customise the configuration. In the following examples your custom docker configuration files should be located on the Docker host under the directory ```/etc/service-config/<container-name>/``` where ```<container-name>``` should match the applicable container name such as "apache-php.app-1.1.1" in the examples.
238+
239+
#### [httpd/apache-bootstrap.conf](https://github.com/jdeathe/centos-ssh-apache-php-fcgi/blob/centos-6/etc/services-config/httpd/apache-bootstrap.conf)
240+
241+
The bootstrap script initialises the app. It sets up the Apache service user + group, generates passwords, enables Apache modules and adds/removes SSL support.
242+
202243
#### ssl/certs/localhost.crt
203244

204-
You may need to override the default auto-generated self signed certificate. To do this you can add the SSLCertificateFile to your config directory using the filename ```localhost.crt``` for example:
245+
You may need to override the default auto-generated self signed certificate. To do this you can add the SSLCertificateFile to the Docker hosts directory using the filename ```localhost.crt``` for example:
205246

206247
```
207248
/etc/services-config/apache-php.app-1.1.1/ssl/certs/localhost.crt
@@ -223,7 +264,7 @@ To override the SSLCertificateKeyFile add it to your config directory using the
223264

224265
The supervisor service's configuration can also be overridden by editing the custom supervisord.conf file. It shouldn't be necessary to change the existing configuration here but you could include more [program:x] sections to run additional commands at startup.
225266

226-
### DocumentRoot Data Directory
267+
### Apache DocumentRoot - Data Directory
227268

228269
In the previous example Docker run commands we mapped the Docker host directory ```/var/services-data/apache-php/app-1``` to ```/var/www/app``` in the Docker container, where ```/var/services-data/``` is the directory used to store persistent files and the subdirectory is used by an individual app's named container(s), ```apache-php.app-1.1.1```, in the previous examples.
229270

0 commit comments

Comments
 (0)