|
| 1 | +# PHP-Apache Debian 13 (Trixie) |
| 2 | + |
| 3 | +This is an Apache and php-fpm image: |
| 4 | + |
| 5 | +- Base: Debian 13 (Trixie) |
| 6 | +- Apache httpd: 2.4 |
| 7 | +- PHP: 8.4 |
| 8 | + |
| 9 | +This image is designed to be quite configurable and as such is good for getting |
| 10 | +started but probably not a great base if you want a highly optimised container. |
| 11 | +This image also expects to be used behind a load balancer and as such does not |
| 12 | +listen on port 80 but instead port 8000. Also make note of how to handle SSL |
| 13 | +offloading to the load balancer and how this affects .htaccess rules. |
| 14 | + |
| 15 | +Note: Unlike the other images this does not provide php-imap due to Debian packaging issues. |
| 16 | + |
| 17 | +## Options: |
| 18 | + |
| 19 | +All options are optional. |
| 20 | +The values shown here are the defaults. The options listed here are also case sensitive. |
| 21 | + |
| 22 | +### Global |
| 23 | + |
| 24 | +``` |
| 25 | +timeout = 30 |
| 26 | +TZ = UTC |
| 27 | +``` |
| 28 | + |
| 29 | +### HTTPD |
| 30 | + |
| 31 | +``` |
| 32 | +httpd_remoteipheader = X-Forwarded-For |
| 33 | +httpd_remoteipinternalproxy = (unset) |
| 34 | +
|
| 35 | +# Subdirectory within the git repository that contains the site root eg 'www' |
| 36 | +httpd_root = (unset) |
| 37 | +
|
| 38 | +# If unset the following is used |
| 39 | +RemoteIPInternalProxy 10.0.0.0/8 |
| 40 | +RemoteIPInternalProxy 172.16.0.0/12 |
| 41 | +RemoteIPInternalProxy 192.168.0.0/16 |
| 42 | +``` |
| 43 | + |
| 44 | +### PHP/PHP-FPM |
| 45 | + |
| 46 | +``` |
| 47 | +phpopts_ = (unset) |
| 48 | +
|
| 49 | +# phpopts Examples |
| 50 | +phpopts_short_open_tag = off |
| 51 | +phpopts_post_max_size = 8M |
| 52 | +phpopts_upload_max_filesize = 2M |
| 53 | +phpopts_memory_limit = 128M |
| 54 | +
|
| 55 | +# PHP Cache options |
| 56 | +php_cache = (opcache|none) default is opcache, none doesn't load any cache extensions. |
| 57 | +php_apc_shm_size = 64M # This is for the apcu extension |
| 58 | +php_opcache_memory_consumption = 128 |
| 59 | +php_opcache_revalidate_freq = 2 |
| 60 | +
|
| 61 | +# PHP Session options |
| 62 | +php_session_save_handler = (unset) |
| 63 | +php_session_save_path = (unset) |
| 64 | +
|
| 65 | +# PHP Session examples |
| 66 | +php_session_save_handler = redis |
| 67 | +php_session_save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2" |
| 68 | +
|
| 69 | +php_session_save_handler = memcached |
| 70 | +php_session_save_path = "host:11211" |
| 71 | +
|
| 72 | +# PHP-FPM options |
| 73 | +phpfpm_pm_max_children = 3 |
| 74 | +phpfpm_pm_max_requests = 500 |
| 75 | +``` |
| 76 | + |
| 77 | +### Email/msmtp |
| 78 | + |
| 79 | +msmtp expects a from address to be set either via environment variable (`msmtp_from`) or |
| 80 | +in the php mail() function. eg. `mail('nobody@example.com', 'the subject', |
| 81 | +'the message', null, '-fwebmaster@example.com');` |
| 82 | + |
| 83 | +msmtp also need a host to send email via, it does not queue and forward mail |
| 84 | +like postfix or exim. This could be defined via a docker link `--link |
| 85 | +smtp:smtp` |
| 86 | + |
| 87 | +``` |
| 88 | +msmtp_host = SMTP_PORT_25_TCP_ADDR or mail |
| 89 | +msmtp_port = SMTP_PORT_25_TCP_PORT or 25 |
| 90 | +msmtp_from = (unset) |
| 91 | +msmtp_user = (unset) |
| 92 | +msmtp_pass = (unset) |
| 93 | +``` |
| 94 | + |
| 95 | +## PHP Pre Execution |
| 96 | + |
| 97 | +PHP pre-execution helpers are included in this image. See |
| 98 | +[PHP Extras](https://github.com/panubo/php-extras) for more information. |
| 99 | + |
| 100 | +Set `auto_prepend_file=xxxx_prepend.php` to enable. |
| 101 | + |
| 102 | +## SSL Offloading |
| 103 | + |
| 104 | +This container should be used behind a load balancing reverse proxy and as such |
| 105 | +SSL should be offloaded to the load balancer. However, this can cause issues |
| 106 | +when your applications want to know if they are being served over SSL as the |
| 107 | +local webserver cannot determine this. Below are workarounds for the two most common |
| 108 | +issues. |
| 109 | + |
| 110 | +If you want to redirect users from a non-ssl connection to a SSL connection with |
| 111 | +htaccess and mod_rewrite the following rules work both behind an SSL offloading |
| 112 | +load balancer and also when the local webserver is handling the SSL. |
| 113 | + |
| 114 | +``` |
| 115 | +<IfModule mod_rewrite.c> |
| 116 | + RewriteEngine on |
| 117 | + RewriteCond %{HTTP:X-Forwarded-Proto} !=https |
| 118 | + RewriteCond %{HTTPS} !=on |
| 119 | + RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R=301,L] |
| 120 | +</IfModule> |
| 121 | +``` |
| 122 | + |
| 123 | +Some PHP application also check they are running on an SSL connection. As the |
| 124 | +local webserver doesn't set $_SERVER['HTTPS'] correctly when behind a proxy the |
| 125 | +following code can be used to fix the issue. |
| 126 | + |
| 127 | +```php |
| 128 | +/* Set _SERVER['HTTPS'] correctly when behind a proxy setting HTTP_X_FORWARDED_PROTO */ |
| 129 | +if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { |
| 130 | + $_SERVER['HTTPS'] = 'on'; |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +or set `auto_prepend_file=SSLHelper_prepend.php` to use the SSL Helper from the [PHP Extras](https://github.com/panubo/php-extras) repo. |
0 commit comments