Table of Contents
Installation dependencies
Install memcached extension
Home Backend Development PHP7 How to install memcache and memcached extensions under PHP7

How to install memcache and memcached extensions under PHP7

Jun 25, 2021 am 09:15 AM
memcache memcached 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.

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Memcache in PHP development? How to use Memcache in PHP development? Nov 07, 2023 pm 12:49 PM

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

What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? What should I do if the plug-in is installed in php7.0 but it still shows that it is not installed? Apr 02, 2024 pm 07:39 PM

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.

PHP Server Environment FAQ Guide: Quickly Solve Common Problems PHP Server Environment FAQ Guide: Quickly Solve Common Problems Apr 09, 2024 pm 01:33 PM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

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

Which one is better, php8 or php7? Which one is better, php8 or php7? Nov 16, 2023 pm 03:09 PM

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.

Record once and use strace to diagnose the problem of PHP occupying too much system resources. Record once and use strace to diagnose the problem of PHP occupying too much system resources. May 03, 2024 pm 04:31 PM

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-

How to make PHP5.6 and PHP7 coexist through Nginx configuration on the same server? How to make PHP5.6 and PHP7 coexist through Nginx configuration on the same server? Apr 01, 2025 pm 03:15 PM

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...

See all articles