I'm trying to store PHP7 $_SESSION['...']
information (from an ElasticBeanstalk app) in a centralized Memcached cluster via AWS Elasticache.
Here are the steps I am taking:
- Note the ElasticBeanstalk's security group
- In the AWS console, navigate to Services > ElastiCache and click "Get Started Now"
- Under "Cluster engine" check "Memcached"
- Under "Memcached settings" enter "sessions" for "Name" and leave all default settings (will be more specific after I'm done with this proof of concept)
- Now on the Dashboard, wait until "status" is "created" and then expand the row and note the public dns (note that steps will be added to add the security group from step 1 will be here as well... I am doing this now btw)
- On your local machine, create a directory called
sample
- Under
sample
, create.ebextensions/elasticcache-sessions.config
with the following content:
files:
"/etc/php.d/project.ini" :
mode: "000644"
owner: root
group: root
content: |
[Session]
session.save_handler = memcached
session.save_path = "tcp://dns-noted-from-step-4:11211"
Still under
sample
, createindex.php
with the following content:header('Content-Type: text/plain'); session_start(); if(!isset($_SESSION['visit'])) { echo "This is the first time you're visiting this server\n"; $_SESSION['visit'] = 0; } else echo "Your number of visits: ".$_SESSION['visit'] . "\n"; $_SESSION['visit']++; echo "Server IP: ".$_SERVER['SERVER_ADDR'] . "\n"; echo "Client IP: ".$_SERVER['REMOTE_ADDR'] . "\n"; print_r($_COOKIE);
Compress the
sample
directory as a.zip
file and deploy it to the Beanstalk application noted in step 1- Visit /sample/index.php in your browser and...
PHP Fatal error: session_start(): Failed to create session ID: memcached.
is thrown.
If I SSH into an EC2 instance belonging to Beanstalk, I can see that PHP7 is installed. If I php --ini | grep memcached
, there are results. I also am able to verify that the ebextension I wrote is getting applied. Ready to bang my head against the wall here. Your help is appreciated.