Installation of memcached under Linux

Source: Internet
Author: User
Tags install php memcached php memcached aliyun

System mirroring and environmental requirements:

1) for the Windows Series version and developers of the relevant tutorials, please refer to this Article 1.0 start the installation steps

2) for Centos 6 series and Aliyun Linux 6 series, please refer to this Article 2.0 to start the installation step

3) Centos 5 Series and Aliyun Linux 5 Series version, please refer to this article 3.0 to start the installation steps

4) for series versions of Ubuntu Debian, please refer to the 4.0 installation steps in this article

Note: If you already have a PHP memcache environment, please note some tips in the tutorial, in order to avoid the production environment is overwritten, resulting in business is not available, before upgrading and re-compiling environment, please do a good environment backup!

1.0 Installation Steps

If the standard PHP memcached extension can not be successfully built, you may consider the form of manual package to access the OCS, connection method please refer to the following link, the sample code is very simple, and PHP memcached is the difference between the only support the mainstream interface, you need to supplement some specific interface, The installation and use methods are as follows:

Https://github.com/ronnywang/PHPMemcacheSASL

2.0 Installation Steps

CentOS and Aliyun Linux 6 series versions

First, you need to verify that components such as gcc-c++ are installed and can be used, if not,

Yum  Install gcc+ gcc-c++

Use Gcc–v to see if the version is 4.2 (inclusive) "must be installed GCC gcc to be greater than or equal to 4.2"

1) Rpm–qa | grep PHP to see if there is a PHP environment in the system, if not, install it, if there is PHP, do not install. It is recommended to use php5.3 "with" version PHP5.2 some version of the source code will have Zend_parse_parameters_none function error, if you need to use the official PHP-related documents, "including Source compiled PHP"

Yum Install Php-devel,php-common,php-cli  

"As source code compiled, please follow the official PHP compilation upgrade Method"

2) Install SASL related environment

Yum install cyrus-sasl-plain CYRUS-SASL  cyrus-sasl-devel  cyrus-sasl-lib

"Please check to see if any of these packages have been installed, and if so, you do not need to install them."

3) Install Source package libmemcached "recommended version libmemcached-1.0.16"

Please first detect if there are installed these packages "contains source package" If there is no need to install

wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz Tar zxvf LIBMEMCACHED-1.0.16.TAR.GZCD libmemcached-1.0.16./configure--prefix=/usr/local/libmemcached-- Enable-saslmakemake INSTALLCD.

4) Install Source package memcached "recommended version is memcached-2.2.0"

Before installing memcached, you need to confirm whether there are zlib-devel packages that need to be executed

Yum Install Zlib-devel

Please first detect if there are installed Memcached client Package "contains source package" If there is no need to install, but need to recompile to increase-ENABLE-MEMCACHED-SASL this extension

wget Http://pecl.php.net/get/memcached-2.2.0.tgztar ZXVF MEMCACHED-2.2.0.TGZCD Memcached-2.2.0phpize (if there are two sets of PHP environments in the system, you need to call the command/usr/bin/phpize absolute path, which is the PHP environment path using OCS)./configure-- With-libmemcached-dir=/usr/local/libmemcached--ENABLE-MEMCACHED-SASL (Note this parameter) Makemake install

Finally modify the php.ini file (locate find the file, if the system has two sets of PHP environment, you need to find the use of the OCS PHP environment path, corresponding to modify), increase

EXTENSION=MEMCACHED.SOMEMCACHED.USE_SASL = 1

Depend on:

The Memcached 2.2.0 extension must use a library of libmemcached 1.0.x, and libraries less than 1.0 will no longer compile successfully. GCC requirements are above 4.2 when compiling libmemcached.

Use the last Test code of this page to test if the environment is deployed successfully, modify the corresponding address port username and password in the code

3.0 Installation Steps

CentOS and Aliyun Linux 5 Series version "64-bit version"

First, you need to verify that components such as gcc-c++ are installed.

Yum  Install gcc+ gcc-c++

1) Rpm–qa | grep PHP to see if there is a PHP environment in the system, if not, install it, if there is PHP do not install! It is recommended to use php5.3 "with" version PHP5.2 some version of the source code will have Zend_parse_parameters_none function error, if you need to use the official PHP-related documents, "including Source compiled PHP"

Yum Install php53 Php53-devel

2) Install SASL related environment

Yum install cyrus-sasl-plain CYRUS-SASL  cyrus-sasl-devel  cyrus-sasl-lib

3) Install Source package libmemcached "recommended version libmemcached1.0.2"

Please first detect if there are installed these packages "contains source package" If there is no need to install

wget HTTP://LAUNCHPAD.NET/LIBMEMCACHED/1.0/1.0.16/+DOWNLOAD/LIBMEMCACHED-1.0.16.TAR.GZTAR-ZXVF LIBMEMCACHED-1.0.16.TAR.GZCD LIBMEMCACHED-1.0.16CD libmemcached-1.0.16./configure--prefix=/usr/local/ Libmemcached--enable-saslmakemake INSTALLCD.

4) Install Source package memcached "recommended version memcached2.0"

Before installing memcached, you need to confirm whether there are zlib-devel packages that need to be executed

Yum Install Zlib-devel

Please first detect if there are installed Memcached client Package "contains source package" If there is no need to install, but need to recompile to increase-ENABLE-MEMCACHED-SASL this extension

wget HTTP://PECL.PHP.NET/GET/MEMCACHED-2.2.0.TGZTAR-ZXVF MEMCACHED-2.0.0.TGZCD Memcached-2.0.0phpize (if there are two sets of PHP environment in the system, you need absolute path to call the command/usr/bin/phpize, the path is the PHP environment path using OCS, please execute phpize within the memcached source directory). Configure--with-libmemcached-dir=/usr/local/libmemcached--ENABLE-MEMCACHED-SASL (note this parameter) makemake instal

Finally modify the php.ini file (locate find the file, Yum installed in general in/etc/php.ini if the system has two sets of PHP environment, you need to find the use of the OCS PHP environment path, corresponding modification), increase

extension=memcached.so MEMCACHED.USE_SASL = 1

Execute php–m |grep memcached If the result is memcache indicates that the environment has been supported Memcache

Use the last Test code of this page to test if the environment is deployed successfully, modify the corresponding address port username and password in the code

4.0 installation Steps

1) Change Ubuntu source

Scenario One: Vim/etc/apt/source.list

Add content to the front

deb http://mirrors.aliyun.com/ubuntu/precise main restricted universe Multiversedeb http://mirrors.aliyun.com/ubuntu/precise-security main restricted universe Multiversedeb/HTTP Mirrors.aliyun.com/ubuntu/precise-updates main restricted universe Multiversedeb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/precise-backports main Restricted Universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/precise main restricted universe MULTIVERSEDEB-SRC http://mirrors.aliyun.com/ubuntu/precise-security main restricted universe multiversedeb-src http ://mirrors.aliyun.com/ubuntu/precise-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ ubuntu/precise-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ Precise-backports main restricted Universe multiverseapt-get Update//Update one of the following tables 

Scenario Two: wget http://oss.aliyuncs.com/aliyunecs/update_source.tgz download Update_source compressed package to execute the permissions chmod 777 file name, Then execute the script to make the automatic change source operation

2) configuration via Ape-get gcc,g++

First, you need to use the Dpkg–s installation package name "such as Dpkg–s gcc" to verify that components such as gcc-c++ are installed, such as not performing

Apt-get BUILD-DEP gccapt-get Install build-essentialapt-get install Pkg-config

3) Install PHP5, Php5-dev

First, you need to use the Dpkg–s installation package name "such as Dpkg–s PHP" to verify that the installation of components such as PHP is not executed

Apt-get install php5 php5-dev  "also automatically installs PHP5-CLI and Php5-common"

4) Installation Configuration SASL support

First, you need to use the Dpkg–s installation package name "For example Dpkg–s LIBSASL2" to verify that components such as LIBSASL2 CLOOG-PPL are installed such as do not

Apt-get Install  Libsasl2-dev cloog-pplcd/usr/local/src

5) Install the specified version of Libmemcache

Please first detect if there are installed these packages "contains source package" If there is no need to install

wget HTTPS://LAUNCHPAD.NET/LIBMEMCACHED/1.0/1.0.16/+DOWNLOAD/LIBMEMCACHED-1.0.16.TAR.GZTAR-ZXVF LIBMEMCACHED-1.0.16.TAR.GZCD libmemcached-1.0.16./configure--prefix=/usr/local/libmemcachedmakemake INSTALLCD.

6) Install the specified version of memcached

Please first detect if there are installed Memcached client Package "contains source package" If there is no need to install, but need to recompile to increase-ENABLE-MEMCACHED-SASL this extension

wget Http://pecl.php.net/get/memcached-2.2.0.tgztar zxvf memcached-2.2.0.tgzcd memcached-2.2.0phpize5./configure-- with-libmemcached-dir=/usr/local/libmemcached--enable-memcached-saslmakemake Install

7) Configure PHP to support memcached and then test

echo "extension=memcached.so" >>/etc/php5/conf.d/pdo.iniecho "MEMCACHED.USE_SASL = 1" >>/etc/php5/conf.d /pdo.ini

Php-m |grep Mem

Memcached "shows that the component represents an installation complete"

Configuration complete

Code examples such as the following

1. Example 1: The most basic connection of OCS and Set/get operation:

$connect = new Memcached;  Declares a new Memcached link $connect->setoption (memcached::opt_compression, false); Turn off compression function $connect->setoption (Memcached::opt_binary_protocol, true); Using Binary Binary protocol $connect->addserver (' aaaaaaaaaa.m.yyyyyyyyyyy.ocs.aliyuncs.com ', 11211); Add the OCS instance address and port number $connect->setsaslauthdata (' Aaaaaaaaaa, ' password '); Set the OCS account password to authenticate, if the password-free feature is turned on, you do not need this step $connect->set ("Hello", "World"); Echo ' Hello: ', $connect->get ("Hello"); Connect->quit ();

2. Example 2: Caching an array in OCS

$connect = new Memcached; Declares a new Memcached link $connect->setoption (memcached::opt_compression, false); Turn off the compression function $connect->setoption (Memcached::opt_binary_protocol, true);//Use Binary Binary protocol $connect->addserver (' Xxxxxxxx.m.yyyyyyyy.ocs.aliyuncs.com ', 11211);//Add OCS instance address and port number $connect->setsaslauthdata (' xxxxxxxx ', ' bbbbbbbb ' )///Set the OCS account password to authenticate, if the password-free feature is turned on, this step is not required. $user = Array (    "name" = "OCS",    "age" = 1,    "sex" = "male");//Declare a set of arrays  $expire = 60;//Set Expiration Time test ($connect->set (' your_name ', $user, $expire), True, ' set cache failed '), if ($connect->get (' your_name ')) {$result = $connect->get (' your_name ');} Else{echo "Return code:", $connect->getresultcode (), echo "RETUCN Message:", $connect->getresultmessage (); If an error occurs, parse the return code $result= "";} Print_r ($result); $connect->quit (); function test ($val, $expect, $msg) {     if ($val! = $expect) throw new Exception ($ msg);}

3. Example 3:ocs used in conjunction with MySQL database

$connect = new Memcached; Declare a new Memcached link $connect->setoption (memcached::opt_compression, false);//Turn off the compression function $connect->setoption ( Memcached::opt_binary_protocol, True);//Use Binary Binary protocol $connect->addserver (' xxxxxx.m.yyyyyyyy.ocs.aliyuncs.com ', 11211);//Add instance Address port number $connect->setsaslauthdata (' xxxxxx ', ' my_passwd ');//Set the OCS account password to authenticate, if the password-free function is turned on, then this step is not required $user = Array ("name" = "OCS", "age" = 1, "sex" = "male");  Defines a set of array if ($connect->get (' your_name ')) {$result = $connect->get (' your_name ');  Print_r ($result); echo "Found in OCS, get data from OCS";  If data is obtained, this data is printed from the OCS exit;  }else{echo "Return code:", $connect->getresultcode (); echo "RETUCN Message:", $connect->getresultmessage ();//Throw Code return code $db _host= ' zzzzzz.mysql.rds.aliyuncs.com ';         Database address $db _name= ' my_db ';    Database name $db _username= ' Db_user ';  Database user name $db _password= ' db_passwd ';//database user password $connection =mysql_connect ($db _host, $db _username, $db _password); if (!mysql_select_db ($db _name, $Connection) {echo ' Could not select database ';//The connection is unsuccessful and throws an error message exit;  } $sql = "Select Name,age,sex from test1 WHERE name = ' OCS '";  $result = mysql_query ($sql, $connection); while ($row = Mysql_fetch_assoc ($result)) {$user = array ("name" + = $row ["name"], "age" and "age" = $row ["    "]," sex "= $row [" Sex "],); $expire = 5; Sets the expiration time of the data in the cache test ($connect->set (' your_name ', $user, $expire), True, ' set cache failed ');  Write to the OCS cache} mysql_free_result ($result); Mysql_close ($connection);} Print_r ($connect->get (' your_name ')); Print out the retrieved data echo "not Found in Ocs,get data from MySQL"; Confirm data obtained from the database $connect->quit (); function test ($val, $expect, $msg) {if ($val! = $expect) throw new Exception ($msg);}

Source: https://help.aliyun.com/knowledge_detail/5974954.html

Installation of memcached under Linux

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.