Docker Redis database cache configuration (WordPress)

The group next door plays Redis every day, and I simply install one. The host of this blog is a Docker environment. Containers used include PHP containers, Nginx containers, MySQL containers, and the newly added Redis container.

network environment

The containers required for this blog to run are all located in the same Docker bridge network, and each container can access other containers through the container name.

The advantage of this is that the network interaction is carried out internally. Except for Nginx, there is no need to map other ports to external ports.

preparation in advance

Since it is a Docker environment, first pull a Redis container:

 $docker pull redis

Check the network group of the PHP container and remember its network name:

All preparations are completed.

Configure and start Redis container

  1. Create configuration file and directory
    Create Redis required directory:

     mkdir ~/conf mkdir -p ~/data/redis_data

    Clone Default Profile redis.conf :

     #Www.azimiao.com Zimiao haunt blog cd ~/conf wget  https://raw.githubusercontent.com/redis/redis/unstable/redis.conf

    On demand configuration redis.conf For example, add a connection password:

     Requirepass mypassword//Cancel the previous # and modify the password text
  2. Start Container
    Start the Redis container and map the configuration file and data directory:

     #Blog www.azimiao.com docker run -itd \ --name redis_server1 \ -v /home/yetu/conf/redis.conf:/etc/redis.conf \ -v /home/yetu/data/redisdata:/data \ --network blog_default \ --restart=always redis redis-server /etc/redis.conf

    Command resolution:

    • -v /home/yetu/conf/redis.conf:/etc/redis.conf : Map Profile
    • -v /home/yetu/data/redis_data:/data : Map Data File
    • --network blog_default : Join the blog_default network
    • redis-server /etc/redis.conf : Use the configuration file to start the redis server in the container

    Then in the php container, you can ping the redis_server1 :

     #ping redis_server1 PING redis_server1 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.177 ms 64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.181 ms 64 bytes from 172.18.0.4: seq=2 ttl=64 time=0.162 ms

Configure PHP

Check whether the Redis extension is installed in php:

 <? php echo phpinfo(); ?>

If the Redis extension has been installed, the following is displayed:

If not, enter the PHP container to quickly install the Redis extension:

 # docker exec -it php /bin/sh # install-php-extensions redis #Press ctrl+p+q to exit

Configure WordPress

edit wp-config.php , add parameter definitions required for plug-in connection:

 define("WP_REDIS_HOST","redis_server1");// Host name (Docker container name) define("WP_REDIS_PORT",6379);// Port (6379 for configuration file by default) define("WP_REDIS_PASSWORD","yourpassword");// Password (if any) #Other parameter references: https://github.com/rhubarbgroup/redis-cache/wiki/Connection-Parameters

Then search for plug-ins in the background plug-in store Redis Object Cache And install:

Finally, in the background Settings ->Redis Click Enable Object Cache , if you can, you can connect WordPress to Redis.

other

The Redis installed above can only be accessed by internal containers under the same Docker bridging network, and it does not map any host ports, so it is relatively safe.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/7035.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*