CentOS installation memcached and memcache extensions for PHP configuration

Source: Internet
Author: User
Tags configuration php phpinfo

Download the required source code package

All installation packages are up-to-date.
1. Download libevent2.0.22

: http://libevent.org/

    1. Download memcached1.4.24

      : http://memcached.org/

    2. Download PHP extension memcache3.0.8

      : Http://pecl.php.net/package/memcache

Two installation detailed steps

first download the above three packages to the/tmp directory
1. Installing Libevent

cd /tmp  #首先进入到该下载包的目录tar zxvf libevent-2.0.22#解压包cd libevent-2.0.22#进入到解压的目录#编译前配置,生成Makefile文件,路径可自行更改#编译+安装

Test whether the installation was successful

2. Installing memcached

cd /tmp  #首先进入到该下载包的目录tar zxvf memcached-1.4.24#解压包cd memcached-1.4.24#进入到解压的目录#编译前配置,生成Makefile文件,路径必须与libevent中一致#编译+安装

Test whether the installation was successful

The installation of the memcached server is completed by the above operation. It's a special simple! Now, let's do a memcache. php extension Installation
3. Install the extension

cd /tmp  #首先进入到该下载包的目录tar zxvf memcache-3.0.8#解压包cd memcache-3.0.8#进入到解压的目录#动态为php添加扩展。phpize路径可能不一致,请根据自己的实际情况#php-config请根据自己环境情况填写#编译+安装

Complete the above steps, the mood pleasant click on the Enter, ready to drink saliva dashing, the result appeared a bit wrong (this is the reason I wrote this blog, or do not bother to record)

Read the code error message, said the zlib.h can not find. If you can't find it, give it to him. Really

Installing Zlib
Download zlib-1.2.8.tar.gz

: http://www.zlib.net/

cd /tmp  #首先进入到该下载包的目录tar zxvf zlib-1.2.8#解压包cd zlib-1.2.8#进入到解压的目录#编译+安装

Then configure the system files to load the zlib generated library files that were just compiled and installed.
Vi/etc/ld.so.conf.d/zlib.conf
Add the following content to save the exit:/usr/local/zlib/lib
That is, the file path to add the installation directory, the library file. The installed library file is loaded after the Ldconfig is run.

OK, at this point, re-execute the Make;make install command in the PHP extension of memcache
If you see the following information, it indicates success:

Three configuration php.ini files

First through the Phpinfo function, find the path of PHP.ini, mine is:/opt/lampp/etc/php.ini
Add the following to the content:

  1. To modify the Extension_dir path:
    Extension_dir = "/opt/lampp/lib/php/extensions/no-debug-non-zts-20121212/"
  2. Extension=memcache.so
    [Memcache]
    Memcache.allow_failover = 1
    Memcache.max_failover_attempts=20
    Memcache.chunk_size =8192
    Then restart Apache and check the situation again through phpinfo. If you have the following, the configuration is successful:
Quad Configuration Memcached Server
    1. Start the memcached server
      Memcached-d-M 10-u root-l 127.0.0.1-p 11211-c 256-p/tmp/memcached.pid

parameter Description:
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, I'm 10MB,
-U is the user running memcache, I am root here,
-L is the server IP address of the listener, if there are multiple addresses, I specify the server IP address 127.0.0.1,
-P is the port that sets Memcache listening, I set here 11211, preferably more than 1024 ports,
The-c option is the maximum number of concurrent connections to run, the default is 1024, I set the 256 here, according to the load of your server to set,
-P is set to save memcache PID file, I am here to save in/tmp/memcached.pid
2. End of memcached
Kill cat /tmp/memcached.pid
3. Check whether the memcached has been started

Five-Test php memcache Extension
<?php    $mem = new Memcache;    $mem->connect("192.168.12.201", 13001);    $mem->set(‘key‘,‘This is a test!‘, 0, 60);    $val = $mem->get(‘key‘);    echo $val;?>

Written in the following: we are interested in changing the session to use Memcache to save. PHP itself using the file way, not very good, motionless file size sum on the G. If a friend is now installed in the win environment, please refer to: http://blog.csdn.net/hel12he/article/details/43758733

CentOS installation memcached and memcache extensions for PHP configuration

Related Article

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.