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:
sample
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
, create index.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
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
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.
We beat our heads on a wall with the same exact problem for a long time. We found that Apache just wasn't making the network request out to Elasticache.
So, digging into SELinux, found that running this would fix it:
setsebool -P httpd_can_network_connect 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.