Update mentioned php versions that are EOL

This commit is contained in:
Joseph Ferguson 2023-06-23 11:40:43 -07:00
parent 310d83d7e9
commit 1dfc91d288
1 changed files with 32 additions and 34 deletions

View File

@ -11,7 +11,7 @@ PHP is a server-side scripting language designed for web development, but which
### Create a `Dockerfile` in your PHP project ### Create a `Dockerfile` in your PHP project
```dockerfile ```dockerfile
FROM %%IMAGE%%:7.4-cli FROM %%IMAGE%%:8.2-cli
COPY . /usr/src/myapp COPY . /usr/src/myapp
WORKDIR /usr/src/myapp WORKDIR /usr/src/myapp
CMD [ "php", "./your-script.php" ] 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: 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 ```console
$ 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 $ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp %%IMAGE%%:8.2-cli php your-script.php
``` ```
## How to install more PHP extensions ## 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. 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 ```Dockerfile
FROM %%IMAGE%%:7.4-cli FROM %%IMAGE%%:8.2-cli
RUN docker-php-source extract \ RUN docker-php-source extract \
# do important things \ # do important things \
&& docker-php-source delete && docker-php-source delete
@ -52,7 +52,7 @@ RUN docker-php-source extract \
For example, if you want to have a PHP-FPM image with the `gd` extension, 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 the `gd` extension, you can inherit the base image that you like, and write your own `Dockerfile` like this:
```dockerfile ```dockerfile
FROM %%IMAGE%%:7.4-fpm FROM %%IMAGE%%:8.2-fpm
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
libfreetype-dev \ libfreetype-dev \
libjpeg62-turbo-dev \ libjpeg62-turbo-dev \
@ -76,59 +76,57 @@ Some extensions are compiled by default. This depends on the PHP version you are
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: 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 ```dockerfile
FROM %%IMAGE%%:7.4-cli FROM %%IMAGE%%:8.2-cli
RUN pecl install redis-5.1.1 \ RUN pecl install redis-5.3.7 \
&& pecl install xdebug-2.8.1 \ && pecl install xdebug-3.2.1 \
&& docker-php-ext-enable redis xdebug && docker-php-ext-enable redis xdebug
``` ```
```dockerfile ```dockerfile
FROM %%IMAGE%%:5.6-cli FROM %%IMAGE%%:8.2-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \ RUN apt-get update && apt-get install -y libmemcached-dev libssl-dev zlib1g-dev \
&& pecl install memcached-2.2.0 \ && pecl install memcached-3.2.0 \
&& docker-php-ext-enable memcached && docker-php-ext-enable memcached
``` ```
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). 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 compatibility when choosing a version of the extension to install, but does when trying to install it). 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.
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. 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.2.0 && pecl install redis-5.3.7` instead of `pecl install memcached-3.2.0 redis-5.3.7`. However, `docker-php-ext-enable memcached redis` is fine to be all in one command.
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-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 ### Other extensions
Some extensions are not provided via either Core or PECL; these can be installed too, although the process is less automated: Some extensions are not provided via either Core or PECL; these can be installed too, although the process is less automated:
```dockerfile ```dockerfile
FROM %%IMAGE%%:5.6-cli FROM %%IMAGE%%:8.2-cli
RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz' -o xcache.tar.gz \ RUN curl -fsSL '[url-to-custom-php-module]' -o module-name.tar.gz \
&& mkdir -p xcache \ && mkdir -p module-name \
&& tar -xf xcache.tar.gz -C xcache --strip-components=1 \ && sha256sum -c "[shasum-value] module-name.tar.gz" \
&& rm xcache.tar.gz \ && tar -xf module-name.tar.gz -C module-name --strip-components=1 \
&& rm module-name.tar.gz \
&& ( \ && ( \
cd xcache \ cd module-name \
&& phpize \ && phpize \
&& ./configure --enable-xcache \ && ./configure --enable-module-name \
&& make -j "$(nproc)" \ && make -j "$(nproc)" \
&& make install \ && make install \
) \ ) \
&& rm -r xcache \ && rm -r module-name \
&& docker-php-ext-enable xcache && docker-php-ext-enable module-name
``` ```
The `docker-php-ext-*` scripts *can* accept an arbitrary path, but it must be absolute (to disambiguate from built-in extension names), so the above example could also be written as the following: The `docker-php-ext-*` scripts *can* accept an arbitrary path, but it must be absolute (to disambiguate from built-in extension names), so the above example could also be written as the following:
```dockerfile ```dockerfile
FROM %%IMAGE%%:5.6-cli FROM %%IMAGE%%:8.2-cli
RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz' -o xcache.tar.gz \ RUN curl -fsSL '[url-to-custom-php-module]' -o module-name.tar.gz \
&& mkdir -p /tmp/xcache \ && mkdir -p /tmp/module-name \
&& tar -xf xcache.tar.gz -C /tmp/xcache --strip-components=1 \ && sha256sum -c "[shasum-value] module-name.tar.gz" \
&& rm xcache.tar.gz \ && tar -xf module-name.tar.gz -C /tmp/module-name --strip-components=1 \
&& docker-php-ext-configure /tmp/xcache --enable-xcache \ && rm module-name.tar.gz \
&& docker-php-ext-install /tmp/xcache \ && docker-php-ext-configure /tmp/module-name --enable-module-name \
&& rm -r /tmp/xcache && docker-php-ext-install /tmp/module-name \
&& rm -r /tmp/module-name
``` ```
## Running as an arbitrary user ## Running as an arbitrary user
@ -163,7 +161,7 @@ The default config can be customized by copying configuration files into the `$P
### Example ### Example
```dockerfile ```dockerfile
FROM %%IMAGE%%:7.4-fpm-alpine FROM %%IMAGE%%:8.2-fpm-alpine
# Use the default production configuration # Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"