php/root/help.1
2018-11-05 16:09:13 +00:00

294 lines
9.2 KiB
Groff

.TH PHP 7.1 Docker image
.PP
This container image includes PHP 7.1 as a S2I
\[la]https://github.com/openshift/source-to-image\[ra] base image for your PHP 7.1 applications.
Users can choose between RHEL and CentOS based builder images.
The RHEL image is available in the Red Hat Container Catalog
\[la]https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/php-71-rhel7\[ra]
as registry.access.redhat.com/rhscl/php\-71\-rhel7.
The CentOS image is then available on Docker Hub
\[la]https://hub.docker.com/r/centos/php-71-centos7/\[ra]
as centos/php\-71\-centos7.
The resulting image can be run using Docker
\[la]http://docker.io\[ra]\&.
.SH Description
.PP
PHP 7.1 available as container is a base platform for
building and running various PHP 7.1 applications and frameworks.
PHP is an HTML\-embedded scripting language. PHP attempts to make it easy for developers
to write dynamically generated web pages. PHP also offers built\-in database integration
for several commercial and non\-commercial database management systems, so writing
a database\-enabled webpage with PHP is fairly simple. The most common use of PHP coding
is probably as a replacement for CGI scripts.
.PP
This container image includes an npm utility, so users can use it to install JavaScript
modules for their web applications. There is no guarantee for any specific npm or nodejs
version, that is included in the image; those versions can be changed anytime and
the nodejs itself is included just to make the npm work.
.SH Usage
.PP
To build a simple php\-test\-app
\[la]https://github.com/sclorg/s2i-php-container/tree/master/7.1/test/test-app\[ra] application
using standalone S2I
\[la]https://github.com/openshift/source-to-image\[ra] and then run the
resulting image with Docker
\[la]http://docker.io\[ra] execute:
.IP \(bu 2
.PP
\fBFor RHEL based image\fP
.PP
.RS
.nf
$ s2i build https://github.com/sclorg/s2i\-php\-container.git \-\-context\-dir=7.1/test/test\-app rhscl/php\-71\-rhel7 php\-test\-app
$ docker run \-p 8080:8080 php\-test\-app
.fi
.RE
.IP \(bu 2
.PP
\fBFor CentOS based image\fP
.PP
.RS
.nf
$ s2i build https://github.com/sclorg/s2i\-php\-container.git \-\-context\-dir=7.1/test/test\-app centos/php\-71\-centos7 php\-test\-app
$ docker run \-p 8080:8080 php\-test\-app
.fi
.RE
.PP
\fBAccessing the application:\fP
.PP
.RS
.nf
$ curl 127.0.0.1:8080
.fi
.RE
.SH Environment variables
.PP
To set these environment variables, you can place them as a key value pair into a \fB\fC\&.sti/environment\fR
file inside your source code repository.
.PP
The following environment variables set their equivalent property value in the php.ini file:
* \fBERROR\_REPORTING\fP
* Informs PHP of which errors, warnings and notices you would like it to take action for
* Default: E\_ALL \& \~E\_NOTICE
* \fBDISPLAY\_ERRORS\fP
* Controls whether or not and where PHP will output errors, notices and warnings
* Default: ON
* \fBDISPLAY\_STARTUP\_ERRORS\fP
* Cause display errors which occur during PHP's startup sequence to be handled separately from display errors
* Default: OFF
* \fBTRACK\_ERRORS\fP
* Store the last error/warning message in $php\_errormsg (boolean)
* Default: OFF
* \fBHTML\_ERRORS\fP
* Link errors to documentation related to the error
* Default: ON
* \fBINCLUDE\_PATH\fP
* Path for PHP source files
* Default: .:/opt/app\-root/src:/opt/rh/rh\-php71/root/usr/share/pear
* \fBPHP\_MEMORY\_LIMIT\fP
* Memory Limit
* Default: 128M
* \fBSESSION\_NAME\fP
* Name of the session
* Default: PHPSESSID
* \fBSESSION\_HANDLER\fP
* Method for saving sessions
* Default: files
* \fBSESSION\_PATH\fP
* Location for session data files
* Default: /tmp/sessions
* \fBSESSION\_COOKIE\_DOMAIN\fP
* The domain for which the cookie is valid.
* Default:
* \fBSESSION\_COOKIE\_HTTPONLY\fP
* Whether or not to add the httpOnly flag to the cookie
* Default: 0
* \fBSESSION\_COOKIE\_SECURE\fP
* Specifies whether cookies should only be sent over secure connections.
* Default: Off
* \fBSHORT\_OPEN\_TAG\fP
* Determines whether or not PHP will recognize code between <? and ?> tags
* Default: OFF
* \fBDOCUMENTROOT\fP
* Path that defines the DocumentRoot for your application (ie. /public)
* Default: /
.PP
The following environment variables set their equivalent property value in the opcache.ini file:
* \fBOPCACHE\_MEMORY\_CONSUMPTION\fP
* The OPcache shared memory storage size in megabytes
* Default: 128
* \fBOPCACHE\_REVALIDATE\_FREQ\fP
* How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.
* Default: 2
.PP
You can also override the entire directory used to load the PHP configuration by setting:
* \fBPHPRC\fP
* Sets the path to the php.ini file
* \fBPHP\_INI\_SCAN\_DIR\fP
* Path to scan for additional ini configuration files
.PP
You can override the Apache MPM prefork
\[la]https://httpd.apache.org/docs/2.4/mod/mpm_common.html\[ra]
settings to increase the performance for of the PHP application. In case you set
the Cgroup limits in Docker, the image will attempt to automatically set the
optimal values. You can override this at any time by specifying the values
yourself:
.IP \(bu 2
\fBHTTPD\_START\_SERVERS\fP
.IP \(bu 2
The StartServers
\[la]https://httpd.apache.org/docs/2.4/mod/mpm_common.html#startservers\[ra]
directive sets the number of child server processes created on startup.
.IP \(bu 2
Default: 8
.IP \(bu 2
\fBHTTPD\_MAX\_REQUEST\_WORKERS\fP
.IP \(bu 2
The MaxRequestWorkers
\[la]https://httpd.apache.org/docs/2.4/mod/mpm_common.html#maxrequestworkers\[ra]
directive sets the limit on the number of simultaneous requests that will be served.
.IP \(bu 2
\fB\fCMaxRequestWorkers\fR was called \fB\fCMaxClients\fR before version httpd 2.3.13.
.IP \(bu 2
Default: 256 (this is automatically tuned by setting Cgroup limits for the container using this formula:
\fB\fCTOTAL\_MEMORY / 15MB\fR\&. The 15MB is average size of a single httpd process.
.PP
You can use a custom composer repository mirror URL to download packages instead of the default 'packagist.org':
.PP
.RS
.nf
* **COMPOSER\_MIRROR**
* Adds a custom composer repository mirror URL to composer configuration. Note: This only affects packages listed in composer.json.
* **COMPOSER\_INSTALLER**
* Overrides the default URL for downloading Composer of https://getcomposer.org/installer. Useful in disconnected environments.
* **COMPOSER\_ARGS**
* Adds extra arguments to the `composer install` command line (for example `\-\-no\-dev`).
.fi
.RE
.SH Source repository layout
.PP
You do not need to change anything in your existing PHP project's repository.
However, if these files exist they will affect the behavior of the build process:
.IP \(bu 2
\fBcomposer.json\fP
.PP
List of dependencies to be installed with \fB\fCcomposer\fR\&. The format is documented
here
\[la]https://getcomposer.org/doc/04-schema.md\[ra]\&.
.IP \(bu 2
\fB\&.htaccess\fP
.PP
In case the \fBDocumentRoot\fP of the application is nested within the source directory \fB\fC/opt/app\-root/src\fR,
users can provide their own Apache \fB\&.htaccess\fP file. This allows the overriding of Apache's behavior and
specifies how application requests should be handled. The \fB\&.htaccess\fP file needs to be located at the root
of the application source.
.SH Hot deploy
.PP
In order to immediately pick up changes made in your application source code, you need to run your built image with the \fB\fCOPCACHE\_REVALIDATE\_FREQ=0\fR environment variable passed to the Docker
\[la]http://docker.io\[ra] \fB\fC\-e\fR run flag:
.PP
.RS
.nf
$ docker run \-e OPCACHE\_REVALIDATE\_FREQ=0 \-p 8080:8080 php\-app
.fi
.RE
.PP
To change your source code in running container, use Docker's exec
\[la]http://docker.io\[ra] command:
.PP
.RS
.nf
docker exec \-it <CONTAINER\_ID> /bin/bash
.fi
.RE
.PP
After you Docker exec
\[la]http://docker.io\[ra] into the running container, your current directory is set
to \fB\fC/opt/app\-root/src\fR, where the source code is located.
.SH Extending image
.PP
Not only content, but also startup scripts and configuration of the image can
be extended using source\-to\-image
\[la]https://github.com/openshift/source-to-image\[ra]\&.
.PP
The structure of the application can look like this:
.TS
allbox;
l l
l l .
\fB\fCFolder name\fR \fB\fCDescription\fR
\fB\fC\&./httpd\-\&cfg\fR T{
Can contain additional Apache configuration files (\fB\fC*.conf\fR)
T}
\fB\fC\&./httpd\-\&ssl\fR T{
Can contain own SSL certificate (in \fB\fCcerts/\fR subdirectory) and key (in \fB\fCprivate/\fR subdirectory)
T}
T{
\fB\fC\&./php\-\&pre\-\&start\fR
T} T{
Can contain shell scripts (\fB\fC*.sh\fR) that are sourced before \fB\fChttpd\fR is started
T}
T{
\fB\fC\&./php\-\&post\-\&assemble\fR
T} T{
Can contain shell scripts (\fB\fC*.sh\fR) that are sourced at the end of \fB\fCassemble\fR script
T}
\fB\fC\&./\fR Application source code
.TE
.SH See also
.PP
Dockerfile and other sources are available on
\[la]https://github.com/sclorg/s2i-php-container\[ra]\&.
In that repository you also can find another versions of PHP environment Dockerfiles.
Dockerfile for CentOS is called Dockerfile, Dockerfile for RHEL is called Dockerfile.rhel7.
.SH Security Implications
.PP
\-p 8080:8080
.PP
.RS
.nf
Opens container port 8080 and maps it to the same port on the Host.
.fi
.RE