Table of Contents
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.
Important
If you use a custom session path and encounter errors while cloning your application or creating a staging application. In that case, we recommend updating the session path to /home/hostname/application_name/public_html/var/sessions, as this directory "var/sessions" is excluded by default from cloning and staging creation processes to avoid any conflicts.
If session-writing errors are encountered, ensure permissions for the session directory are appropriately set. Verify the directory's existence and make adjustments if necessary to prevent operational disruptions.
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 on 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.
Addressing performance bottlenecks in session storage can significantly improve your application experience. Slow session handling is often caused by file-based sessions or unrelated I/O contention, which can be mitigated by creating a dedicated session folder and clearing old, irrelevant session files regularly. This ensures better organization and faster access.
How to Set the Session Path for an Application
Step #1 โ 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.
Once you are connected, execute the following command to view the hostname and note it down.
hostname
Step #2 โ Creating the Session Directory
Next, we need to create a directory to set that as a Session Path.
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.
ls
Step #3 โ Setting the Session Path in PHP FPM Settings
Log in to your Cloudways Platform using your credentials.
From the top menu bar, open Servers.
Next, choose the server where your desired application is deployed.
Click the globe icon.
Next, choose your application.
Under Application Management, select Application Settings.
Next, navigate to the PHP FPM Settings.
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
Finally, click Save Changes.
To extend session timeouts, update your configuration with the following directives:
php_value[session.cookie_lifetime] = 31536000 php_admin_value[session.gc_maxlifetime] = 31536000
These settings modify the session cookie lifetime and garbage collection (GC) lifetime, extending session duration to one year.
It should start saving the user-related sessions in your defined session path.
Troubleshooting Common Session Issues
Quick Session Expirations: If sessions expire too quickly, verify the timeout configuration in the application's PHP settings and make necessary adjustments to
session.gc_maxlifetime.Cross-User Data Issues: Ensure each application uses a unique session directory to prevent conflicts and enable a secure namespace for session saving mechanisms like Redis.
Best Practices for Managing PHP Sessions
Use dedicated and writable session directories for improved organization.
Regularly clean up obsolete session files.
Collaborate closely with developers to configure optimal session timeout settings, paths, and storage mechanisms.
Always test changes in a staging environment before implementation.
Stop Wasting Time on Servers
Cloudways handles server management for you so you can focus on creating great apps and keeping your clients happy. Start Free.
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.







