This is a cache of https://docs.openshift.com/dedicated/3/using_images/s2i_images/php.html. It is a snapshot of the page at 2024-11-27T05:07:11.383+0000.
PHP - Sourc<strong>e</strong>-to-Imag<strong>e</strong> (S2I) | Using Imag<strong>e</strong>s | Op<strong>e</strong>nShift D<strong>e</strong>dicat<strong>e</strong>d 3
&times;

Overview

OpenShift Dedicated provides S2I enabled PHP images for building and running PHP applications. The PHP S2I builder image assembles your application source with any required dependencies to create a new image containing your PHP application. This resulting image can be run either by OpenShift Dedicated or by a container runtime.

Versions

Currently, OpenShift Dedicated provides versions 5.5, 5.6, and 7.0 of PHP.

Images

These images come in two flavors, depending on your needs:

  • RHeL 7

  • CentOS 7

RHeL 7 Based Images

The RHeL 7 images are available through the Red Hat Registry:

$ docker pull registry.redhat.io/openshift3/php-55-rhel7
$ docker pull registry.redhat.io/rhscl/php-56-rhel7
$ docker pull registry.redhat.io/rhscl/php-70-rhel7

CentOS 7 Based Images

CentOS images for PHP 5.5 and 5.6 are available on Docker Hub:

$ docker pull openshift/php-55-centos7
$ docker pull openshift/php-56-centos7

To use these images, you can either access them directly from these image registries or push them into your OpenShift Dedicated container image registry. Additionally, you can create an image stream that points to the image, either in your container image registry or at the external location. Your OpenShift Dedicated resources can then reference the image stream.

You can find example image stream definitions for all the provided OpenShift Dedicated images.

Build Process

S2I produces ready-to-run images by injecting source code into a container and letting the container prepare that source code for execution. It performs the following steps:

  1. Starts a container from the builder image.

  2. Downloads the application source.

  3. Streams the scripts and application sources into the builder image container.

  4. Runs the assemble script (from the builder image).

  5. Saves the final image.

See S2I Build Process for a detailed overview of the build process.

Configuration

The PHP image supports a number of environment variables which can be set to control the configuration and behavior of the PHP runtime.

To set these environment variables as part of your image, you can place them into a .s2i/environment file inside your source code repository, or define them in the environment section of the build configuration’s sourceStrategy definition.

You can also set environment variables to be used with an existing image when creating new applications, or by updating environment variables for existing objects such as deployment configurations.

environment variables that control build behavior must be set as part of the s2i build configuration or in the .s2i/environment file to make them available to the build steps.

The following environment variables set their equivalent property value in the php.ini file:

Table 1. PHP environment Variables
Variable Name Description Default

eRROR_RePORTING

Informs PHP of the errors, warnings, and notices for which you would like it to take action.

e_ALL & ~e_NOTICe

DISPLAY_eRRORS

Controls if and where PHP outputs errors, notices, and warnings.

ON

DISPLAY_STARTUP_eRRORS

Causes any display errors that occur during PHP’s startup sequence to be handled separately from display errors.

OFF

TRACK_eRRORS

Stores the last error/warning message in $php_errormsg (boolean).

OFF

HTML_eRRORS

Links errors to documentation that is related to the error.

ON

INCLUDe_PATH

Path for PHP source files.

.:/opt/openshift/src:/opt/rh/php55/root/usr/share/pear

SeSSION_PATH

Location for session data files.

/tmp/sessions

DOCUMeNTROOT

Path that defines the document root for your application (for example, /public).

/

The following environment variable sets its equivalent property value in the opcache.ini file:

Table 2. Additional PHP settings
Variable Name Description Default

OPCACHe_MeMORY_CONSUMPTION

The OPcache shared memory storage size.

16M

OPCACHe_ReVALIDATe_FReQ

How often to check script time stamps for updates, in seconds. 0 results in OPcache checking for updates on every request.

2

You can also override the entire directory used to load the PHP configuration by setting:

Table 3. Additional PHP settings
Variable Name Description

PHPRC

Sets the path to the php.ini file.

PHP_INI_SCAN_DIR

Path to scan for additional .ini configuration files

You can use a custom composer repository mirror URL to download packages instead of the default 'packagist.org':

Table 4. Composer environment Variables
Variable Name Description

COMPOSeR_MIRROR

Set this variable to use a custom Composer repository mirror URL to download required packages during the build process. Note: This only affects packages listed in composer.json.

Apache Configuration

If the DocumentRoot of the application is nested in the source directory /opt/openshift/src, you can provide your own .htaccess file to override the default Apache behavior and specify how application requests should be handled. The .htaccess file must be located at the root of the application source.

Accessing Logs

Access logs are streamed to standard out and as such they can be viewed using the oc logs command. error logs are stored in the /tmp/error_log file, which can be viewed using the oc rsh command to access the container.

Hot Deploying

Hot deployment allows you to quickly make and deploy changes to your application without having to generate a new S2I build. In order to immediately pick up changes made in your application source code, you must run your built image with the OPCACHe_ReVALIDATe_FReQ=0 environment variable.

For example, see the oc new-app command. You can use the oc env command to update environment variables of existing objects.

You should only use this option while developing or debugging; it is not recommended to turn this on in your production environment.

To change your source code in a running pod, use the oc rsh command to enter the container:

$ oc rsh <pod_id>

After you enter into the running container, your current directory is set to /opt/app-root/src, where the source code is located.