Bootstrap FreeKB - PHP - Enable memcache for PHP FPM on Docker
PHP - Enable memcache for PHP FPM on Docker

Updated:   |  PHP articles

This assumes you have installed the php:fpm container on Docker and the memcache container.

Here is how you can build the php:fpm image using a Dockerfile that includes memcache. Notice in this example that the "pecl install" command is used to install memcache.

FROM php:fpm
RUN apt-get update
RUN pecl install memcache
RUN docker-php-ext-enable memcache

 

And you would then use the docker build command to create the image.

docker build --file Dockerfile --tag php:fpm_memcache

 

The docker images command should return something like this.

REPOSITORY   TAG              IMAGE ID       CREATED             SIZE
php          fpm_memcache     bc6a0e2b34ff   About an hour ago   491MB

 

And then use the docker run command is used to create and start the php fpm container.

docker run --detach --name php-fpm --publish 0.0.0.0:9000:9000 php:fpm_ssh2

 

The docker container ls command should show that the PHP container is up and running.

]$ sudo docker container ls
CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS
3c83cc256665   php:fpm_memcache     "docker-php-entrypoi…"   57 seconds ago   Up 56 seconds   0.0.0.0:9000->9000/tcp

 

The memcache library should be installed, which can be seen with the php -i command.

~]$ sudo docker exec php-fpm php -i | grep -i memcache
]$ sudo docker exec php-fpm php -i | grep -i memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 32768 => 32768
memcache.compress_threshold => 20000 => 20000
memcache.default_port => 11211 => 11211
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.lock_timeout => 15 => 15
memcache.max_failover_attempts => 20 => 20
memcache.prefix_host_key => Off => Off
memcache.prefix_host_key_remove_subdomain => Off => Off
memcache.prefix_host_key_remove_www => On => On
memcache.prefix_static_key => no value => no value
memcache.protocol => ascii => ascii
memcache.redundancy => 1 => 1
memcache.session_prefix_host_key => Off => Off
memcache.session_prefix_host_key_remove_subdomain => Off => Off
memcache.session_prefix_host_key_remove_www => On => On
memcache.session_prefix_static_key => no value => no value
memcache.session_redundancy => 2 => 2
memcache.session_save_path => no value => no value
Registered save handlers => files user memcache

 

The memcache module should be enabled, which can be seen with the php -m command.

~]$ sudo docker exec php-fpm php -m | grep memcache
memcache

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2f7282 in the box below so that we can be sure you are a human.