1. Install via Yum
Yum-y Install memcached
#安装完成后执行:
Memcached–h
2. Memcached operation
View Test Number Modification configuration
Vim/etc/sysconfig/memcached
The contents are as follows:
port= "11211″ #端口
User= "memcached" #用户
maxconn= "1024″ #最大内存
Cachesize= "64″ #缓存大小
Options= "" #其它选项
Can modify port, user and maximum memory, cache size
Systemctl Restart memcached #重启
Systemctl start memcached #启动
Systemctl Enable memcached #开机自启动
Systemctl status memcached #状态
Systemctl Stop memcached #关闭
3. Installing the Php-memcache Extension
Yum-y Install Php-pecl-memcache
#打开配置文件php. ini
Vim/etc/php.ini
#在里面添加扩展:
Extension=memcache.so
#重启下Apache
Systemctl Restart Httpd.service
#测试下扩展安装成功与否
Create a index.php file, and then
<?php phpinfo ();? >
Open the browser, enter the URL, if it appears as follows, the installation is successful:
# If it does not appear as shown, please continue to install Libevent-devel
Yum-y Install Libevent-devel
After this installation, no surprises, should be successful!
4. Firewall Release 11211 Port
Firewall-cmd--permanent--zone=public--add-port=11211/tcp
Proceed to here, everything is ready OK. Now, test it.
5. Testing under PHP
#建立test the. php file, write the following code:
<?php
$mem = new Memcache;
$mem->connect (' 127.0.0.1 ', 11211);
$mem->set (' Test ', "Hello world!", 0, 60);
$val = $mem->get (' Test ');
Echo $val;
?>
Then enter the appropriate URL in the browser, if everything is OK, it will appear as follows:
~
But in the process of running this program, the browser prompts: "SELinux alert Browser". Find a reason, with selinux (in this case, the SELinux will not do a deep dive). Landlord to take the measure is simple, is to close this selinux can:
Vim/etc/sysconfig/selinux
Modify the following:
Change the selinux= enforcing to selinux=disabled.
After restarting, enter the appropriate URL in the browser to see the effect as shown!
Copyright notice: Hello, everyone!
Install memcache under CentOS