← ServerPilot Docs

How to Install the PHP Memcached Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "7.4" or "8.3"). To install a PECL extension for multiple PHP versions, repeat the PECL extension installation for each PHP version.
These PHP extensions provide client access to the Memcached server. They are not the Memcached server itself.

You also need to install the Memcached server to use Memcached with your PHP apps.

Memcached

Installing Memcached on PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, and 8.3

To install this extension for PHP X.Y, SSH in to your server as root and run the following commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libmemcached-dev
sudo peclX.Y-sp install memcached

When you are shown the following prompts, you will want to press Enter to select the default option for all of the prompts except for enable sasl. When shown the enable sasl prompt, input "no", then press Enter.

zlib directory [no] :

use system fastlz [no] :

enable igbinary serializer [no] :

enable msgpack serializer [no] :

enable json serializer [no] :

enable server protocol [no] :

enable sasl [yes] : no

enable sessions [yes] :

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root

sudo bash -c "echo extension=memcached.so > /etc/phpX.Y-sp/conf.d/memcached.ini"
sudo service phpX.Y-fpm-sp restart

Installing Memcached on PHP 5.4, 5.5, and 5.6

To install this extension, SSH in to your server as root and run the following commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libmemcached-dev
sudo pecl5.X-sp install memcached-2.2.0

When you are shown the prompt

libmemcached directory [no] :

type or paste the following text exactly as shown and press Enter.

no --disable-memcached-sasl

That is, the entire line you'll see on your screen will be as follows once you press Enter.

libmemcached directory [no] : no --disable-memcached-sasl

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root

sudo bash -c "echo extension=memcached.so > /etc/php5.X-sp/conf.d/memcached.ini"
sudo service php5.X-fpm-sp restart

Verifying the Installation

You can verify the memcached extension is installed correctly by running this command:

phpX.Y-sp -i | grep -i "memcached support"

You should see output like the following:

memcached support => enabled

Uninstalling the Memcached Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/memcached.ini
sudo peclX.Y-sp uninstall memcached

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart

Memcache

Two different extensions are available that provide access to Memcached from within your PHP scripts. One is named memcache and the other is named memcached. This extension (the one named memcache with no d on the end) is no longer maintained.
For instructions on the memcached extension (with a d on the end), see the section above.

To install this extension, SSH in to your server as root and run the following command:

sudo apt-get install gcc make autoconf libc-dev pkg-config
sudo apt-get install zlib1g-dev
sudo pecl5.X-sp install memcache

Once installed, create a configuration file for the extension and restart PHP.

sudo bash -c "echo extension=memcache.so > /etc/php5.X-sp/conf.d/memcache.ini"
sudo service php5.X-fpm-sp restart

The memcache extension does not support PHP 7. For PHP 7 support, use the memcached extension shown above.

Last updated: November 20, 2023

Launch your first site in 5 minutes