The following will introduce the installation steps of memcached client for installing php
1. Download and install libmemcached client
Official website address: http://libmemcached.org/libMemcached.html
$wget -c https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz #亲 千万不要下载1.0.17哦 有bug $tar -zxvf libmemcached-1.0.16.tar.gz $cd libmemcached-1.0.16 $./configure --prefix=/usr/local/libmemcached --with-memcached $sudo make $sudo make install
2. Download and install memcached
Official website address: http://pecl.php.net/package/memcached
$wget -c http://pecl.php.net/get/memcached-2.2.0b1.tgz $tar -zxvf memcached-2.2.0b1.tgz $cd memcached-2.2.0b1 $sudo /usr/local/php/bin/phpize $./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disabled-memcached-sasl $sudo make $sudo make install
3. Restart php nginx
$sudo /etc/init.d/nginx restart $sudo /etc/init.d/php restart
Note: How to write scripts to restart nginx and php. Reference
php startup script
nginx startup script
4. Check whether the installation is successful
If the phpinfo() function appears as follows, the installation is successful
First make sure there is a difference between memcache and memcached.
Telnet successfully proves that memcache is successfully installed.
phpinfo shows memcached, so that’s no problem
But you said
using the official PHP file to test memcached is useless, the page prompts a 500 error
I wonder if you are using something similar to this code.
$mem = new Memcache;
$mem->connect("192.168.x.y", 11211)or die ("Could not connect");
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>
Pay attention to the first line. . $mem = new Memcache;
If your server supports memcached, memcached will be displayed in phpinfo
If it is memcache, only memcache will be displayed
memcached is php an extension of.
So if you use new memcache to instance memcached, it is normal that 500 will appear.
Linux’s memcached is the server side
php’s memcache is the client side
The client accesses the server side to access data