|
1 | 1 | PHP 8.1 container image
|
2 | 2 | =======================
|
3 | 3 |
|
4 |
| -This container image includes PHP 8.1 as a [S2I](https://github.com/openshift/source-to-image) base image for your PHP 8.1 applications. |
5 |
| -Users can choose between RHEL and CentOS Stream based builder images. |
6 |
| -The RHEL UBI images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), |
7 |
| -the CentOS Stream images are available on [Quay.io](https://quay.io/organization/sclorg), |
8 |
| -and the Fedora images are available in [Quay.io](https://quay.io/organization/fedora). |
9 |
| -The resulting image can be run using [podman](https://github.com/containers/libpod). |
10 |
| - |
11 |
| -Note: while the examples in this README are calling `podman`, you can replace any such calls by `docker` with the same arguments |
12 |
| - |
13 |
| -Description |
14 |
| ------------ |
15 |
| - |
16 |
| -PHP 8.1 available as container is a base platform for |
17 |
| -building and running various PHP 8.1 applications and frameworks. |
18 |
| -PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers |
19 |
| -to write dynamically generated web pages. PHP also offers built-in database integration |
20 |
| -for several commercial and non-commercial database management systems, so writing |
21 |
| -a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding |
22 |
| -is probably as a replacement for CGI scripts. |
23 |
| - |
24 |
| -This container image includes an npm utility, so users can use it to install JavaScript |
25 |
| -modules for their web applications. There is no guarantee for any specific npm or nodejs |
26 |
| -version, that is included in the image; those versions can be changed anytime and |
27 |
| -the nodejs itself is included just to make the npm work. |
28 |
| - |
29 |
| -Usage in OpenShift |
30 |
| ------------------- |
31 |
| -In this example, we will assume that you are using the `ubi8/php-81` image, available via `php:8.1` imagestream tag in Openshift. |
32 |
| - |
33 |
| -To build a simple [cakephp-sample-app](https://github.com/sclorg/cakephp-ex.git) application in Openshift: |
34 |
| - |
35 |
| -``` |
36 |
| -oc new-app php:8.1~https://github.com/sclorg/cakephp-ex.git |
37 |
| -``` |
38 |
| - |
39 |
| -To access the application: |
40 |
| -``` |
41 |
| -$ oc get pods |
42 |
| -$ oc exec <pod> -- curl 127.0.0.1:8080 |
43 |
| -``` |
44 |
| - |
45 |
| -**Accessing the application:** |
46 |
| -``` |
47 |
| -$ curl 127.0.0.1:8080 |
48 |
| -``` |
49 |
| - |
50 |
| -Source-to-Image framework and scripts |
51 |
| -------------------------------------- |
52 |
| -This image supports the [Source-to-Image](https://docs.openshift.com/container-platform/4.14/openshift_images/create-images.html#images-create-s2i_create-images) |
53 |
| -(S2I) strategy in OpenShift. The Source-to-Image is an OpenShift framework |
54 |
| -which makes it easy to write images that take application source code as |
55 |
| -an input, use a builder image like this PHP container image, and produce |
56 |
| -a new image that runs the assembled application as an output. |
57 |
| - |
58 |
| -To support the Source-to-Image framework, important scripts are included in the builder image: |
59 |
| - |
60 |
| -* The `/usr/libexec/s2i/assemble` script inside the image is run to produce a new image with the application artifacts. The script takes sources of a given application and places them into appropriate directories inside the image. It utilizes some common patterns in PHP application development (see the **Environment variables** section below). |
61 |
| -* The `/usr/libexec/s2i/run` script is set as the default command in the resulting container image (the new image with the application artifacts). It runs `httpd` with PHP support enabled. |
62 |
| - |
63 |
| -Building an application using a Dockerfile |
64 |
| ------------------------------------------- |
65 |
| -Compared to the Source-to-Image strategy, using a Dockerfile is a more |
66 |
| -flexible way to build a PHP container image with an application. |
67 |
| -Use a Dockerfile when Source-to-Image is not sufficiently flexible for you or |
68 |
| -when you build the image outside of the OpenShift environment. |
69 |
| - |
70 |
| -To use the PHP image in a Dockerfile, follow these steps: |
71 |
| - |
72 |
| -#### 1. Pull a base builder image to build on |
73 |
| - |
74 |
| -``` |
75 |
| -podman pull ubi8/php-81 |
76 |
| -``` |
77 |
| - |
78 |
| -An UBI image `ubi8/php-81` is used in this example. This image is usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). |
79 |
| - |
80 |
| -#### 2. Pull an application code |
81 |
| - |
82 |
| -An example application available at https://github.com/sclorg/cakephp-ex.git is used here. Feel free to clone the repository for further experiments. |
83 |
| - |
84 |
| -``` |
85 |
| -git clone https://github.com/sclorg/cakephp-ex.git app-src |
86 |
| -``` |
87 |
| - |
88 |
| -#### 3. Prepare an application inside a container |
89 |
| - |
90 |
| -This step usually consists of at least these parts: |
91 |
| - |
92 |
| -* putting the application source into the container |
93 |
| -* installing the dependencies |
94 |
| -* setting the default command in the resulting image |
95 |
| - |
96 |
| -For all these three parts, users can either setup all manually and use commands `./composer.phar` or other commands explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users can use the Source-to-Image scripts inside the image ([3.2.](#32-to-use-the-source-to-image-scripts-and-build-an-image-using-a-dockerfile-create-a-dockerfile-with-this-content); see more about these scripts in the section "Source-to-Image framework and scripts" above), that already know how to set-up and run some common PHP applications. |
97 |
| - |
98 |
| -##### 3.1. To use your own setup, create a Dockerfile with this content: |
99 |
| -``` |
100 |
| -FROM ubi8/php-81 |
101 |
| -
|
102 |
| -# Add application sources |
103 |
| -ADD app-src . |
104 |
| -
|
105 |
| -# Install the dependencies |
106 |
| -RUN TEMPFILE=$(mktemp) && \ |
107 |
| - curl -o "$TEMPFILE" "https://getcomposer.org/installer" && \ |
108 |
| - php <"$TEMPFILE" && \ |
109 |
| - ./composer.phar install --no-interaction --no-ansi --optimize-autoloader |
110 |
| -
|
111 |
| -# Run script uses standard ways to configure the PHP application |
112 |
| -# and execs httpd -D FOREGROUND at the end |
113 |
| -# See more in <version>/s2i/bin/run in this repository. |
114 |
| -# Shortly what the run script does: The httpd daemon and php needs to be |
115 |
| -# configured, so this script prepares the configuration based on the container |
116 |
| -# parameters (e.g. available memory) and puts the configuration files into |
117 |
| -# the approriate places. |
118 |
| -# This can obviously be done differently, and in that case, the final CMD |
119 |
| -# should be set to "CMD httpd -D FOREGROUND" instead. |
120 |
| -CMD /usr/libexec/s2i/run |
121 |
| -
|
122 |
| -``` |
123 |
| - |
124 |
| -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: |
125 |
| -``` |
126 |
| -FROM ubi8/php-81 |
127 |
| -
|
128 |
| -# Add application sources to a directory that the assemble script expects them |
129 |
| -# and set permissions so that the container runs without root access |
130 |
| -USER 0 |
131 |
| -ADD app-src /tmp/src |
132 |
| -RUN chown -R 1001:0 /tmp/src |
133 |
| -USER 1001 |
134 |
| -
|
135 |
| -# Install the dependencies |
136 |
| -RUN /usr/libexec/s2i/assemble |
137 |
| -
|
138 |
| -# Set the default command for the resulting image |
139 |
| -CMD /usr/libexec/s2i/run |
140 |
| -``` |
141 |
| - |
142 |
| -#### 4. Build a new image from a Dockerfile prepared in the previous step |
143 |
| - |
144 |
| -``` |
145 |
| -podman build -t cakephp-app . |
146 |
| -``` |
147 |
| - |
148 |
| -#### 5. Run the resulting image with the final application |
149 |
| - |
150 |
| -``` |
151 |
| -podman run -d cakephp-app |
152 |
| -``` |
153 |
| - |
154 |
| -Environment variables for Source-to-Image |
155 |
| ------------------------------------------ |
156 |
| - |
157 |
| -To set these environment variables, you can place them as a key value pair into a `.s2i/environment` |
158 |
| -file inside your source code repository. |
159 |
| - |
160 |
| -The following environment variables set their equivalent property value in the php.ini file: |
161 |
| -* **ERROR_REPORTING** |
162 |
| - * Informs PHP of which errors, warnings and notices you would like it to take action for |
163 |
| - * Default: E_ALL & ~E_NOTICE |
164 |
| -* **DISPLAY_ERRORS** |
165 |
| - * Controls whether or not and where PHP will output errors, notices and warnings |
166 |
| - * Default: ON |
167 |
| -* **DISPLAY_STARTUP_ERRORS** |
168 |
| - * Cause display errors which occur during PHP's startup sequence to be handled separately from display errors |
169 |
| - * Default: OFF |
170 |
| -* **HTML_ERRORS** |
171 |
| - * Link errors to documentation related to the error |
172 |
| - * Default: ON |
173 |
| -* **INCLUDE_PATH** |
174 |
| - * Path for PHP source files |
175 |
| - * Default: .:/opt/app-root/src:/opt/rh/rh-php81/root/usr/share/pear (EL7) |
176 |
| - * Default: .:/opt/app-root/src:/usr/share/pear (EL8, Fedora) |
177 |
| -* **PHP_MEMORY_LIMIT** |
178 |
| - * Memory Limit |
179 |
| - * Default: 128M |
180 |
| -* **PHP_CLEAR_ENV** |
181 |
| - * Sets to clear environment in FPM workers. See [FPM_CONFIGURATION](https://www.php.net/manual/en/install.fpm.configuration.php). |
182 |
| - * Default: ON |
183 |
| -* **SESSION_NAME** |
184 |
| - * Name of the session |
185 |
| - * Default: PHPSESSID |
186 |
| -* **SESSION_HANDLER** |
187 |
| - * Method for saving sessions |
188 |
| - * Default: files |
189 |
| -* **SESSION_PATH** |
190 |
| - * Location for session data files |
191 |
| - * Default: /tmp/sessions |
192 |
| -* **SESSION_COOKIE_DOMAIN** |
193 |
| - * The domain for which the cookie is valid. |
194 |
| - * Default: |
195 |
| -* **SESSION_COOKIE_HTTPONLY** |
196 |
| - * Whether or not to add the httpOnly flag to the cookie |
197 |
| - * Default: 0 |
198 |
| -* **SESSION_COOKIE_SECURE** |
199 |
| - * Specifies whether cookies should only be sent over secure connections. |
200 |
| - * Default: Off |
201 |
| -* **SHORT_OPEN_TAG** |
202 |
| - * Determines whether or not PHP will recognize code between <? and ?> tags |
203 |
| - * Default: OFF |
204 |
| -* **DOCUMENTROOT** |
205 |
| - * Path that defines the DocumentRoot for your application (ie. /public) |
206 |
| - * Default: / |
207 |
| - |
208 |
| -The following environment variables set their equivalent property value in the opcache.ini file: |
209 |
| -* **OPCACHE_MEMORY_CONSUMPTION** |
210 |
| - * The OPcache shared memory storage size in megabytes |
211 |
| - * Default: 128 |
212 |
| -* **OPCACHE_REVALIDATE_FREQ** |
213 |
| - * How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request. |
214 |
| - * Default: 2 |
215 |
| -* **OPCACHE_MAX_FILES** |
216 |
| - * The maximum number of keys (scripts) in the OPcache hash table. Only numbers between 200 and 1000000 are allowed. |
217 |
| - * Default: 4000 |
218 |
| - |
219 |
| -You can also override the entire directory used to load the PHP configuration by setting: |
220 |
| -* **PHPRC** |
221 |
| - * Sets the path to the php.ini file |
222 |
| -* **PHP_INI_SCAN_DIR** |
223 |
| - * Path to scan for additional ini configuration files |
224 |
| - |
225 |
| -You can override the Apache [MPM prefork](https://httpd.apache.org/docs/2.4/mod/mpm_common.html) |
226 |
| -settings to increase the performance for of the PHP application. In case you set |
227 |
| -some Cgroup limits, the image will attempt to automatically set the |
228 |
| -optimal values. You can override this at any time by specifying the values |
229 |
| -yourself: |
230 |
| - |
231 |
| -* **HTTPD_START_SERVERS** |
232 |
| - * The [StartServers](https://httpd.apache.org/docs/2.4/mod/mpm_common.html#startservers) |
233 |
| - directive sets the number of child server processes created on startup. |
234 |
| - * Default: 8 |
235 |
| -* **HTTPD_MAX_REQUEST_WORKERS** |
236 |
| - * The [MaxRequestWorkers](https://httpd.apache.org/docs/2.4/mod/mpm_common.html#maxrequestworkers) |
237 |
| - directive sets the limit on the number of simultaneous requests that will be served. |
238 |
| - * `MaxRequestWorkers` was called `MaxClients` before version httpd 2.3.13. |
239 |
| - * Default: 256 (this is automatically tuned by setting Cgroup limits for the container using this formula: |
240 |
| - `TOTAL_MEMORY / 15MB`. The 15MB is average size of a single httpd process. |
241 |
| -* **HTTPD_MAX_REQUESTS_PER_CHILD** |
242 |
| - * The [MaxRequestsPerChild](http://httpd.apache.org/docs/current/mod/mpm_common.html#maxconnectionsperchild) |
243 |
| - directive sets the limit on the number of connections that an individual child server process will handle. |
244 |
| - After `MaxRequestsPerChild` connections, the child process will die. If `MaxRequestsPerChild` is 0, then the process will never expire. |
245 |
| - * Setting `MaxRequestsPerChild` to a non-zero value limits the amount of memory that a process can consume by (accidental) memory leakage. |
246 |
| - * `MaxRequestsPerChild` is called `MaxConnectionsPerChild` in Apache HTTP 2.3.9 and later. |
247 |
| - * Default: 4000 |
248 |
| -* **HTTPD_MAX_KEEPALIVE_REQUESTS** |
249 |
| - * The [MaxKeepAliveRequests](http://httpd.apache.org/docs/current/mod/core.html#maxkeepaliverequests) |
250 |
| - directive limits the number of requests allowed per connection when `KeepAlive` is on. If it is set to 0, unlimited requests will be allowed. |
251 |
| - * Default: 100 |
252 |
| - |
253 |
| - You can use a custom composer repository mirror URL to download packages instead of the default 'packagist.org': |
254 |
| - |
255 |
| - * **COMPOSER_MIRROR** |
256 |
| - * Adds a custom composer repository mirror URL to composer configuration. Note: This only affects packages listed in composer.json. |
257 |
| - * **COMPOSER_INSTALLER** |
258 |
| - * Overrides the default URL for downloading Composer of https://getcomposer.org/installer. Useful in disconnected environments. |
259 |
| - * **COMPOSER_VERSION** |
260 |
| - * Overrides the default composer version to install (1, 2, preview, snapshot or version="x.y.z") |
261 |
| - * **COMPOSER_ARGS** |
262 |
| - * Adds extra arguments to the `composer install` command line (for example `--no-dev`). |
263 |
| - |
264 |
| - |
265 |
| -Source repository layout |
266 |
| ------------------------- |
267 |
| - |
268 |
| -You do not need to change anything in your existing PHP project's repository. |
269 |
| -However, if these files exist they will affect the behavior of the build process: |
270 |
| - |
271 |
| -* **composer.json** |
272 |
| - |
273 |
| - List of dependencies to be installed with `composer`. The format is documented |
274 |
| - [here](https://getcomposer.org/doc/04-schema.md). |
275 |
| - |
276 |
| - |
277 |
| -* **.htaccess** |
278 |
| - |
279 |
| - In case the **DocumentRoot** of the application is nested within the source directory `/opt/app-root/src`, |
280 |
| - users can provide their own Apache **.htaccess** file. This allows the overriding of Apache's behavior and |
281 |
| - specifies how application requests should be handled. The **.htaccess** file needs to be located at the root |
282 |
| - of the application source. |
283 |
| - |
284 |
| -Hot deploy |
285 |
| ----------- |
286 |
| - |
287 |
| -In order to immediately pick up changes made in your application source code, you need to run your built image with the `OPCACHE_REVALIDATE_FREQ=0` environment variable passed to [Podman](https://github.com/containers/libpod) `-e` run flag: |
288 |
| - |
289 |
| -``` |
290 |
| -$ podman run -e OPCACHE_REVALIDATE_FREQ=0 -p 8080:8080 php-app |
291 |
| -``` |
292 |
| - |
293 |
| -To change your source code in running container, use Podman's [exec](https://github.com/containers/libpod)) command: |
294 |
| -``` |
295 |
| -podman exec -it <CONTAINER_ID> /bin/bash |
296 |
| -``` |
297 |
| - |
298 |
| -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set |
299 |
| -to `/opt/app-root/src`, where the source code is located. |
300 |
| - |
301 |
| - |
302 |
| -Extending image |
303 |
| ---------------- |
304 |
| -Not only content, but also startup scripts and configuration of the image can |
305 |
| -be extended using [source-to-image](https://github.com/openshift/source-to-image). |
306 |
| - |
307 |
| -The structure of the application can look like this: |
308 |
| - |
309 |
| -| Folder name | Description | |
310 |
| -|-------------------|----------------------------| |
311 |
| -| `./httpd-cfg` | Can contain additional Apache configuration files (`*.conf`)| |
312 |
| -| `./httpd-ssl` | Can contain own SSL certificate (in `certs/` subdirectory) and key (in `private/` subdirectory)| |
313 |
| -| `./php-pre-start`| Can contain shell scripts (`*.sh`) that are sourced before `httpd` is started| |
314 |
| -| `./php-post-assemble`| Can contain shell scripts (`*.sh`) that are sourced at the end of `assemble` script| |
315 |
| -| `./` | Application source code | |
316 |
| - |
317 |
| - |
318 |
| -See also |
319 |
| --------- |
320 |
| -Dockerfile and other sources are available on https://github.com/sclorg/s2i-php-container. |
321 |
| -In that repository you also can find another versions of Python environment Dockerfiles. |
322 |
| -Dockerfile for RHEL8 is called `Dockerfile.rhel8`, Dockerfile for RHEL9 is called `Dockerfile.rhel9` and the Fedora Dockerfile is called Dockerfile.fedora. |
323 |
| - |
324 |
| -Security Implications |
325 |
| ---------------------- |
326 |
| - |
327 |
| --p 8080:8080 |
328 |
| - |
329 |
| - Opens container port 8080 and maps it to the same port on the Host. |
| 4 | +**The PHP 8.1 image is deprecated.** |
0 commit comments