You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
7
7
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
15
9
| Tag | Nginx | PHP | Alpine |
16
10
|-----|-------|-----|--------|
17
11
| latest | 1.11.9 | 7.1.1 | 3.4 |
18
12
| 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**
22
13
23
-
## Building from source
24
-
To build from source you need to clone the git repo and run docker build:
The source files for this project can be found here: [https://github.com/ngineered/nginx-php-fpm](https://github.com/ngineered/nginx-php-fpm)
30
16
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/)
32
20
```
33
21
docker pull richarvey/nginx-php-fpm
34
22
```
35
-
36
23
## Running
37
24
To simply run the container:
38
25
```
39
26
sudo docker run -d richarvey/nginx-php-fpm
40
27
```
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)
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.
43
36
44
37
### Available Configuration Parameters
45
38
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
64
57
-**RUN_SCRIPTS** : Set to 1 to execute scripts
65
58
-**PGID** : Set to GroupId you want to use for nginx (helps permissions when using local volume)
66
59
-**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.
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:
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:
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:
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)
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:
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.
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:
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:
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
Copy file name to clipboardExpand all lines: docs/repo_layout.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ However if you wish to use scripting support you'll want to split code and scrip
26
26
- ......
27
27
```
28
28
29
-
### src
29
+
### src / Webroot
30
30
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.
31
31
32
32
``` docker run -e 'WEBROOT=/var/www/html/src/' -e OTHER_VARS ........ ```
Copy file name to clipboardExpand all lines: docs/scripting_templating.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
###Scripting
1
+
## Scripting
2
2
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.
0 commit comments