Merge pull request #1567 from J0WI/default-php-exts
[PHP] Document default extensions
This commit is contained in:
commit
af0f5cf03f
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
PHP is a server-side scripting language designed for web development, but which can also be used as a general-purpose programming language. PHP can be added to straight HTML or it can be used with a variety of templating engines and web frameworks. PHP code is usually processed by an interpreter, which is either implemented as a native module on the web-server or as a common gateway interface (CGI).
|
||||
|
||||
> [wikipedia.org/wiki/PHP](http://en.wikipedia.org/wiki/PHP)
|
||||
> [wikipedia.org/wiki/PHP](https://en.wikipedia.org/wiki/PHP)
|
||||
|
||||
%%LOGO%%
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ PHP is a server-side scripting language designed for web development, but which
|
|||
### Create a `Dockerfile` in your PHP project
|
||||
|
||||
```dockerfile
|
||||
FROM %%IMAGE%%:7.2-cli
|
||||
FROM %%IMAGE%%:7.4-cli
|
||||
COPY . /usr/src/myapp
|
||||
WORKDIR /usr/src/myapp
|
||||
CMD [ "php", "./your-script.php" ]
|
||||
|
|
@ -29,7 +29,7 @@ $ docker run -it --rm --name my-running-app my-php-app
|
|||
For many simple, single file projects, you may find it inconvenient to write a complete `Dockerfile`. In such cases, you can run a PHP script by using the PHP Docker image directly:
|
||||
|
||||
```console
|
||||
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp %%IMAGE%%:7.2-cli php your-script.php
|
||||
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp %%IMAGE%%:7.4-cli php your-script.php
|
||||
```
|
||||
|
||||
## How to install more PHP extensions
|
||||
|
|
@ -41,7 +41,7 @@ We provide the helper scripts `docker-php-ext-configure`, `docker-php-ext-instal
|
|||
In order to keep the images smaller, PHP's source is kept in a compressed tar file. To facilitate linking of PHP's source with any extension, we also provide the helper script `docker-php-source` to easily extract the tar or delete the extracted source. Note: if you do use `docker-php-source` to extract the source, be sure to delete it in the same layer of the docker image.
|
||||
|
||||
```Dockerfile
|
||||
FROM %%IMAGE%%:7.2-cli
|
||||
FROM %%IMAGE%%:7.4-cli
|
||||
RUN docker-php-source extract \
|
||||
# do important things \
|
||||
&& docker-php-source delete
|
||||
|
|
@ -49,16 +49,15 @@ RUN docker-php-source extract \
|
|||
|
||||
### PHP Core Extensions
|
||||
|
||||
For example, if you want to have a PHP-FPM image with `iconv` and `gd` extensions, you can inherit the base image that you like, and write your own `Dockerfile` like this:
|
||||
For example, if you want to have a PHP-FPM image with `gd` extensions, you can inherit the base image that you like, and write your own `Dockerfile` like this:
|
||||
|
||||
```dockerfile
|
||||
FROM %%IMAGE%%:7.2-fpm
|
||||
FROM %%IMAGE%%:7.4-fpm
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libfreetype6-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libpng-dev \
|
||||
&& docker-php-ext-install -j$(nproc) iconv \
|
||||
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
|
||||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||
&& docker-php-ext-install -j$(nproc) gd
|
||||
```
|
||||
|
||||
|
|
@ -66,14 +65,18 @@ Remember, you must install dependencies for your extensions manually. If an exte
|
|||
|
||||
See ["Dockerizing Compiled Software"](https://tianon.xyz/post/2017/12/26/dockerize-compiled-software.html) for a description of the technique Tianon uses for determining the necessary build-time dependencies for any bit of software (which applies directly to compiling PHP extensions).
|
||||
|
||||
### Default extensions
|
||||
|
||||
Some extensions are compiled by default. This depends on the PHP version you are using. Run `php -m` in the container to get a list for your specific version.
|
||||
|
||||
### PECL extensions
|
||||
|
||||
Some extensions are not provided with the PHP source, but are instead available through [PECL](https://pecl.php.net/). To install a PECL extension, use `pecl install` to download and compile it, then use `docker-php-ext-enable` to enable it:
|
||||
|
||||
```dockerfile
|
||||
FROM %%IMAGE%%:7.2-cli
|
||||
RUN pecl install redis-4.0.1 \
|
||||
&& pecl install xdebug-2.6.0 \
|
||||
FROM %%IMAGE%%:7.4-cli
|
||||
RUN pecl install redis-5.1.1 \
|
||||
&& pecl install xdebug-2.8.1 \
|
||||
&& docker-php-ext-enable redis xdebug
|
||||
```
|
||||
|
||||
|
|
@ -86,11 +89,11 @@ RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
|
|||
|
||||
It is *strongly* recommended that users use an explicit version number in their `pecl install` invocations to ensure proper PHP version compatibility (PECL does not check the PHP version compatiblity when choosing a version of the extension to install, but does when trying to install it).
|
||||
|
||||
For example, `memcached-2.2.0` has no PHP version constraints (https://pecl.php.net/package/memcached/2.2.0), but `memcached-3.0.4` requires PHP 7.0.0 or newer (https://pecl.php.net/package/memcached/3.0.4). When doing `pecl install memcached` (no specific version) on PHP 5.6, PECL will try to install the latest release and fail.
|
||||
For example, `memcached-2.2.0` has no PHP version constraints (https://pecl.php.net/package/memcached/2.2.0), but `memcached-3.1.4` requires PHP 7.0.0 or newer (https://pecl.php.net/package/memcached/3.1.4). When doing `pecl install memcached` (no specific version) on PHP 5.6, PECL will try to install the latest release and fail.
|
||||
|
||||
Beyond the compatibility issue, it's also a good practice to ensure you know when your dependencies receive updates and can control those updates directly.
|
||||
|
||||
Unlike PHP core extensions, PECL extensions should be installed in series to fail properly if something went wrong. Otherwise errors are just skipped by PECL. For example, `pecl install memcached-2.2.0 && pecl install redis-2.2.8` instead of `pecl install memcached-2.2.0 redis-2.2.8`. However, `docker-php-ext-enable memcached redis` is fine to be all in one command.
|
||||
Unlike PHP core extensions, PECL extensions should be installed in series to fail properly if something went wrong. Otherwise errors are just skipped by PECL. For example, `pecl install memcached-3.1.4 && pecl install redis-5.1.1` instead of `pecl install memcached-3.1.4 redis-5.1.1`. However, `docker-php-ext-enable memcached redis` is fine to be all in one command.
|
||||
|
||||
### Other extensions
|
||||
|
||||
|
|
@ -159,7 +162,7 @@ The default config can be customized by copying configuration files into the `$P
|
|||
### Example
|
||||
|
||||
```dockerfile
|
||||
FROM %%IMAGE%%:7.2-fpm-alpine
|
||||
FROM %%IMAGE%%:7.4-fpm-alpine
|
||||
|
||||
# Use the default production configuration
|
||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||
|
|
|
|||
Loading…
Reference in New Issue