Install Memcached in PHP8.2-FPM+ With NGINX Ubuntu

0. Don’t forget to install pear for pecl call.

sudo apt-get install -y php8.2-pear

1. After You install the php8.2-fpm you run this command:

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 pecl install memcached

RESULT:

WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/memcached can optionally use PHP extension "igbinary" (version >= 2.0)
pecl/memcached can optionally use PHP extension "msgpack" (version >= 2.0)
downloading memcached-3.2.0.tgz …
Starting to download memcached-3.2.0.tgz (90,722 bytes)
…………………done: 90,722 bytes
18 source files, building
running: phpize

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.

Configuring for:
PHP Api Version: 20220829
Zend Module Api No: 20220829
Zend Extension Api No: 420220829
libmemcached directory [no] : no
zlib directory [no] : no
use system fastlz [no] : no
enable igbinary serializer [no] : no
enable msgpack serializer [no] : no
enable json serializer [no] : no
enable server protocol [no] : no
enable sasl [yes] : non
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/php/8.2/fpm/php.ini"
sudo bash -c "echo 'extension=memcached.so' >> /etc/php/8.2/cli/php.ini"
sudo service php8.2-fpm restart

Reference Link

Installing and Configuring Memcached with PHP8.2

Memcached is a high-performance, distributed memory caching system designed to speed up dynamic web applications by alleviating database load. It is widely used to enhance the performance of web-based applications by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. This article will guide you through the process of installing Memcached on your server and integrating it with PHP.

Read also How to Install Memcached in CodeIgniter Framework

After installing php8.2 with nginx you might install the main memcached and the memcached for PHP.

sudo apt-get update
sudo apt-get install memcached
sudo apt-get install php8.2-memcached

Conclusion: You have successfully installed and configured Memcached with PHP. Memcached is a powerful tool for improving the performance of your PHP applications. It’s easy to set up and integrate, and it can significantly reduce the load on your database by caching frequently accessed data.

Additional Tips:

  • Regularly monitor your Memcached usage.
  • Secure your Memcached server, especially if it’s on a public network.
  • Keep your software updated for security and performance improvements.
Exit mobile version