Elasticache session_start (): Failed to create session id

I am trying to store PHP7 information $_SESSION['...'](from an ElasticBeanstalk application) in a centralized Memcached cluster through AWS Elasticache.

Here are the steps I'm taking:

  • Pay attention to the ElasticBeanstalk security group
  • In the AWS console, go to Services> ElastiCache and click Start Now.
  • In the "Cluster engine" section, check the "Memcached" box.
  • In the “Memcached Settings” section, enter “sessions” for “Name” and leave all the default settings (will be more specific after I have finished this proof of concept)
  • Now in the dashboard, wait until the “status” is “created”, and then expand the line and pay attention to the public dns (note that the steps will be added to add the security group from step 1, it will also be here ... I do it's btw now)
  • On the local computer, create a directory with the name sample
  • In samplecreate .ebextensions/elasticcache-sessions.configwith the following contents:

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"
Run code
  1. Under samplecreate index.phpwith the following contents:

    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. Compressing sampleas a file .zipand deploying 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..

SSH EC2, Beanstalk, , PHP7 . php --ini | grep memcached, . , ebextension, , . , . .

+4

Source: https://habr.com/ru/post/1676561/


All Articles