1. Install memcached service and php extension
apt-get install memcached php5-memcached php5-memcache
2. Check whether the memcached service is installed
ps aux | grep memcached
You can find that memcached starts automatically after installation. You can also view it with the following command:
netstat -tap | grep 'memcached'
3. If you need to modify the configuration file
please go to: /etc/memcached.conf
Restart after modification
pkill memcached
/usr/bin/memcached restart - p 11211 -u nobody -l 127.0.0.1
It is best to find a shell script on the Internet, you can directly memcache start
4. Finally, restart the web server, use fast-cgi of apache or nginx
/etc/init.d/apache2 restart
Finally let’s take a simple example:
$mem = newMemcache;
$mem->connect("localhost",11211);
$mem->set('test', 'hello world',0,60);
echo $mem->get('test');
If you can see the hello word, it's really ok.