Cloudways offers highly customizable server-level PHP settings and PHP FPM settings that users can directly modify from the Cloudways Platform.

In this article, you will learn how to set the session path for your applications using the Cloudways Platform.

Why You Should Set up Session Path

Usually, a website is not intelligent enough to maintain any information about visitors navigating from one page to another. HTTP is a stateless protocol which means that a server can not remember every user among multiple requests, but you can easily handle this limitation by enabling the PHP sessions.

PHP sessions allow you to track each website visitor across different pages of a website and store information about them at a specific path, also known as the session save path. In addition, PHP sessions inform the server that all requests originate from the same visitor; thus, allowing you to customize the user experience and save their preferences.

How to Set the Session Path for an Application

Set Session Path — Fetching the Server Hostname

You can set the Session Path from the Cloudways Platform, but you require a server hostname for it; therefore, connect to your server using SSH.

  1. Once you are connected, execute the following command to view the hostname and note it down.


Set Session Path — Creating the Session Directory

Next, we need to create a directory to set that as a Session Path.

  1. Navigate to the public_html folder using the following command. Be sure to replace application_name with your application name. Your application name is also available on the Cloudways Platform.

cd applications/application_name/public_html/

2. Next, create a session directory using the following command.

mkdir session

Moreover, you can use the listing command to view the created directory.


Set Session Path — Setting the Session Path in PHP FPM Settings

Log in to your Cloudways Platform using your credentials.

  1. From the top menu bar, open Servers.

  2. Then, choose the server where your desired application is deployed.

3. Next, click www.

4. Choose your application.

5. Under Application Management, select Application Settings.

6. Next, navigate to the PHP FPM Settings.

7. Add the following PHP directive at the end. Make sure to replace hostname and application_name with the correct hostname and application name you noted earlier.

Be sure to replace application_name with your application name. Your application name is also available on the Cloudways Platform. Do not add a semi-colon before the directive, as it will make it a comment.

php_admin_value[session.save_path] = /home/hostname/application_name/public_html/session

8. Finally, click Save Changes.

It should start saving the user-related sessions in your defined session path.

That’s it! We hope this article was helpful. If you need any help, then feel free to search your query on Cloudways Support Center or contact us via chat (Need a Hand > Send us a Message). Alternatively, you can also create a support ticket.

Did this answer your question?