Install the memcache module for PHP extension in linux

Source: Internet
Author: User
Tags zts

Installation environment
RHEL 4
Php 5.2.6


Required Software
Libevent-1.4.6-stable.tar.gz (http://monkey.org /~ Provos/libevent /)
Memcache-2.2.3.tgz (http://pecl.php.net/package/memcache)
Memcached-1.2.6.tar.gz (http://www.danga.com/memcached)


Install configurations

1. Install libevent
# Tar zxf libevent-1.4.6-stable.tar.gz
# Cd libevent-1.4.6-stable
#./Configure -- prefix =/usr/local/servers/libevent
# Make & make install

2. Install memcached
# Tar zxvf memcached-1.2.6.tar.gz
# Cd memcached-1.2.6
#./Configure -- prefix =/usr/local/servers/memcached -- with-libevent =/usr/local/servers/libevent
# Make & make install

3. Run memcached
#/Usr/local/servers/memcached-d-m 128-l localhost-p 11211-u root

-D run memcached in daemon mode;
-M: Set the memory size available for memcached, in MB;
-L set the IP address of the listener. If it is a local machine, this parameter is usually not set;
-P: Set the listening port. The default value is 11211. Therefore, you can leave this parameter unspecified;
-U indicates the user;

If you encounter problems when running memcached, the error prompt is as follows:

/Usr/local/servers/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

Run LD_DUBUG = libs to know the library loading path when memcached is started. The details are as follows:

# LD_DEBUG = libs/usr/local/servers/memcached/bin/memcached-v
10929: find library = libevent-1.4.so.2 [0]; searching
10929: search cache =/etc/ld. so. cache
10929: search path =/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2: /lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686: /usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2: /usr/lib (system search path)
10929: trying file =/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file =/lib/tls/i686/libevent-1.4.so.2
10929: trying file =/lib/tls/sse2/libevent-1.4.so.2
10929: trying file =/lib/tls/libevent-1.4.so.2
10929: trying file =/lib/i686/sse2/libevent-1.4.so.2
10929: trying file =/lib/i686/libevent-1.4.so.2
10929: trying file =/lib/sse2/libevent-1.4.so.2
10929: trying file =/lib/libevent-1.4.so.2
10929: trying file =/usr/lib/tls/i686/sse2/libevent-1.4.so.2
10929: trying file =/usr/lib/tls/i686/libevent-1.4.so.2
10929: trying file =/usr/lib/tls/sse2/libevent-1.4.so.2
10929: trying file =/usr/lib/tls/libevent-1.4.so.2
10929: trying file =/usr/lib/i686/sse2/libevent-1.4.so.2
10929: trying file =/usr/lib/i686/libevent-1.4.so.2
10929: trying file =/usr/lib/sse2/libevent-1.4.so.2
10929: trying file =/usr/lib/libevent-1.4.so.2
10929:

Then create a link for the libevent-1.4.so.2 and then run memcached:
# Ln-s/usr/local/servers/libevent/lib/libevent-1.4.so.2/lib/libevent-1.4.so.2

4. Install the memcache extension of php

You can use the pecl installation program that comes with php.
#/Usr/local/servers/php5/bin/pecl install memcache

You can also install it from the source code.
# Tar zxf memcache-2.2.3.tgz
# Cd memcache-2.2.3
#/Usr/local/servers/php5/bin/phpize
#. /Configure -- enable-memcache =/usr/local/servers/memcached -- with-php-config =/usr/local/servers/php5/bin/php-config -- with-apxs2 =/ usr/sbin/apxs
# Make & make inst

After the installation is complete, a message like this will be prompted:
Installing shared extensions:/usr/local/servers/php5/lib/php/extension/ no-debug-non-zts-20060922/

Remember this, modify php. ini, and

Extension_dir = "./"
Change
Extension_dir = "/usr/local/servers/php5/lib/php/extensions /"

Add a row
Extension = "no-debug-non-zts-20060922/memcache. so"

5. Use phpinfo to view


Test Module

<? Php

$ Memcache = new Memcache;
$ Memcache-> connect (localhost, 12000) or die ("cocould not connect ");

$ Version = $ memcache-> getVersion ();
Echo "Servers version:". $ version. "<br/> ";

$ Tmp_object = new stdClass;
$ Tmp_object-> str_attr = test;
$ Tmp_object-> int_attr = 123;

$ Memcache-> set (key, $ tmp_object, false, 10) or die ("Failed to save data at the server ");
Echo "Store data in the cache (data will expire in 10 seconds) <br/> ";

$ Get_result = $ memcache-> get (key );
Echo "Data from the cache: <br/> ";

Var_dump ($ get_result );

?>

Display result:

Servers version: 1.2.6
Store data in the cache (data will expire in 10 seconds)
Data from the cache:

Object (stdClass) [3] public str_attr => string test (length = 4) public int_attr => int 123

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.