Installing the PHP memcache server and its clients under Linux (CentOS 6.4) (Detailed tutorial)

Source: Internet
Author: User
Tags zts

Objective

In the construction of personal blog, because no framework, pure manual code front desk and backstage, resulting in a lot of problems, one of the problems is that the MySQL connection caused by the page corresponding speed abnormally low. After querying a variety of ways, you can only consider using the memcache cache. After referring to a lot of articles, finally succeeded in installing Memcache under centos6.4. Because of the discovery during the installation process, many articles in some details are not explained clearly, causing me to stuck on a problem. To help other kids who may have had the same problems as I have, I'm going to introduce my installation process in detail, not ctrl+c,ctrl+v. Hope to be of help to everyone. (partial reference www.52weis.com)

One. memcached Installation

First of all, Memcache is divided into server and client. Memcached is a server that is installed on servers in the service side, and the following is a client, a server installed in a PHP environment.

1, memcached Download:

Http://memcached.org/downloads (official website), the author downloaded the version is memcached-1.4.21.tar.gz (2014-10-12)

2, Libevent Download:

Because libevent need to use, so need to download, if you have to do not download. The address is: http://www.monkey.org/~provos/libevent/. This is the dependency that memcached installation requires

3, Libevent Installation:

Since these two installations are not very complex, it is only a list of commands (decompression is not introduced, should all know):

Enter the Libevent installation directory,

./configure--prefix=/usr/local/libevent (/usr/local/libevent is the installation path)

Then make, make install

4, memcached Installation:

Unzip, enter the directory, install:

./configure--prefix=/usr/local/memcached

Then make, make install

Second, install php memcache extension

  1. Download memcache (client):

The address is Http://pecl.php.net/package/memcache, the author of the next version is 3.0.8

2. Installation:

Into the extracted directory, the author is/usr/local/memcache, PHP installation directory in/usr/local/php

Execute command

    /usr/local/php/bin/phpize (executed under the Memcache directory)

And then execute

./configure--enable-memcache--with-php-config=/usr/local/php/bin/php-config--with-zlib-dir,

make, make install.

After successful installation, the following information will be displayed, recorded, and so on, as follows:

    /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

And then

Change the extension_dir in php.ini = "./" To

Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"

And then

Add a row to load the memcache extension: extension=memcache.so

Note that in the/usr/local/memcache directory, you may not see configure, so you will be confused about how to execute it./configure? In fact, configure is generated by PHP, the name is this command

/usr/local/php/bin/phpize. This many tutorials are not clear, the author also found a lot of information in understand configure how to come.

Three, the basic setting of memcached:

1. Start the server side of the memcache:
/usr/local/bin/memcached-d-M 10-u root-l 192.168.0.200-p 11211-c 256-p/tmp/memcached.pid

Here is an explanation of the startup parameters:

The-D option is to start a daemon,

-M is the amount of memory allocated to Memcache, in megabytes, default 64MB

-M return error on memory exhausted (rather than removing items)

-U is the user running memcache, and if it is currently root, you need to specify the user with this parameter.

-L is the server IP address of the listener, which defaults to all network cards.

-P is the port that sets the TCP listener for memcache, preferably a port above 1024

The-c option is the maximum number of concurrent connections that are running, by default 1024

-P is a PID file that is set to save Memcache

-F <factor> Chunk size growth factor (default:1.25)

-I Override the size of each slab page. Adjusts max item size (new 1.4.2 version)

Running PS aux|grep memcached

If there are memcached related processes, then the success!

  

2. If you want to end the memcache process, execute:

Kill ' Cat/tmp/memcached.pid '

3. Restart Apache:

Service httpd Restart

  

4. Testing

Run the following file, if there is a result the output is built successfully
< PHP
$mem = new Memcache;
$mem->connect ("127.0.0.1", 11211); The listening port set above the//11211
$mem->set (' key ', ' it does work! ');
$val = $mem->get (' key ');
Echo $val;
?>

Iii. concluding remarks

In the installation of various software, due to different circumstances, resulting in a variety of installation failure is very normal, the author once in the installation of PHP, replace a machine loaded PHP, according to the original method of failure, are environmental problems. So I hope that when we encounter problems, as far as possible to reference the information on the Internet, if you find a lot of information to solve the problem, I hope to write down the experience, and everyone to share, rather than pure copy and paste, to avoid other people waste too much time on the search answer. This is also my intention to write this tutorial, or to share more. (see www.52weis.com for more details)

Iv. References:

Linux under Memcache installation

Linux installation PHP and memcache process logging

php5.3.x Support Memcache under CentOS

Hope the above is helpful to everyone

 

Installing the PHP memcache server and its clients under

Linux (CentOS 6.4) (detailed tutorial)

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.