Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9cda0d0

Browse files
committed
Add documentation and examples
1 parent 7fb96f7 commit 9cda0d0

File tree

4 files changed

+91
-43
lines changed

4 files changed

+91
-43
lines changed

‎README.md

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ Or mount your own code to be served by PHP-FPM & Nginx
3939

4040
docker run -p 80:8080 -v ~/my-codebase:/var/www/html trafex/php-nginx
4141

42-
### Docker Hub repository name change
43-
Since we switched to PHP8 the repository name [trafex/alpine-nginx-php7](https://hub.docker.com/r/trafex/alpine-nginx-php7) didn't make sense anymore.
44-
Because you can't change the name of the repository on Docker Hub I created a new one.
45-
46-
From now on this image can be pulled from Docker Hub under the name [trafex/php-nginx](https://hub.docker.com/r/trafex/php-nginx).
47-
4842
## Configuration
4943
In [config/](config/) you'll find the default configuration files for Nginx, PHP and PHP-FPM.
5044
If you want to extend or customize that you can do so by mounting a configuration file in the correct folder;
@@ -59,44 +53,13 @@ PHP configuration:
5953

6054
PHP-FPM configuration:
6155

62-
docker run -v "`pwd`/php-fpm-settings.conf:/etc/php8/php-fpm.d/server.conf" trafex/php-nginx
56+
docker run -v "`pwd`/php-fpm-settings.conf:/etc/php82/php-fpm.d/server.conf" trafex/php-nginx
6357

6458
_Note; Because `-v` requires an absolute path I've added `pwd` in the example to return the absolute path to the current directory_
6559

60+
## Documentation and examples
61+
To modify this container to your specific needs please see the following examples;
6662

67-
## Adding composer
68-
69-
If you need [Composer](https://getcomposer.org/) in your project, here's an easy way to add it.
70-
71-
```Dockerfile
72-
FROM trafex/php-nginx:latest
73-
74-
# Install composer from the official image
75-
COPY --from=composer /usr/bin/composer /usr/bin/composer
76-
77-
# Run composer install to install the dependencies
78-
RUN composer install --optimize-autoloader --no-interaction --no-progress
79-
```
80-
81-
### Building with composer
82-
83-
If you are building an image with source code in it and dependencies managed by composer then the definition can be improved.
84-
The dependencies should be retrieved by the composer but the composer itself (`/usr/bin/composer`) is not necessary to be included in the image.
85-
86-
```Dockerfile
87-
FROM composer AS composer
88-
89-
# copying the source directory and install the dependencies with composer
90-
COPY <your_directory>/ /app
91-
92-
# run composer install to install the dependencies
93-
RUN composer install \
94-
--optimize-autoloader \
95-
--no-interaction \
96-
--no-progress
97-
98-
# continue stage build with the desired image and copy the source including the
99-
# dependencies downloaded by composer
100-
FROM trafex/php-nginx
101-
COPY --chown=nginx --from=composer /app /var/www/html
102-
```
63+
* [Adding xdebug support](docs/xdebug-support.md)
64+
* [Adding composer](docs/composer-support.md)
65+
* [Getting the real IP of the client behind a load balancer](docs/real-ip-behind-loadbalancer.md)

‎docs/composer-support.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Adding composer
2+
3+
If you need [Composer](https://getcomposer.org/) in your project, here's an easy way to add it.
4+
5+
```Dockerfile
6+
FROM trafex/php-nginx:latest
7+
8+
# Install composer from the official image
9+
COPY --from=composer /usr/bin/composer /usr/bin/composer
10+
11+
# Run composer install to install the dependencies
12+
RUN composer install --optimize-autoloader --no-interaction --no-progress
13+
```
14+
15+
## Building with composer
16+
17+
If you are building an image with source code in it and dependencies managed by composer then the definition can be improved.
18+
The dependencies should be retrieved by the composer but the composer itself (`/usr/bin/composer`) is not necessary to be included in the image.
19+
20+
```Dockerfile
21+
FROM composer AS composer
22+
23+
# Copying the source directory and install the dependencies with composer
24+
COPY <your_directory>/ /app
25+
26+
# Run composer install to install the dependencies
27+
RUN composer install \
28+
--optimize-autoloader \
29+
--no-interaction \
30+
--no-progress
31+
32+
# Continue stage build with the desired image and copy the source including the dependencies downloaded by composer
33+
FROM trafex/php-nginx:latest
34+
COPY --chown=nginx --from=composer /app /var/www/html
35+
```

‎docs/real-ip-behind-loadbalancer.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Getting the real IP of the client behind a load balancer
2+
If you use this container behind a proxy or load balancer you might want to get the real IP of the client instead of the IP of the proxy or load balancer.
3+
4+
To do this you can add the following configuration to the [Nginx configuration](../config/nginx.conf):
5+
6+
```nginx
7+
set_real_ip_from <CIDR>
8+
9+
real_ip_header X-Forwarded-For;
10+
real_ip_recursive on;
11+
```
12+
13+
Where `<CIDR>` is the CIDR of your proxy or load balancer, see the [Nginx documentation](http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from). The real IP of the client will now be available in PHP under `$_SERVER['REMOTE_ADDR']`.

‎docs/xdebug-support.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Adding xdebug support
2+
3+
Create the following file `xdebug.ini`
4+
5+
```ini
6+
zend_extension=xdebug.so
7+
xdebug.mode=develop,debug
8+
xdebug.discover_client_host=true
9+
xdebug.start_with_request=yes
10+
xdebug.trigger_value=PHPSTORM
11+
xdebug.log_level=0
12+
13+
xdebug.var_display_max_children=10
14+
xdebug.var_display_max_data=10
15+
xdebug.var_display_max_depth=10
16+
17+
xdebug.client_host=host.docker.internal
18+
xdebug.client_port=9003
19+
```
20+
21+
Create a new image with the following `Dockerfile`
22+
23+
```Dockerfile
24+
FROM trafex/php-nginx:latest
25+
26+
# Temporary switch to root
27+
USER root
28+
29+
# Install xdebug
30+
RUN apk add --no-cache php82-pecl-xdebug
31+
32+
# Add configuration
33+
COPY xdebug.ini ${PHP_INI_DIR}/conf.d/xdebug.ini
34+
35+
# Switch back to non-root user
36+
USER nobody
37+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /