1. Download the required source code package
1. Download libevent2.0.22
2. Download memcached1.4.24
3. Download the php extension memcache3.0.8.
II. Installation steps
First, download the three software packages downloaded to the/usr/local/src Directory (note: you can put them in another directory)
1. Install libevent
Cd/usr/local/src
Tar zxvf libevent-2.0.22-stable.tar.gz # extract package
Cd libevent-2.0.22-stable
./Configure -- prefix =/usr/local # Pre-compilation configuration, generate Makefile File, path can be changed by yourself
Make # compile
Make install # install
2. Install memcached
Cd/usr/local/src
Tar zxvf memcached-1.4.24.tar.gz # extract package
Cd memcached-1.4.24
./Configure-with-libevent =/usr/local # configure before compilation to generate the Makefile file. The path must be consistent with that in libevent.
Make # compile
Make install # install
(Note: If an error is reported during make compilation, the following figure is displayed :)
Solution:
1, cd/usr/local/memcached-1.4.24 into the memcached Directory
2. vi Makefile (edit the Makefile file, delete "-Werror" in the file, and save it .)
3. Save and install make install.
Test whether the installation is successful.
As shown in the following figure:
3. Install extension
1. cd/usr/local/src
2. tar zxvf memcache-3.0.8.tgz
3. Memcache-3.0.8
4./usr/local/php5/bin/phpize # run the phpize extension installer.
As shown in the following figure:
5../configure-enable-memcache-with-php-config =/usr/local/php5/bin/php-config-with-zlib-dir
6. make # compile
7. make install # install
As shown in the following figure:
3. Configure the php. Ini file
1. Check whether memcache. so exists.
Cd/usr/local/lib/php/extensions/no-debug-non-zts-20100525/
2. vi/usr/local/php5/etc/php. ini # Edit php. ini
Add the following code:
Extension = memcache. so
[Memcache]
Extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525 /"
Memcache. allow_failover = 1
Memcache. max_failover_attempts = 20
Memcache. chunk_size = 8192
4. Configure the memcached server
1. Start the memcached server
Memcached-d-m 10-u root-l 127.0.0.1-p 11211-c 256-P/usr/local/bin/memcached. pid
If an error message such as "memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory" is reported when memcached is started, the location of the libevent cannot be found for memcached.
As shown in the following figure:
Solution:
1. First, check where the libevent is and run: # whereis libevent
2. Then, check where memcached looks for it and execute # LD_DEBUG = libs memcached-v 2> & 1>/dev/null | less: yes/usr/lib/libevent-2.0.so.5, so, create soft chain
3, # ln-s/usr/local/lib/libevent-2.0.so.5/usr/lib/libevent-2.0.so.5
4. Disable memcached: pkill memcached
5. Restart: memcached-d-m 10-u root-l 127.0.0.1-p 11211-c 256-P/usr/local/bin/memcached. pid
6. Check the port to see if memcached is successfully started! # Netstat-ant
As shown in the following figure:
Indicates that startup is successful!
7. Check whether your memcache extension has been added successfully!
As shown in the following figure:
The extension is added successfully!
5. Test the memcache extension of php
Connect ("127.0.0.1", 11211 );
$ Mem-> set ('key', 'This is my memcache ceshi! ', 0, 60 );
$ Val = $ mem-> get ('key ');
Echo $ val;
?>