Question

Elastic Beanstalk does not, by default, install the ElastiCache Cluster Client PHP module. This is needed to connect to an ElastiCache node cluster. Reading around, most of the instructions relate to creating an ElastiCache resource (which I assume will also install the PHP module on the Elastic Beanstalk). I want to install the PHP module without creating the resource as I want to use an existing cluster. (64bit Linux PHP5.5)

Was it helpful?

Solution

The module is not installed by default in Beanstalk nor any EC2 instances. You have to do this yourself. This also is something completely different than creating a resource. You can do one without the other.

The ElastiCache Cluster Client for PHP is an extension that you can install via pecl on your instances. You can do this manually but if the instance is ever destroyed you have to do this again. Therefore it is much better to include the extension's install procedure as part of your deployment process. In a beanstalk app you can do this by adding configurations files in your .ebextensions dir.

For example, create these two files. I took these from an actual config file:

#.ebextensions/01fileselasticachephp.config
files:
  "/tmp/AmazonElastiCacheClusterClient-latest-PHP54-64bit.tgz" :
    mode: "000777"
    owner: ec2-user
    group: ec2-user
    source: http://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-5.4/latest-64bit

#.ebextensions/02setupelasticachephp.config
commands: 
  01install: 
    command: "pecl install /tmp/AmazonElastiCacheClusterClient-latest-PHP54-64bit.tgz"

The actual name of the files don't matter. They are for your own organization purposes. Anything in that directory with a .config extension will be executed in alphabetical order, that's why you want to prefix your files with a number so that they get executed in the right order: first download the extension and then install it. Mind you that you can also do it all at once in one file. I split it in two because because my actual config files were a lot bigger.

Once you have these files in place do a deployment and the Elastic Cache Cluster Client will be installed.

Note that at the time I deployed this, only the 5.4 client was available that's why my example shows that. I don't know if there is a 5.5 client so it's up to you to find out. You should only need to change the file name and URL to point to the 5.5 extension and should be all set to go.

OTHER TIPS

UPDATE (as of 10/2020)

The solution above didn't work for me with the current software versions, but it definitely pointed me in the right direction. What didn't work was specifically the pecl install command (even using pecl7): it always threw the error "could not extract the package.xml file from [...]" and I couldn't find a solution for it.

So here's the config file that worked for me:

commands:
  02-get-file:
    command: "wget https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-7.3/latest-64bit"
  02-untar:
    command: "sudo tar -zxf latest-64bit amazon-elasticache-cluster-client.so"
  03-move-file:
    command: "sudo mv amazon-elasticache-cluster-client.so /usr/lib64/php/7.3/modules/"
  04-create-ini:
    command: "grep -qF 'extension=amazon-elasticache-cluster-client.so' /etc/php-7.3.d/50-memcached.ini || echo 'extension=amazon-elasticache-cluster-client.so' | sudo tee --append /etc/php-7.3.d/50-memcached.ini"
  05-cleanup:
    command: "sudo rm latest-64bit*"
  06-restart-apache:
    command: "sudo /etc/init.d/httpd restart"

Hope this helps other people!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top