ubuntu nginx php mysql memcached_centos6+nginx+php+mysql+memcached+wordpress

centos6+nginx+php+mysql+memcached+wordpress 搭建步骤(1)

LNMP 平台搭建:

请参考:http://www.cnblogs.com/ligao/p/6125710.html

1,安装 memcached:

memcache 是 pecl 扩展库版本,原生支持 php,出现更早,是老前辈;

memcached 是 libmemcached 版本,出现较后,是新一代,因此也更加完善,推荐使用。

(1)yum 安装方式:

yum -y install memcached

#启动 memcached

service memcached start

#开机启动

chkconfig memcached on

(2)编译安装方式:

1,安装环境依赖包:yum install cyrus-sasl-devel gcc+ gcc-c++ gcc-devel

2,#从官方下载最新源码包

wget http://memcached.org/files/memcached-1.4.25.tar.gz

#解压开始编译安装

tar xzvf memcached-1.4.15.tar.gz

cd memcached-1.4.15

./configure –prefix=/usr/local/memcached

make && make install

(3)设置环境变量

ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached

cp scripts/memcached.sysv /etc/init.d/memcached

(4)改为监听 127.0.0.1,并关闭 UDP 连接方式,若为远程服务调用或不需要的话请跳过此行

sed -i ‘s/OPTIONS=””/OPTIONS=”-l 127.0.0.1 -U 0″/g’ /etc/init.d/memcached

sed -i ‘s@chown@#chown@’ /etc/init.d/memcached

sed -i ‘s@/var/run/memcached/memcached.pid@/var/run/memcached.pid@’ /etc/init.d/memcached

(5)启动并设置开机服务

chmod +x /etc/init.d/memcached

service memcached start

chkconfig –add memcached

chkconfig memcached on

2,安装 php-memcached 组件:

(1)从 github 下载 PHP7 专用的 memcached 组件分支

[root@MyServer ~]# wget https://github.com/php-memcached-dev/php-memcached/archive/php7.zip

[root@MyServer ~]# unzip php7.zip

[root@MyServer ~]# cd php-memcached-php7/

[root@MyServer ~]#/usr/local/php/bin/phpize ##phpize 的作用可以这样理解:侦测环境(phpize 工具是在 php 安装目录下,基于这点 phpize 对应了当时的 php 环境,所以是要根据该 php 的配置情况生成对应的 configure 文件),建立一个 configure 文件。必须在一个目录下去运行 phpize。那么 phpize 就知道你的的环境是哪个目录,并且 configure 文件建立在该目录下。

[root@MyServer ~]#./configure –with-php-config=/usr/local/php/bin/php-config –with-libmemcached-dir=/usr/local/libmemcached

[root@MyServer ~]#make && make install

ps:make install 会自动将生成的.so 扩展复制到 php 的扩展目录下去,比如会提示已经安装到 /usr/local/php/php-5.5.18/lib/php/extensions/no-debug-non-zts-20121212/目录下去

编译安装完成

(2)配置再 php 中声明模块路径。

[root@MyServer ~]#vim /etc/php.ini #再文件最后加入

extension=memcached.so

[root@MyServer ~]#php -m | grep memcached #查看 memcached 外部扩展模块是否安装成功

重启 php-fpm/nginx。

(3)测试[root@MyServer ~]# vim test.php

$m = new Memcached();

$m->addServer( '127.0.0.1', 11211 );

$m->set( 'foo', 100 );

echo $m->get( 'foo' ) . "\n";

[root@MyServer ~]# php -f test.php

3,wordpress 缓存设置

做完上述所有步骤,系统环境就已经支持 memcached 缓存了。下面分享如何应用到 WordPressAdd the following to your wp-config.php file:

global $memcached_servers;

$memcached_servers = array(

array(

'127.0.0.1', // Memcached server IP address

11211 // Memcached server port

)

);

If your Memcached server is located on a different server or port, adjust those values as needed. If you have multiple Memcached instances, add additional servers to the array:

global $memcached_servers;

$memcached_servers = array(

array(

'1.2.3.4',

11211

),

array(

'1.2.3.5',

11211

)

);

值得说明的是,这里还有一个大坑等着你来踩:

WordPress 官网上的 object-cache.php 虽然也号称 Memcached 插件,然而它只支持 Memcache,不支持新版的,所以不能使用。如果错误地将 object-cache.php 和 Memcached 混用的话,则会出现 WordPress 打不开,前台后台页面一片空白的现象。

这也就是经常有站长反馈 WordPress 启用 memcached 功能后,页面空白的错误原因了。不巧,张戈在测试的时候也踩坑了,所以特别提出来,希望大家了解错误的原因,规避掉!

(2)安装 memcache

[root@MyServer ~]# wget http://pecl.php.net/get/memcache-3.0.8.tgz #解压之后进行编辑 memcache.php 文件。

vim memcache.php

//修改四个地方(以下注释部分),登陆用户名及密码及连接信息:

define(‘ADMIN_USERNAME’,’admin’); // 此处设置登录用户名

define(‘ADMIN_PASSWORD’,’123456′); // 此处设置登录用户密码

define(‘DATE_FORMAT’,’Y/m/d H:i:s’);

define(‘GRAPH_SIZE’,200);

define(‘MAX_ITEM_DUMP’,50);

$MEMCACHE_SERVERS[] = ‘127.0.0.1:11211’; // 此处设置连接信息

//$MEMCACHE_SERVERS[] = ‘mymemcache-server2:11211’; // 只使用一个进程,此处屏蔽,否则可以设置多个连接信息

(3)把 memcache.php 文件放到 web 根目录下,使用 http://IP 地址/memcache.php 进行访问。

2018040508365434.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值