简体   繁体   中英

Elasticache session_start(): Failed to create session ID

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:

  1. Note the ElasticBeanstalk's security group
  2. In the AWS console, navigate to Services > ElastiCache and click "Get Started Now"
  3. Under "Cluster engine" check "Memcached"
  4. 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)
  5. 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)
  6. On your local machine, create a directory called sample
  7. 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"

  1. 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);
  2. Compress the sample directory as a .zip file and deploy it to the Beanstalk application noted in step 1

  3. 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 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM