Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Tutorials
    • All tutorials
    • Deploying the Apache Kafka® web interface
    • Migrating a database from a third-party Apache Kafka® cluster to Managed Service for Apache Kafka®
    • Moving data between Managed Service for Apache Kafka® clusters using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for YDB to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for ClickHouse® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for Greenplum® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for MongoDB using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for MySQL® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for OpenSearch using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for PostgreSQL using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for YDB using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Data Streams using Data Transfer
    • Delivering data from Data Streams to Managed Service for YDB using Data Transfer
    • Delivering data from Data Streams to Managed Service for Apache Kafka® using Data Transfer
    • YDB change data capture and delivery to YDS
    • Configuring Kafka Connect to work with a Managed Service for Apache Kafka® cluster
    • Automating Query tasks with Managed Service for Apache Airflow™
    • Sending requests to the Yandex Cloud API via the Yandex Cloud Python SDK
    • Configuring an SMTP server to send e-mail notifications
    • Adding data to a ClickHouse® DB
    • Migrating data to Managed Service for ClickHouse® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for ClickHouse® using Data Transfer
    • Asynchronously replicating data from PostgreSQL to ClickHouse®
    • Exchanging data between Managed Service for ClickHouse® and Yandex Data Processing
    • Configuring Managed Service for ClickHouse® for Graphite
    • Fetching data from Managed Service for Apache Kafka® to Managed Service for ClickHouse®
    • Fetching data from Managed Service for Apache Kafka® to ksqlDB
    • Fetching data from RabbitMQ to Managed Service for ClickHouse®
    • Saving a Data Streams data stream in Managed Service for ClickHouse®
    • Asynchronous replication of data from Yandex Metrica to ClickHouse® using Data Transfer
    • Using hybrid storage in Managed Service for ClickHouse®
    • Sharding Managed Service for ClickHouse® tables
    • Data resharding in a Managed Service for ClickHouse® cluster
    • Loading data from Yandex Direct to a data mart enabled by Managed Service for ClickHouse® using Cloud Functions, Object Storage, and Data Transfer
    • Loading data from Object Storage to Managed Service for ClickHouse® using Data Transfer
    • Migrating data with change of storage from Managed Service for OpenSearch to Managed Service for ClickHouse® using Data Transfer
    • Loading data from Managed Service for YDB to Managed Service for ClickHouse® using Data Transfer
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
    • Configuring Cloud DNS to access a Managed Service for ClickHouse® cluster from other cloud networks
    • Migrating a Yandex Data Processing HDFS cluster to a different availability zone
    • Importing data from Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Importing data from Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Mounting Object Storage buckets to the file system of Yandex Data Processing hosts
    • Working with Apache Kafka® topics using Yandex Data Processing
    • Automating operations with Yandex Data Processing using Managed Service for Apache Airflow™
    • Shared use of Yandex Data Processing tables through Metastore
    • Transferring metadata between Yandex Data Processing clusters using Metastore
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Migrating to Managed Service for Elasticsearch using snapshots
    • Migrating collections from a third-party MongoDB cluster to Managed Service for MongoDB
    • Migrating data to Managed Service for MongoDB
    • Migrating Managed Service for MongoDB cluster from 4.4 to 6.0
    • Sharding MongoDB collections
    • MongoDB performance analysis and tuning
    • Migrating a database from a third-party MySQL® cluster to a Managed Service for MySQL® cluster
    • Managed Service for MySQL® performance analysis and tuning
    • Syncing data from a third-party MySQL® cluster to Managed Service for MySQL® using Data Transfer
    • Migrating a database from Managed Service for MySQL® to a third-party MySQL® cluster
    • Migrating a database from Managed Service for MySQL® to Object Storage using Data Transfer
    • Migrating data from Object Storage to Managed Service for MySQL® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Debezium
    • Migrating a database from Managed Service for MySQL® to Managed Service for YDB using Data Transfer
    • MySQL® change data capture and delivery to YDS
    • Migrating data from Managed Service for MySQL® to Managed Service for PostgreSQL using Data Transfer
    • Migrating data from AWS RDS for PostgreSQL to Managed Service for PostgreSQL using Data Transfer
    • Migrating data from Managed Service for MySQL® to Managed Service for Greenplum® using Data Transfer
    • Configuring an index policy in Managed Service for OpenSearch
    • Migrating data from Elasticsearch to Managed Service for OpenSearch
    • Migrating data from a third-party OpenSearch cluster to Managed Service for OpenSearch using Data Transfer
    • Loading data from Managed Service for OpenSearch to Object Storage using Data Transfer
    • Migrating data from Managed Service for OpenSearch to Managed Service for YDB using Data Transfer
    • Copying data from Managed Service for OpenSearch to Managed Service for Greenplum® using Yandex Data Transfer
    • Migrating data from Managed Service for PostgreSQL to Managed Service for OpenSearch using Data Transfer
    • Authenticating a Managed Service for OpenSearch cluster in OpenSearch Dashboards using Keycloak
    • Using the yandex-lemmer plugin in Managed Service for OpenSearch
    • Creating a PostgreSQL cluster for 1C:Enterprise
    • Searching for the Managed Service for PostgreSQL cluster performance issues
    • Managed Service for PostgreSQL performance analysis and tuning
    • Logical replication PostgreSQL
    • Migrating a database from a third-party PostgreSQL cluster to Managed Service for PostgreSQL
    • Migrating a database from Managed Service for PostgreSQL
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for PostgreSQL to Managed Service for YDB using Data Transfer
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Migrating data from Object Storage to Managed Service for PostgreSQL using Data Transfer
    • PostgreSQL change data capture and delivery to YDS
    • Migrating data from Managed Service for PostgreSQL to Managed Service for MySQL® using Data Transfer
    • Migrating data from Managed Service for PostgreSQL to Managed Service for OpenSearch using Data Transfer
    • Troubleshooting string sorting issues in PostgreSQL after upgrading glibc
    • Migrating a database from Greenplum® to ClickHouse®
    • Migrating a database from Greenplum® to PostgreSQL
    • Exporting Greenplum® data to a cold storage in Object Storage
    • Loading data from Object Storage to Managed Service for Greenplum® using Data Transfer
    • Copying data from Managed Service for OpenSearch to Managed Service for Greenplum® using Yandex Data Transfer
    • Creating an external table from a Object Storage bucket table using a configuration file
    • Migrating a database from a third-party Valkey™ cluster to Yandex Managed Service for Valkey™
    • Using a Yandex Managed Service for Valkey™ cluster as a PHP session storage
    • Loading data from Object Storage to Managed Service for YDB using Data Transfer
    • Loading data from Managed Service for YDB to Object Storage using Data Transfer
    • Processing Audit Trails events
    • Processing Cloud Logging logs
    • Processing CDC Debezium streams
    • Analyzing data with Jupyter
    • Processing files with usage details in Yandex Cloud Billing
    • Entering data into storage systems
    • Smart log processing
    • Transferring data within microservice architectures
    • Migrating data to Object Storage using Data Transfer
    • Migrating data from a third-party Greenplum® or PostgreSQL cluster to Managed Service for Greenplum® using Data Transfer
    • Migrating Managed Service for MongoDB clusters
    • Migrating MySQL® clusters
    • Migrating to a third-party MySQL® cluster
    • Migrating PostgreSQL clusters
    • Creating a schema registry to deliver data in Debezium CDC format from Apache Kafka®

In this article:

  • Required paid resources
  • Getting started
  • Prepare the infrastructure
  • Configure additional settings
  • Configure PHP to use the Yandex Managed Service for Valkey™ cluster as storage for sessions
  • Check whether PHP session data is saved to the Yandex Managed Service for Valkey™ cluster
  • Delete the resources you created
  1. Building a data platform
  2. Using a Yandex Managed Service for Valkey™ cluster as a PHP session storage

Using Yandex Managed Service for Valkey™ clusters as PHP session storage

Written by
Yandex Cloud
Updated at May 5, 2025
  • Required paid resources
  • Getting started
    • Prepare the infrastructure
    • Configure additional settings
  • Configure PHP to use the Yandex Managed Service for Valkey™ cluster as storage for sessions
  • Check whether PHP session data is saved to the Yandex Managed Service for Valkey™ cluster
  • Delete the resources you created

You can use Yandex Managed Service for Valkey™ clusters for storing PHP session data.

To configure a Yandex Managed Service for Valkey™ cluster as PHP session storage:

  1. Configure PHP to use the Yandex Managed Service for Valkey™ cluster as storage for sessions.
  2. Check whether PHP session data is saved to the Yandex Managed Service for Valkey™ cluster.

If you no longer need the resources you created, delete them.

Required paid resourcesRequired paid resources

The support cost includes:

  • Yandex Managed Service for Valkey™ target cluster fee: Using computing resources allocated to hosts, and its disk space (see Valkey™ pricing).
  • Fee for using public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).
  • VM fee: using computing resources, storage, and public IP address (see Compute Cloud pricing).

Getting startedGetting started

Prepare the infrastructurePrepare the infrastructure

Manually
Terraform
  1. If you use Virtual Private Cloud security groups, configure them. Add TCP settings to the security group to allow the following:

    • Incoming traffic on port 22 from any IP addresses for SSH.
    • Outgoing and incoming traffic on ports 80 and 443 to and from any IP address for HTTP/HTTPS.
    • Outgoing and incoming traffic on port 6379 to and from internal network IP addresses for Valkey™.

    For more information, see Security groups.

  2. Create a virtual machine with LAMP/LEMP in Yandex Compute Cloud of any suitable configuration.

    When creating a VM, select the security group that you set up earlier. To check the security settings, enter the VM's public IP address in the browser address bar: the default page of the web server should be displayed.

  3. Create a Yandex Managed Service for Valkey™ cluster with any suitable configuration. When creating a Yandex Managed Service for Valkey™ cluster, specify the same network and security groups as those of the VM hosting the web server.

  1. If you do not have Terraform yet, install it.

  2. Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.

  3. Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it.

  4. Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.

  5. Download the configuration file for the appropriate cluster type to the same working directory:

    • redis-cluster-non-sharded-and-vm-for-php.tf: For a non-sharded cluster.
    • redis-cluster-sharded-and-vm-for-php.tf: For a sharded cluster.

    Each file describes the following:

    • Network.
    • Subnet.
    • Default security group and rules required to connect to the cluster and VM from the internet.
    • Yandex Managed Service for Valkey™ cluster.
    • Virtual machine.
  6. Specify the following in the configuration file:

    • Password to access the Yandex Managed Service for Valkey™ cluster.
    • ID of the public LAMP/LEMP image.
    • Username and path to the public key file for accessing the virtual machine. By default, the specified username is ignored in the image that is currently used. A user with the ubuntu username is created instead. Use it to connect to the VM.
  7. Make sure the Terraform configuration files are correct using this command:

    terraform validate
    

    If there are any errors in the configuration files, Terraform will point them out.

  8. Create the required infrastructure:

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console.

Configure additional settingsConfigure additional settings

  1. Connect to the VM with the web server via SSH and configure it:

    • Install certificates:

      sudo mkdir --parents /usr/local/share/ca-certificates/Yandex/ && \
      sudo wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \
          --output-document /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt
      
    • Prepare the environment and install the phpredis library using pecl:

      sudo apt update && \
      sudo apt install php-dev pkg-php-tools redis-tools --yes && \
      sudo pecl channel-update pecl.php.net && \
      sudo pecl install redis
      
    • Become the owner of the /var/www/html/ directory and delete all its contents:

      sudo chown <username> /var/www/html/ --recursive && \
      rm /var/www/html/*
      

Configure PHP to use the Yandex Managed Service for Valkey™ cluster as storage for sessionsConfigure PHP to use the Yandex Managed Service for Valkey™ cluster as storage for sessions

  1. Make changes to the php.ini configuration file for your web server.

    The php.ini file is usually located in the following directory:

    • /etc/php/7.2/apache2/ for Apache
    • /etc/php/7.2/fpm/ for NGINX

    To find out the location of php.ini, run the sudo find /etc/ -name php.ini command.

    Note

    There is no need to make any changes to php.ini for the PHP CLI.

    Non-sharded cluster
    Sharded cluster
    [PHP]
    ...
    extension = redis
    ...
    [Session]
    session.save_handler = redis
    session.save_path = "tcp://<Valkey™_master_host_FQDN>:6379?auth=<password>"
    
    [PHP]
    ...
    extension = redis
    ...
    [Session]
    session.save_handler = rediscluster
    session.save_path = "seed[]=<FQDN1>:6379&seed[]=<FQDN2>:6379&seed[]=<FQDN3>:6379&auth=<password>"
    

    Here, <FQDN1>, <FQDN2>, and <FQDN3> are fully qualified domain names of cluster master hosts. For example, for a cluster with three shards and password for password, the session.save_path parameter value will look like this:

    session.save_path = "seed[]=rc1a-t9h8gxqo********.mdb.yandexcloud.net:6379&seed[]=rc1b-7qxk0h3b********.mdb.yandexcloud.net:6379&seed[]=rc1c-spy1c1i4********.mdb.yandexcloud.net:6379&auth=password"
    

    For more information about how to connect to clusters, see Setting up a connection.

  2. Restart the web server:

    • sudo systemctl restart apache2 for Apache
    • sudo systemctl restart php7.2-fpm for NGINX

Check whether PHP session data is saved to the Yandex Managed Service for Valkey™ clusterCheck whether PHP session data is saved to the Yandex Managed Service for Valkey™ cluster

  1. In the /var/www/html/ directory, create a file named index.php that will be outputting the powers of 2:

    <?php
    session_start();
    
    $count = isset($_SESSION['count']) ? $_SESSION['count'] : 1;
    
    echo $count;
    
    $_SESSION['count'] = $count * 2;
    

    Each time the page is refreshed, the output value will increase. The $count variable value will be saved in the session data. A unique key will be created for each session in Valkey™.

  2. Connect to the Valkey™ cluster from the VM via redis-cli:

    redis-cli -c -h <master_host_FQDN> -a <password>
    

    Enter the following command to see what keys are stored in Valkey™:

    KEYS *
    
    (empty list or set)
    

    The returned result shows that no data is currently stored in Valkey™.

  3. Check whether user sessions are saved when connecting to the web server:

    1. Enter the public IP of the VM hosting the web server in the browser address bar. The first time you open the page, 1 will be output.
    2. Refresh the page several times: the output value will increase.
    3. Open the page in a different browser: the count will start from 1.
    4. Refresh the page several times: the output value will increase, too.

    The fact that the $count variable value is saved between the browser page updates shows that the configured PHP session storage mechanism in the Yandex Managed Service for Valkey™ cluster works well.

  4. Repeat the query to view the keys stored in Valkey™:

    KEYS *
    
    1) "PHPREDIS_SESSION:keb02haicgi0ijeju3********"
    2) "PHPREDIS_SESSION:c5r0mbe1v84pn2b5kj********"
    

    The returned result shows that, for each session in Valkey™, its own key is created.

Delete the resources you createdDelete the resources you created

Delete the resources you no longer need to avoid paying for them:

Manually
Terraform
  • Delete the Yandex Managed Service for Valkey™ cluster.
  • Delete the virtual machine.
  • If you reserved public static IP addresses, release and delete them.
  1. In the terminal window, go to the directory containing the infrastructure plan.

    Warning

    Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.

  2. Delete resources:

    1. Run this command:

      terraform destroy
      
    2. Confirm deleting the resources and wait for the operation to complete.

    All the resources described in the Terraform manifests will be deleted.

Was the article helpful?

Previous
Migrating a database from a third-party Valkey™ cluster to Yandex Managed Service for Valkey™
Next
Loading data from Object Storage to Managed Service for YDB using Data Transfer
Yandex project
© 2025 Yandex.Cloud LLC