Add documentation and examples

This commit is contained in:
Tim de Pater
2023-08-27 11:55:30 +02:00
parent 7fb96f7ee7
commit 9cda0d06f4
4 changed files with 91 additions and 43 deletions
+35
View File
@@ -0,0 +1,35 @@
# Adding composer
If you need [Composer](https://getcomposer.org/) in your project, here's an easy way to add it.
```Dockerfile
FROM trafex/php-nginx:latest
# Install composer from the official image
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Run composer install to install the dependencies
RUN composer install --optimize-autoloader --no-interaction --no-progress
```
## Building with composer
If you are building an image with source code in it and dependencies managed by composer then the definition can be improved.
The dependencies should be retrieved by the composer but the composer itself (`/usr/bin/composer`) is not necessary to be included in the image.
```Dockerfile
FROM composer AS composer
# Copying the source directory and install the dependencies with composer
COPY <your_directory>/ /app
# Run composer install to install the dependencies
RUN composer install \
--optimize-autoloader \
--no-interaction \
--no-progress
# Continue stage build with the desired image and copy the source including the dependencies downloaded by composer
FROM trafex/php-nginx:latest
COPY --chown=nginx --from=composer /app /var/www/html
```
+13
View File
@@ -0,0 +1,13 @@
# Getting the real IP of the client behind a load balancer
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.
To do this you can add the following configuration to the [Nginx configuration](../config/nginx.conf):
```nginx
set_real_ip_from <CIDR>
real_ip_header X-Forwarded-For;
real_ip_recursive on;
```
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']`.
+37
View File
@@ -0,0 +1,37 @@
# Adding xdebug support
Create the following file `xdebug.ini`
```ini
zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.discover_client_host=true
xdebug.start_with_request=yes
xdebug.trigger_value=PHPSTORM
xdebug.log_level=0
xdebug.var_display_max_children=10
xdebug.var_display_max_data=10
xdebug.var_display_max_depth=10
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
```
Create a new image with the following `Dockerfile`
```Dockerfile
FROM trafex/php-nginx:latest
# Temporary switch to root
USER root
# Install xdebug
RUN apk add --no-cache php82-pecl-xdebug
# Add configuration
COPY xdebug.ini ${PHP_INI_DIR}/conf.d/xdebug.ini
# Switch back to non-root user
USER nobody
```