Home >Backend Development >PHP7 >How to install memcache and memcached extensions under PHP7

How to install memcache and memcached extensions under PHP7

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-06-25 09:15:472345browse

Memcache and memcached are both PHP extensions of the Memcached server. Among them, memcache appeared earlier than memcached, so some old code may still use memcache extension. You can install one according to your needs. Here are the installation methods for both.

How to install memcache and memcached extensions under PHP7

Memcached is a high-performance distributed memory cache server, and PHP memcache and memcached are both PHP extensions of the Memcached server. Among them, memcache appeared earlier than memcached, so some old code may still use memcache extension. Memcached appeared later, and most frameworks support memcached, which is now relatively popular.

Installation dependencies

The first is memcached. This extension requires the libmemcached client library, otherwise the following error will occur

checking for libmemcached location... configure: error: memcached support requires libmemcached. Use –with-libmemcached-dir=

to specify the prefix where libmemcached headers and library are located
ERROR: `/var/tmp/memcached/configure –with-libmemcached-dir=no' failed

Can be installed by the following method

[root@lnmp lnmp.cn]# yum install libmemcached libmemcached-devel

And memcache The module uses the function zlib to support data compression, so installing this module requires installing the Zlib module. Otherwise, the following error will occur:

checking for the location of zlib… configure: error: memcache support requires ZLIB. Use –with-zlib-dir=

to specify prefix where ZLIB include and library are located

ERROR: `/var/tmp/memcache/configure –enable-memcache-session=No' failed

You can use yum to install it as follows:

[root@lnmp lnmp.cn]# yum install zlib zlib-devel

Install memcached extension

Try to install with PECL, the address of memcached on PECL Yes:

https://pecl.php.net/package/memcached

[root@lnmp lnmp.cn]# pecl install memcached

pecl/ memcached requires PHP (version >= 5.2.0, version

No valid packages found

install failed

[root@localhost vagrant]

#The prompt is obvious, the memcached extension on PECL only supports versions above PHP 5.2 and below 6.00. Not updated to PHP7 yet. But fortunately, you can find their link on github on PECL's memcached page:

https://github.com/php-memcached-dev/php-memcached

here The code already has a branch that supports PHP7. Here, download the source code to the ext directory of the PHP source code:

[root@lnmp lnmp.cn]# cd /usr/local/src/php-7.0.8/ext/

[root@lnmp ext]# git clone https://github.com/php-memcached-dev/php-memcached memcached

[root@lnmp ext]# cd memcached/

checkout to php7 branch:

[root@lnmp memcached]# git checkout php7

Branch php7 set up to track remote branch php7 from origin.

Switched to a new branch 'php7'

[root@lnmp memcached]

#Use phpize to install, my PHP is installed under /usr/local/php7

[root@lnmp memcached]# /usr/local/php7/bin/phpize

[root@lnmp memcached]# ./configure –with-php-config=/usr /local/php7/bin/php-config

Then make and make install

[root@lnmp memcached]# make

[root@lnmp memcached]# make install

Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/

[root@lnmp memcached]

#You can see that memcached has been installed and the expansion file has been placed in the prompted directory:

[root@lnmp memcached] # ls /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/

memcached.so opcache.a opcache.so

[root@lnmp memcached]

#The last step is to introduce memcached.so in php.ini

[root@lnmp memcached]# vim /usr/local/php7/lib/php .ini

Add:

extension=memcached.so

Remember to reload php-fpm to take effect

[root@lnmp memcached]# systemctl reload php-fpm

Open the phpinfo page and you have seen that the memcached extension has been successfully installed.

How to install memcache and memcached extensions under PHP7


Install memcache extension

Also try to install using PECL:

[root@lnmp memcached]# pecl install memcache

But it also failed

/tmp/pear/temp/memcache/memcache.c:40:40: fatal error: ext/standard/php_smart_str. h: No such file or directory

#include "ext/standard/php_smart_str.h"

                                                                         ##make: *** [memcache.lo] Error 1

ERROR: `make' failed

It seems that the reason is also that PECL does not support the installation of memcache extension under PHP7,

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

has not been updated since 2013. If this road fails, we can only find another way, and try our luck on github. Search pecl memcache

https://github.com/search?utf8=✓&q=pecl memcache&type=Repositories&ref=searchresults

The first one (https://github.com/websupport -sk/pecl-memcache) is what you want, and the code already supports PHP7. Download the code and compile it immediately:

[root@lnmp memcached]# cd ../

[root@lnmp ext]# git clone https://github.com/websupport-sk/pecl-memcache memcache

[root@lnmp ext]# cd memcache

Use phpize installation, the steps are exactly the same as memcached

[root@lnmp memcache]# /usr/local/php7/bin/phpize

[root@lnmp memcache]# ./configure – with-php-config=/usr/local/php7/bin/php-config

[root@lnmp memcache]# make

[root@lnmp memcache]# make install

Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/

[root@lnmp memcache]

#Similar to memcached, introduce memcache.so in php.ini

[root@lnmp memcache]# vim /usr/local/php7/lib/php.ini

Join:

extension=memcache.so

Finally reload php-fpm

[root@lnmp memcache]# systemctl reload php-fpm

You're done, you can see on the phpinfo page that memcahce and memchaced have been successfully installed

Recommended learning:

php Video tutorialHow to install memcache and memcached extensions under PHP7

The above is the detailed content of How to install memcache and memcached extensions under PHP7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete