38

网站加速:WordPress Redis缓存设置

 5 years ago
source link: https://www.linuxprobe.com/wordpress-redis-cache.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ubuntu 16.04.4 LTS

PHP 7.0.30-0ubuntu0.16.04.1 (fpm-fcgi)

nginx version: nginx/1.12.2

安装 Redis
    $ apt install redis-server
修改配置文件
    $ vim /etc/redis/redis.conf
    # 如果需要给其他服务器使用,需要修改 bind 127.0.0.1 为 bind 0.0.0.0 ,以下仅以本机为例
    bind 0.0.0.0  # 允许外部访问
    requirepass aU9Dbks4sPQWr9x8  # 密码设置
    maxmemory 104857600  # 单位,本例为100M
    maxmemory-policy allkeys-lru  # 清理策略,优先移除最近未使用的key

    $ /etc/init.d/redis-server restart

安装 php-redis
    $ cd /etc
    $ git clone https://github.com/phpredis/phpredis.git
    $ apt install php7.0-dev
    $ cd /etc/phpredis
    $ phpize
    $ ./configure
    $ make
    $ make install
配置 php-redis
    $ vim /etc/php/7.0/fpm/php.ini
    # 在 [php] 段落加入下面一行(应该在878行附近)
    extension=/etc/phpredis/modules/redis.so

    # 如果找不到的话,搜索下面类似的注释,加入到附近就行
    ;extension=php_bz2.dll
    ;extension=php_curl.dll
    ;extension=php_fileinfo.dll
    ;extension=php_ftp.dll
    ;extension=php_gd2.dll
    ;extension=php_gettext.dll
    
    $ /etc/init.d/php7.0-fpm restart
配置 wordpress 使用 redis
    # 在 wordpress 后台安装 Redis Object Cache 插件
    # 修改 wp-config.php 配置文件
    $ vim /var/www/html/wp-ocnfig.php

    /**
     * redis object cache配置
     */
    define('WP_REDIS_HOST', '127.0.0.1');  # redis 服务器地址
    define('WP_REDIS_PORT', '6379');  # redis 服务器端口
    define('WP_REDIS_DATABASE', '0');  # redis 数据库(第一个0 ,第一个1,依次类推)
    define('WP_REDIS_PASSWORD', 'aU9Dbks4sPQWr9x8');  # redis 数据库密码
启用 Redis Object Cache

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK