The code is as follows |
Copy Code |
wget http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz TAR-ZXVF memcached-1.4.10.tar.gz CD memcached-1.x.x ./configure #到这一步报错了如下: #configure: Error:libevent is required. You can get it from http://www.monkey.org/~provos/libevent/ |
Memcache used libevent This library for socket processing, so also need to install the latest version of Libevent,libevent is libevent-2.0. (If your system has libevent installed, you may not need to install it)
Official website: http://www.monkey.org/~provos/libevent/
It's just libevent.
The code is as follows |
Copy Code |
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz Tar zxvf libevent-2.0.10-stable.tar.gz ./configure-prefix=/usr Make &&make Install |
Test whether the Libevent is installed successfully
The code is as follows |
Copy Code |
Ls-al/usr/lib | grep libevent
|
Come out a big list of things, said the names installed
Next Install Memcache
The code is as follows |
Copy Code |
./configure–with-libevent=/usr
|
Test whether the memcached was successfully installed
The code is as follows |
Copy Code |
ls-al/usr/local/bin/mem* -rwxr-xr-x 1 root root 203321 01-05 08:03/usr/local/bin/memcached |
Description of Successful Installation
Basic Settings for memcached:
1. Start the Memcache server side:
#/usr/local/bin/memcached-d-M 10-u root-l 192.168.0.200-p 12000-c 256-p/tmp/memcached.pid
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, I am 10MB here,
-U is the user running memcache, I am here root,
-L is a listening server IP address, if there are more than one address, I specify the IP address of the server 192.168.0.200,
-P is the port that sets the memcache listening, I set 12000 here, preferably 1024 or more ports,
The-c option is the maximum number of concurrent connections to run, the default is 1024, I set 256 here, according to the load of your server to set,
-P is set to save the Memcache pid file, which I am here to save in/tmp/memcached.pid,
2. If you want to end the memcache process, execute:
The code is as follows |
Copy Code |
# Kill ' Cat/tmp/memcached.pid ' |
You can also start multiple daemons, but the ports cannot be duplicated.
3. Restart Apache,service httpd restart or nginx
Installing Memcache PHP Extensions
1. Select the Memcache version that you want to download in Http://pecl.php.net/package/memcache.
2. Install the PHP memcache extension
The code is as follows |
Copy Code |
wget http://pecl.php.net/get/memcache-2.2.6.tgz Tar vxzf memcache-2.2.6.tgz CD memcache-2.2.6.tgz /usr/local/php/bin/phpize ./configure–enable-memcache–with-php-config=/usr/local/php/bin/php-config–with-zlib-dir Make Make install |
3. The above installation will have a similar hint:
The code is as follows |
Copy Code |
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/ |
4. Change the Extension_dir = "./" in php.ini to
The code is as follows |
Copy Code |
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/" |
5. Add a row to load the memcache extension: extension=memcache.so
Memcache Environment test:
run the following PHP file, if the output is a test!, it means that the environment has been built successfully. Start to appreciate the charm of memcache!
code is as follows |
copy code |
<? PHP $ MEM = new Memcache; $mem->connect ("127.0.0.1″, 11211)"; $mem->set (' key ', ' This is a test! ', 0, 60); $val = $mem->get (' key '); Echo $val; ? |