How to install memcache and memcached extensions under PHP7
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.
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.
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 memcache]# /usr/local/php7/bin/phpize[root@lnmp memcache]# ./configure – with-php-config=/usr/local/php7/bin/php-config[root@lnmp ext]# cd memcache
Use phpize installation, the steps are exactly the same as memcached
[root@lnmp memcache]# vim /usr/local/php7/lib/php.ini[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
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 installedRecommended learning:
php Video tutorial
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Compared with PHP7, PHP8 has some advantages and improvements in terms of performance, new features and syntax improvements, type system, error handling and extensions. However, choosing which version to use depends on your specific needs and project circumstances. Detailed introduction: 1. Performance improvement, PHP8 introduces the Just-in-Time (JIT) compiler, which can improve the execution speed of the code; 2. New features and syntax improvements, PHP8 supports the declaration of named parameters and optional parameters, making functions Calling is more flexible; anonymous classes, type declarations of properties, etc. are introduced.

Local environment: redhat6.7 system. nginx1.12.1, php7.1.0, the code uses the yii2 framework problem: the local web site needs to use the elasticsearch service. When PHP uses elasticsearch built on a local server, the local load is normal. When I use AWS's elasticsearch service, the load on the local server is often too high. Check the nginx and php logs and find no exceptions. The number of concurrent connections in the system is also not high. At this time, I thought of a strace diagnostic tool that our boss told me. Debugging process: Find a php sub-process idstrace-

Running multiple PHP versions simultaneously in the same system is a common requirement, especially when different projects depend on different versions of PHP. How to be on the same...
