Install memcached and php Client

Source: Internet
Author: User
Tags php memcached
Different from web1.0, web1.0 is content-centered. Therefore, web1.0 only needs to cache content for load. Using reverse proxy to cache pages can solve most of the problems. Web encourages user interaction, and the content is dynamic. If only reverse proxy is used, the rate is low, and the database is frequently written, which puts a lot of pressure on the database. Therefore, web2.0 needs to use the memory cache for web1.0.

Memcached's high-performance, distributed memory object cache system reduces database load in dynamic applications and improves access speed. Memcached has been widely used in various software, such as nginx and mysql.

1. Server Installation
Use weget to download libevent and memcached
Libevent: http://monkey.org /~ Provos/libevent-1.4.9-stable.tar.gz
Memcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz

1. Install the libevent Java code first.

  1. Tar zxvf libevent-1.4.9-stable.tar.gz
  2. Cd libevent-1.4.9-stable
  3. ./Configure
  4. Make
  5. Make install
tar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable./configuremakemake install

2. Install memcached Java code

  1. Tar zxvf memcached-1.2.6.tar.gz
  2. Cd memcached-1.2.6
  3. ./Configure -- enable-threads
  4. Make
  5. Make install
tar zxvf memcached-1.2.6.tar.gzcd memcached-1.2.6./configure --enable-threadsmakemake install

NOTE: If "memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open
Shared object file: No such file or directory, which indicates that memcached cannot find the libevent location.
Therefore, use whereis libevent to obtain the location, and then connect to the Java code in the memcached path.

  1. [Root @ localhost tools] # whereis libevent
  2. Libevent:/usr/local/lib/libevent. la/usr/local/lib/libevent. so/usr/local/lib/libevent.
  3. [Root @ localhost tools] # LD_DEBUG = libs memcached-v 2> & 1>/dev/null | less
  4. 3848: find library = libevent-1.4.so.2 [0]; searching
  5. 3848: search cache =/etc/ld. so. cache
  6. 3848: search path =/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64 :/
  7. Usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
  8. (System search path)
  9. 3848: trying file =/lib64/tls/x86_64/libevent-1.4.so.2
  10. 3848: trying file =/lib64/tls/libevent-1.4.so.2
  11. 3848: trying file =/lib64/x86_64/libevent-1.4.so.2
  12. 3848: trying file =/lib64/libevent-1.4.so.2
  13. 3848:
  14. 3848: find library = libc. so.6 [0]; searching
  15. 3848: search cache =/etc/ld. so. cache
  16. 3848: trying file =/lib64/libc. so.6
  17. 3848:
  18. 3848: find library = libnsl. so.1 [0]; searching
  19. 3848: search cache =/etc/ld. so. cache
  20. 3848: trying file =/lib64/libnsl. so.1
  21. 3848:
  22. 3848: find library = librt. so.1 [0]; searching
  23. 3848: search cache =/etc/ld. so. cache
  24. 3848: trying file =/lib64/librt. so.1
  25. 3848:
  26. 3848: find library = libresolv. so.2 [0]; searching
  27. 3848: search cache =/etc/ld. so. cache
  28. [Root @ localhost tools] # ln-s/usr/local/lib/libevent-1.4.so.2/lib64/
[root@localhost tools]# whereis libeventlibevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a[root@localhost tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less      3848:     find library=libevent-1.4.so.2 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:      search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64                (system search path)      3848:       trying file=/lib64/tls/x86_64/libevent-1.4.so.2      3848:       trying file=/lib64/tls/libevent-1.4.so.2      3848:       trying file=/lib64/x86_64/libevent-1.4.so.2      3848:       trying file=/lib64/libevent-1.4.so.2      3848:           3848:     find library=libc.so.6 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/libc.so.6      3848:           3848:     find library=libnsl.so.1 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/libnsl.so.1      3848:           3848:     find library=librt.so.1 [0]; searching      3848:      search cache=/etc/ld.so.cache      3848:       trying file=/lib64/librt.so.1      3848:           3848:     find library=libresolv.so.2 [0]; searching      3848:      search cache=/etc/ld.so.cache[root@localhost tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/

Ii. memcached support for php installation
Php has two versions of memcached Client

1. memcached
This is the new version of the client based on libmemcached, so you must install libmemcached

Install libmemcached first
: Http://download.tangent.org/libmemcached-0.26.tar.gz

Java code
  1. [Root @ localhost tools] # tar zxvf libmemcached-0.26.tar.gz
  2. [Root @ localhosttools] # cd libmemcached-0.26
  3. [Root @ localhost libmemcached-0.26] #./configure -- prefix =/usr/local/libmemcached/-- with-libmemcached-dir =/usr/local/libmemcached/
  4. [Root @ localhost libmemcached-0.26] # make
  5. [Root @ localhost libmemcached-0.26] # make install
[root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz[root@localhost tools]# cd libmemcached-0.26[root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost libmemcached-0.26]# make[root@localhost libmemcached-0.26]# make install

Install the php memcached Client
: Http://pecl.php.net/get/memcached

Java code
  1. [Root @ localhost tools] # tar zxvf memcached-0.1.4.tgz
  2. [Root @ localhosttools] # cd memcached-0.1.4
  3. [Root @ localhost memcached-0.1.4] #. /configure -- with-php-config =/usr/local/php/bin/php-config -- with-libmemcached-dir =/usr/local/libmemcached/
  4. [Root @ localhost memcached-0.1.4] # make
  5. [Root @ localhost memcached-0.1.4] # make install
[root@localhost tools]# tar zxvf memcached-0.1.4.tgz[root@localhost tools]# cd memcached-0.1.4[root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost memcached-0.1.4]# make[root@localhost memcached-0.1.4]# make install

Modify php. ini and add extension = "memcached. so.

If an error occurs

Java code
  1. Checking for libmemcached location... configure: error: memcached support requires libmemcached. Use -- with-libmemcached-dir = <DIR> to specify the prefix where libmemcached headers and library are located
checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located

Please first find the path with whereis libmemcached, and then add the option -- with-libmemcached-dir = libmemcached path

2. memcache
: Http://pecl.php.net/get/memcache Java code

  1. [Root @ localhost tools] # tar zxvf memcache-3.0.3.tgz
  2. [Root @ localhosttools] # cd memcache-3.0.3
  3. [Root @ localhost tools] #/usr/local/php/bin/phpize
  4. [Root @ localhost tools] #./configure -- with-php-config =/usr/local/php/bin/php-config
  5. [Root @ localhost tools] # make
  6. [Root @ localhost tools] # make install
[root@localhost tools]# tar zxvf memcache-3.0.3.tgz [root@localhost tools]# cd memcache-3.0.3[root@localhost tools]# /usr/local/php/bin/phpize[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@localhost tools]# make[root@localhost tools]# make install

Modify php. ini and add extension = "memcache. so.

Tip: If the so file cannot be found in php, set extension_dir.

Ps: This article has been in the draft box for a long time. Finally, I decided to write more articles. It seems much faster.

References:
Http://www.danga.com/memcached/ http://willko.javaeye.com/blog/332993

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.