Skip to content

Commit a0a3069

Browse files
author
Ric Harvey
committed
Split documentation for easier updates
1 parent 4cfc4cb commit a0a3069

File tree

10 files changed

+151
-140
lines changed

10 files changed

+151
-140
lines changed

README.md

Lines changed: 32 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
[![Travis](https://img.shields.io/docker/pulls/richarvey/nginx-php-fpm.svg?style=flat-square)]()
2-
[![Travis](https://img.shields.io/docker/stars/richarvey/nginx-php-fpm.svg?style=flat-square)]()
1+
[![Travis](https://img.shields.io/docker/pulls/richarvey/nginx-php-fpm.svg?style=flat-square)]() |
2+
[![Travis](https://img.shields.io/docker/stars/richarvey/nginx-php-fpm.svg?style=flat-square)]() |
33
[![Travis](https://img.shields.io/travis/ngineered/nginx-php-fpm.svg?style=flat-square)]()
44

5-
## Introduction
6-
This is a Dockerfile to build a container image for nginx and php-fpm, with the ability to pull website code from git. The container also has the ability to update templated files with variables passed to docker in order to update your settings. There is also support for lets encrypt SSL support.
5+
## Overview
6+
This is a Dockerfile/image to build a container for nginx and php-fpm, with the ability to pull website code from git when the container is created, as well as allowing the container to push and pull changes to the code to and from git. The container also has the ability to update templated files with variables passed to docker in order to update your code and settings. There is support for lets encrypt SSL configurations, custom nginx configs, core nginx/PHP variable overrides for running preferences, X-Forwarded-For headers and UID mapping for local volume support.
77

8-
### Git repository
9-
The source files for this project can be found here: [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
10-
11-
If you have any improvements please submit a pull request.
12-
### Docker hub repository
13-
The Docker hub build can be found here: [https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/](https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/)
14-
## Versions
8+
### Versions
159
| Tag | Nginx | PHP | Alpine |
1610
|-----|-------|-----|--------|
1711
| latest | 1.11.9 | 7.1.1 | 3.4 |
1812
| php71 | 1.11.9 | 7.1.1 | 3.4 |
19-
| php5 | 1.11.5 | 5.6.29 | 3.4 |
20-
21-
**PLEASE NOTE: PHP7.1 is now the default and support for php5 will be dropped soon**
2213

23-
## Building from source
24-
To build from source you need to clone the git repo and run docker build:
25-
```
26-
git clone https://github.com/ngineered/nginx-php-fpm
27-
.git
28-
docker build -t nginx-php-fpm:latest .
29-
```
14+
### Git repository
15+
The source files for this project can be found here: [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
3016

31-
## Pulling from Docker Hub
17+
If you have any improvements please submit a pull request.
18+
### Docker hub repository
19+
The Docker hub build can be found here: [https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/](https://registry.hub.docker.com/u/richarvey/nginx-php-fpm/)
3220
```
3321
docker pull richarvey/nginx-php-fpm
3422
```
35-
3623
## Running
3724
To simply run the container:
3825
```
3926
sudo docker run -d richarvey/nginx-php-fpm
4027
```
28+
You can then browse to ```http://<DOCKER_HOST>``` to view the default install files. To find your ```DOCKER_HOST``` use the ```docker inspect``` to get the IP address (normally 172.17.0.2)
29+
30+
To pull code from git when running:
31+
```
32+
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' richarvey/nginx-php-fpm:latest
33+
```
4134

42-
You can then browse to ```http://<DOCKER_HOST>``` to view the default install files. To find your ```DOCKER_HOST``` use the ```docker inspect``` to get the IP address.
35+
For more detailed examples and explanations please refer to the documentation.
4336

4437
### Available Configuration Parameters
4538
The following flags are a list of all the currently supported options that can be changed by passing in the variables to docker with the -e flag.
@@ -64,117 +57,18 @@ The following flags are a list of all the currently supported options that can b
6457
- **RUN_SCRIPTS** : Set to 1 to execute scripts
6558
- **PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
6659
- **PUID** : Set to UserID you want to use for nginx (helps permissions when using local volume)
67-
68-
### Dynamically Pulling code from git
69-
One of the nice features of this container is its ability to pull code from a git repository with a couple of environmental variables passed at run time. Please take a look at our recommended [repo layout guidelines](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/repo_layout.md).
70-
71-
There are two methods of pulling code from git, you can either use a Personal Token (recommended method) or an SSH key.
72-
73-
**Note:** We would recommend using a git personal token over an SSH key as it simplifies the set up process. To create a personal access token on Github follow this [guide](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
74-
75-
#### Personal Access token
76-
77-
You can pass the container your personal access token from your git account using the __GIT_PERSONAL_TOKEN__ flag. This token must be setup with the correct permissions in git in order to push and pull code.
78-
79-
Since the access token acts as a password with limited access, the git push/pull uses HTTPS to authenticate. You will need to specify your __GIT_USERNAME__ and __GIT_PERSONAL_TOKEN__ variables to push and pull. You'll need to also have the __GIT_EMAIL__, __GIT_NAME__ and __GIT_REPO__ common variables defined.
80-
81-
```
82-
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' richarvey/nginx-php-fpm:latest
83-
```
84-
85-
To pull a repository and specify a branch add the __GIT_BRANCH__ environment variable:
86-
```
87-
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' -e 'GIT_BRANCH=stage' richarvey/nginx-php-fpm:latest
88-
```
89-
#### SSH keys
90-
91-
##### Preparing your SSH key
92-
The container has the option for you to pass it the __SSH_KEY__ variable with a **base64** encoded **private** key. First generate your key and then make sure to add it to github and give it write permissions if you want to be able to push code from the container. Then run:
93-
```
94-
base64 -w 0 /path_to_your_private_key
95-
```
96-
**Note:** Copy the output, but be careful not to copy your prompt
97-
98-
##### Running with SSH Keys
99-
100-
To run the container and pull code simply specify the GIT_REPO URL including *git@* and then make sure you have also supplied your base64 version of your ssh deploy key:
101-
```
102-
sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm:latest
103-
```
104-
105-
To pull a repository and specify a branch add the GIT_BRANCH environment variable:
106-
```
107-
sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' -e 'GIT_BRANCH=stage' richarvey/nginx-php-fpm:latest
108-
```
109-
110-
### User / Group Identifiers
111-
112-
Sometimes when using data volumes (`-v` flags) permissions issues can arise between the host OS and the container. We avoid this issue by allowing you to specify the user `PUID` and optionally the group `PGID`. Ensure the data volume directory on the host is owned by the same user you specify and it will "just work" ™.
113-
114-
An example of mapping the UID and GID to the container is as follows:
115-
116-
```
117-
docker run -d -e "PUID=`id -u $USER`" -e "PGID=`id -g $USER`" -v local_dir:/var/www/html richarvey/nginx-php-fpm:latest
118-
```
119-
120-
This will pull your local UID/GID and map it into the container so you can edit on your host machine and the code will still run in the container.
121-
122-
### Custom Nginx Config files
123-
Sometimes you need a custom config file for nginx to achieve this read the [Nginx config guide](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/nginx_configs.md)
124-
125-
#### REAL IP / X-Forwarded-For Headers
126-
If you operate your container behind a load balancer, an ELB on AWS for example, you need to configure nginx to get the real IP and not the load balancer IP in the logs by using the X-Forwarded-For. We've provided some handy flags to let you do this. You need to set both of these to get this to work:
127-
```
128-
-e "REAL_IP_HEADER=1"
129-
-e "REAL_IP_FROM=Your_CIDR"
130-
```
131-
For example:
132-
```
133-
docker run -d -e "REAL_IP_HEADER=1" -e "REAL_IP_FROM=10.1.0.0/16" richarvey/nginx-php-fpm:latest
134-
```
135-
136-
### Scripting and Templating
137-
Please see the [Scripting and templating guide](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/scripting_templating.md) for more details.
138-
139-
### Lets Encrypt support
140-
This container includes support to easily manage lets encrypt certificates. Please see the [Lets Encrypt guide](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md) for more details.
141-
142-
### Install PHP Modules
143-
144-
First of all drop into the container:
145-
```
146-
docker exec -t -i nginx /bin/bash
147-
```
148-
Then configure and install your module:
149-
```
150-
/usr/local/bin/docker-php-ext-configure sockets
151-
/usr/local/bin/docker-php-ext-install sockets
152-
```
153-
Now restart php-fpm:
154-
```
155-
supervisorctl restart php-fpm
156-
```
157-
158-
## Special Git Features
159-
Specify the ```GIT_EMAIL``` and ```GIT_NAME``` variables for this to work. They are used to set up git correctly and allow the following commands to work.
160-
161-
### Push code to Git
162-
To push code changes made within the container back to git run:
163-
```
164-
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/push
165-
```
166-
167-
### Pull code from Git (Refresh)
168-
In order to refresh the code in a container and pull newer code from git run:
169-
```
170-
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/pull
171-
```
172-
## Logging and Errors
173-
174-
### Logging
175-
All logs should now print out in stdout/stderr and are available via the docker logs command:
176-
```
177-
docker logs <CONTAINER_NAME>
178-
```
179-
### WebRoot
180-
You can set your webroot in the container to anything you want using the ```WEBROOT``` variable e.g -e "WEBROOT=/var/www/html/public". By default code is checked out into /var/www/html/ so if your git repository does not have code in the root you'll need to use this variable.
60+
## Documentation
61+
62+
- [Building from source](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/building.md)
63+
- [Git Auth](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_auth.md)
64+
- Personal Access token
65+
- SSH Keys
66+
- [Git Commands](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/git_commands.md)
67+
- [Repository layout / webroot](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/repo_layout.md)
68+
- [User / Group Identifiers](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/UID_GID_Mapping.md)
69+
- [Custom Nginx Config files](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/nginx_configs.md)
70+
- REAL IP / X-Forwarded-For Headers
71+
- [Scripting and Templating](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/scripting_templating.md) for more details.
72+
- [Lets Encrypt Support](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/lets_encrypt.md) for more details.
73+
- [PHP Modules](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/php_modules.md)
74+
- [Logging and Errors](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/logs.md)

docs/UID_GID_Mapping.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## User / Group Identifiers
2+
Sometimes when using data volumes (`-v` flags) permissions issues can arise between the host OS and the container. We avoid this issue by allowing you to specify the user `PUID` and optionally the group `PGID`. Ensure the data volume directory on the host is owned by the same user you specify and it will "just work" ™.
3+
4+
An example of mapping the UID and GID to the container is as follows:
5+
```
6+
docker run -d -e "PUID=`id -u $USER`" -e "PGID=`id -g $USER`" -v local_dir:/var/www/html richarvey/nginx-php-fpm:latest
7+
```
8+
This will pull your local UID/GID and map it into the container so you can edit on your host machine and the code will still run in the container.

docs/building.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Building from source
2+
To build from source you need to clone the git repo and run docker build:
3+
```
4+
git clone https://github.com/ngineered/nginx-php-fpm
5+
.git
6+
docker build -t nginx-php-fpm:latest .
7+
```

docs/git_auth.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Git Auth
2+
There are two methods of pulling code from git, you can either use a Personal Token (recommended method) or an SSH key.
3+
4+
**Note:** We would recommend using a git personal token over an SSH key as it simplifies the set up process. To create a personal access token on Github follow this [guide](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
5+
6+
### Personal Access token
7+
8+
You can pass the container your personal access token from your git account using the __GIT_PERSONAL_TOKEN__ flag. This token must be setup with the correct permissions in git in order to push and pull code.
9+
10+
Since the access token acts as a password with limited access, the git push/pull uses HTTPS to authenticate. You will need to specify your __GIT_USERNAME__ and __GIT_PERSONAL_TOKEN__ variables to push and pull. You'll need to also have the __GIT_EMAIL__, __GIT_NAME__ and __GIT_REPO__ common variables defined.
11+
12+
```
13+
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' richarvey/nginx-php-fpm:latest
14+
```
15+
16+
To pull a repository and specify a branch add the __GIT_BRANCH__ environment variable:
17+
```
18+
docker run -d -e 'GIT_EMAIL=email_address' -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'GIT_PERSONAL_TOKEN=<long_token_string_here>' -e 'GIT_BRANCH=stage' richarvey/nginx-php-fpm:latest
19+
```
20+
21+
### SSH keys
22+
23+
#### Preparing your SSH key
24+
The container has the option for you to pass it the __SSH_KEY__ variable with a **base64** encoded **private** key. First generate your key and then make sure to add it to github and give it write permissions if you want to be able to push code from the container. Then run:
25+
```
26+
base64 -w 0 /path_to_your_private_key
27+
```
28+
**Note:** Copy the output, but be careful not to copy your prompt
29+
30+
#### Running with SSH Keys
31+
32+
To run the container and pull code simply specify the GIT_REPO URL including *git@* and then make sure you have also supplied your base64 version of your ssh deploy key:
33+
```
34+
sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' richarvey/nginx-php-fpm:latest
35+
```
36+
37+
To pull a repository and specify a branch add the GIT_BRANCH environment variable:
38+
```
39+
sudo docker run -d -e 'GIT_NAME=full_name' -e 'GIT_USERNAME=git_username' -e 'GIT_REPO=github.com/project' -e 'SSH_KEY=BIG_LONG_BASE64_STRING_GOES_IN_HERE' -e 'GIT_BRANCH=stage' richarvey/nginx-php-fpm:latest

docs/git_commands.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Git Commands
2+
Specify the ```GIT_EMAIL``` and ```GIT_NAME``` variables for this to work. They are used to set up git correctly and allow the following commands to work.
3+
4+
### Push code to Git
5+
To push code changes made within the container back to git run:
6+
```
7+
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/push
8+
```
9+
### Pull code from Git (Refresh)
10+
In order to refresh the code in a container and pull newer code from git run:
11+
```
12+
sudo docker exec -t -i <CONTAINER_NAME> /usr/bin/pull
13+
```

docs/logs.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Logging
2+
All logs should now print out in stdout/stderr and are available via the docker logs command:
3+
```
4+
docker logs <CONTAINER_NAME>
5+
```
6+
All logs should now print out in stdout/stderr and are available via the docker logs command:
7+
```
8+
docker logs <CONTAINER_NAME>
9+
```

docs/nginx_configs.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
## Custom Nginx Config files
22
Sometimes you need a custom config file for nginx to do rewrites or password protection, etc. For this reason we've included the ability to have custom nginx configs pulled directly from your git source. Please have a read of the [repo layout guidelines](repo_layout.md) for more information. Its pretty simple to enable this, all you need to do is include a folder in the root of your repository called ```conf/nginx/``` within this folder you need to include a file called ```nginx-site.conf``` which will contain your default nginx site config. If you wish to have a custom file for SSL you simply include a file called ```nginx-site-ssl.conf``` in the same directory. These files will then be swapped in after you code is cloned.
3+
4+
## REAL IP / X-Forwarded-For Headers
5+
If you operate your container behind a load balancer, an ELB on AWS for example, you need to configure nginx to get the real IP and not the load balancer IP in the logs by using the X-Forwarded-For. We've provided some handy flags to let you do this. You need to set both of these to get this to work:
6+
```
7+
-e "REAL_IP_HEADER=1"
8+
-e "REAL_IP_FROM=Your_CIDR"
9+
```
10+
For example:
11+
```
12+
docker run -d -e "REAL_IP_HEADER=1" -e "REAL_IP_FROM=10.1.0.0/16" richarvey/nginx-php-fpm:latest
13+
```

docs/php_modules.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Install PHP Modules
2+
To install and configure extra PHP modules in this image, first of all drop into the container:
3+
```
4+
docker exec -t -i nginx /bin/bash
5+
```
6+
Then configure and install your module:
7+
```
8+
/usr/local/bin/docker-php-ext-configure sockets
9+
/usr/local/bin/docker-php-ext-install sockets
10+
```
11+
Now restart php-fpm:
12+
```
13+
supervisorctl restart php-fpm
14+
```### Install PHP Modules
15+
16+
First of all drop into the container:
17+
```
18+
docker exec -t -i nginx /bin/bash
19+
```
20+
Then configure and install your module:
21+
```
22+
/usr/local/bin/docker-php-ext-configure sockets
23+
/usr/local/bin/docker-php-ext-install sockets
24+
```
25+
Now restart php-fpm:
26+
```
27+
supervisorctl restart php-fpm
28+
```
29+
30+
We may include a env var to do this in the future.

docs/repo_layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ However if you wish to use scripting support you'll want to split code and scrip
2626
- ......
2727
```
2828

29-
### src
29+
### src / Webroot
3030
If you use an alternative directory for your application root like the previous example of __src/__, you can use the __WEBROOT__ variable to instruct nginx that that is where the code should be served from.
3131

3232
``` docker run -e 'WEBROOT=/var/www/html/src/' -e OTHER_VARS ........ ```

docs/scripting_templating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Scripting
1+
## Scripting
22
There is often an occasion where you need to run a script on code to do a transformation once code lands in the container. For this reason we have developed scripting support. By including a scripts folder in your git repository and passing the __RUN_SCRIPTS=1__ flag to your command line the container will execute your scripts. Please see the [repo layout guidelines](https://github.com/ngineered/nginx-php-fpm/blob/master/docs/repo_layout.md) for more details on how to organise this.
33

44
### Using environment variables / templating

0 commit comments

Comments
 (0)