Skip to content

Commit 89051de

Browse files
4c0nbestlong
authored andcommitted
This developer needed to turn back the clock in the PHP-FPM container, you will not believe what he did next! (laradock#1675)
* Added documentation for installing libfaketime in the php-fpm container * Enabled installing and using libfaketime system-wide inside the php-fpm container
1 parent 1b865dd commit 89051de

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

DOCUMENTATION/content/documentation/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,31 @@ e) set it to `true`
14991499
3 - Set it to `true`
15001500
<br>
15011501
4 - Re-build the containers `docker-compose build php-fpm`
1502+
<br>
1503+
1504+
15021505

15031506

1507+
<br>
1508+
<a name="Install-Faketime"></a>
1509+
## Install libfaketime in the php-fpm container
1510+
Libfaketime allows you to control the date and time that is returned from the operating system.
1511+
It can be used by specifying a special string in the `PHP_FPM_FAKETIME` variable in the `.env` file.
1512+
For example:
1513+
`PHP_FPM_FAKETIME=-1d`
1514+
will set the clock back 1 day. See (https://github.com/wolfcw/libfaketime) for more information.
1515+
1516+
1 - Open the `.env` file
1517+
<br>
1518+
2 - Search for the `PHP_FPM_INSTALL_FAKETIME` argument under the PHP-FPM container
1519+
<br>
1520+
3 - Set it to `true`
1521+
<br>
1522+
4 - Search for the `PHP_FPM_FAKETIME` argument under the PHP-FPM container
1523+
<br>
1524+
5 - Set it to the desired string
1525+
<br>
1526+
6 - Re-build the containers `docker-compose build php-fpm`<br>
15041527

15051528

15061529

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ services:
144144
- INSTALL_IMAGE_OPTIMIZERS=${PHP_FPM_INSTALL_IMAGE_OPTIMIZERS}
145145
- INSTALL_IMAGEMAGICK=${PHP_FPM_INSTALL_IMAGEMAGICK}
146146
- INSTALL_CALENDAR=${PHP_FPM_INSTALL_CALENDAR}
147+
- INSTALL_FAKETIME=${PHP_FPM_INSTALL_FAKETIME}
147148
volumes:
148149
- ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
149150
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
@@ -154,6 +155,7 @@ services:
154155
environment:
155156
- PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
156157
- DOCKER_HOST=tcp://docker-in-docker:2375
158+
- FAKETIME=${PHP_FPM_FAKETIME}
157159
depends_on:
158160
- workspace
159161
networks:

env-example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ PHP_FPM_INSTALL_SWOOLE=false
149149
PHP_FPM_INSTALL_PG_CLIENT=false
150150
PHP_FPM_INSTALL_PCNTL=false
151151
PHP_FPM_INSTALL_CALENDAR=false
152+
PHP_FPM_INSTALL_FAKETIME=false
153+
PHP_FPM_FAKETIME=-0
152154

153155
### PHP_WORKER ############################################
154156

php-fpm/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,18 @@ RUN if [ ${INSTALL_CALENDAR} = true ]; then \
485485
docker-php-ext-install calendar \
486486
;fi
487487

488+
###########################################################################
489+
# libfaketime:
490+
###########################################################################
491+
492+
USER root
493+
494+
ARG INSTALL_FAKETIME=false
495+
496+
RUN if [ ${INSTALL_FAKETIME} = true ]; then \
497+
apt-get install -y libfaketime \
498+
;fi
499+
488500
###########################################################################
489501
# Check PHP version:
490502
###########################################################################
@@ -509,6 +521,12 @@ RUN apt-get clean && \
509521

510522
RUN usermod -u 1000 www-data
511523

524+
# Adding the faketime library to the preload file needs to be done last
525+
# otherwise it will preload it for all commands that follow in this file
526+
RUN if [ ${INSTALL_FAKETIME} = true ]; then \
527+
echo "/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1" > /etc/ld.so.preload \
528+
;fi
529+
512530
WORKDIR /var/www
513531

514532
CMD ["php-fpm"]

0 commit comments

Comments
 (0)