How do I install PECL 7 modules on Elastic Beanstalk environments running on PHP 8.1 with Amazon Linux 2 stacks?
"I want to install Redis, Memcached, or other modules for PECL 7 on an AWS Elastic Beanstalk environment running on PHP 8.1 using Amazon Linux 2 stacks."
"I want to install Redis, Memcached, or other modules for PECL 7 on an AWS Elastic Beanstalk environment running on PHP 8.1 using Amazon Linux 2 stacks.Short descriptionTo install PECL 7 modules, you must create a configuration file (.ebextension) that includes commands to:Install dependenciesInstall the PECL moduleCreate or modify configuration filesNote: For Amazon Linux 1 stacks, see How do I install PECL 7 modules on Elastic Beanstalk environments running on PHP with Amazon Linux 1 stacks?Resolution1.    Set up the .ebextensions directory in the root of the source bundle of your application. For example:|-- .ebextensions|        |-- redis/memcached.config|        |-- other .config files|-- other application filesFor more information, see Advanced environment customization with configuration files (.ebextensions).Note: All configuration files are stored in the .ebextensions folder. The Elastic Beanstalk environment uses only files that end with the .config extension.2.    In the .ebextensions directory, create a configuration file that includes the following commands for your module.For Redis modules:commands:  01_install_redis:    command: /usr/bin/yes 'no' | /usr/bin/pecl install redis    test: '! /usr/bin/pecl info redis'  02_remove_extension:    command: /bin/sed -i -e '/extension="redis.so"/d' /etc/php.ini  03_create_conf:    command: /bin/echo 'extension="redis.so"' > /etc/php.d/41-redis.iniThe Redis configuration file does the following:Installs the Redis module and tests for installation success (01_install_redis)Removes the Redis extension from the /etc/php.ini file (02_remove_extension)Creates a configuration file called 41-redis.ini at /etc/php.d/ (03_create_conf)For Memcached modules:packages:  yum:    libmemcached-devel: []commands:  01_install_memcached:    command: /usr/bin/yes 'no'| /usr/bin/pecl install memcached    test: '! /usr/bin/pecl info memcached'  02_remove_extension:    command: /bin/sed -i -e '/extension="memcached.so"/d' /etc/php.ini  03_create_conf:    command: /bin/echo 'extension="memcached.so"' > /etc/php.d/41-memcached.iniThe Memcached configuration file does the following:Installs the Memcached module and tests for installation success (01_install_memcached)Removes the Redis extension from the /etc/php.ini file (02_remove_extension)Creates a configuration file called 41-memcached.ini at /etc/php.d/ (03_create_conf)Note: Always test a new .ebextension before adding to a production environment.Follow"