Current Location: Home> Latest Articles> Complete Guide to Installing memcache and memcached Extensions in PHP7

Complete Guide to Installing memcache and memcached Extensions in PHP7

gitbox 2025-08-07

Preparation

Before installing the memcache and memcached extensions, make sure you have completed the following prerequisites:

  • PHP 7 is installed on your server and meets the extension requirements.
  • Memcached server is installed and running, as the extensions depend on it.

Installing the memcache Extension

Download and Install the libmemcache Library

First, you need to install the libmemcache library. Download the latest stable version from the official libmemcache website, extract it, navigate to the directory, and run:

./configure
make
sudo make install

If libmemcache is already installed on your system, you can skip this step.

Install the PHP memcache Extension

Run the following command to install the memcache extension:

pecl install memcache

After installation, add the following line to your php.ini file:

extension=memcache.so

Save the file and restart your web server to apply the changes.

Installing the memcached Extension

Download and Install the libmemcached Library

Similar to memcache, installing the memcached extension requires the libmemcached library. Download the stable version, extract it, then run:

./configure
make
sudo make install

If the library is already installed, you may skip this step.

Install the PHP memcached Extension

Use the following command to install:

pecl install memcached

Once installed, add the following line to your php.ini file:

extension=memcached.so

Save and close the file, then restart your web server.

Verifying the Installation

You can verify that the extensions are working by creating a phpinfo file. Create a file named phpinfo.php with the following content:

<?php
phpinfo();
?>

Save and access the file in your browser. If you see information related to memcache and memcached, the installation was successful.

Conclusion

By following these steps, you have successfully installed memcache and memcached extensions in PHP7 and verified their functionality. With these caching extensions enabled, you can significantly improve the performance and response speed of your PHP applications.