In Linux compiling, need gcc,make,cmake,autoconf,libtool and other tools, need to be installed in advance.
memcached installation includes: 1, the installation of the service side, 2, the installation of the client
First, server-side installation
Method One:
Memcached relies on the Libevent library, so we need to install Libevent first.
Assuming that the source is stacked in/usr/local/src
1 cd/usr/local/src2 wget https://github.com/libevent/libevent/releases/ download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz3 tar zxvf libevent-2.0. -stable.tar.gz4 CD libevent-2.0. Stable5 ./configure--prefix=/usr/local/libevent6 make && make Install
Install Memcached Server Edition
1 cd/usr/local/src2 wget http://www.memcached.org/files/ memcached-1.4.33.tar.gz3 tar zxvf memcached-1.4. - . tar.gz 4 CD memcached-1.4. - 5 ./configure--prefix=/usr/local/6 --with-libevent=/usr/loca/libevent 7 make && make install
Start memcached
1 - 11211 -u nobody-vv
The memcached server-side installation starts successfully and outputs the information to the console as indicated above
Want to run the plus-D option in the background
1 - 11211 -u nobody-d
1 ps aux | grep memcached
Whether the query process has memcached
Startup success
Method Two:
1 yum-y install memcached
We're done with this one step.
Start memcached
1 127.0. 0.1 11211 -U root
Show as method two start result
Second, the client installation
Client needs to install Libmemcached Library
1 cd/usr/local/src2 wget https://launchpad.net/libmemcached/1.0/1.0.18/+ download/libmemcached-1.0.18.tar.gz3 tar zxvf libmemcached-1.0. - . tar.gz 4 CD libmemcached-1.0. - 5 ./configure--prefix=/usr/local/libmemcached6 make && make install
Installing the PHP-FPM memcached extension
1 cd/usr/local/src2 wget http://pecl.php.net/get/memcached-2.2.0.tgz 3 Tar zxvf memcached-2.2. 0 . tgz 4 CD memcached-2.2. 0
At this point, we will build the Configure configuration file using the phpize generated when PHP was installed
1 /usr/local/php/bin/2 --with-php-config=/usr/local/php/bin/php-config3 ./configure--with-php-config=/usr/local/php/bin/php-4 --with-libmemcached-dir=/usr/local /libmemcached--disable-memcached-SASL5 make && make install
--WITH-PHP-CONFIG specifies Php-config, which is the same directory as Phpize,
--with-libmemcached-dir Specify libmemcached installation directory, just now we--prefix that directory,
--DISABLE-MEMCACHED-SASL indicates that our system does not support sasl.h
If the installation is successful, you will be prompted: Installing Shared extension:/usr/local/php/lib/extensions/no-debug-non-zts-20160524/class information
Next, we edit the PHP config file php.ini and add the php-memcached extension to the configuration file.
In php.ini, add the following:
1 extension=memcached.so
Finally restart Nginx and PHP-FPM
After restarting, check whether the installation is complete php-memcached extension
Create a test.php file in the Nginx Web root directory
1 <? PHP 2 phpinfo (); 3 ?>
Enter the server IP address in the browser
The above instructions memcached PHP extension installed successfully.
Other PHP extensions can be installed according to this method.
Simple operation with PHP memcached
In fact, memcached and Redis, MySQL is no different, the same database, (Redis is a non-relational database, MySQL is a relational database), so the use is similar to the same command-line use and PHP operation to use, More commands about memcached you can do it yourself Baidu.
1<?PHP2 3$mem =NewMemcached ();//instantiate the Memcached class4$server =Array (5Array'127.0.0.1',11211), 6 );7$memaddservers ($server);8 9$memSet('name','Zhangsan', the);////Set cache value, valid for 3,600 seconds, if the valid time is set to 0, it means that the cached value is permanent (before system restart)TenEcho $memGet('name'); One A?>
Reference: http://blog.csdn.net/baidu_30000217/article/details/51494007
Linux PHP installation memcached extensions