Bobcares

Best way to fix – PHP Warning session.save_path not set

by | Oct 24, 2019

Warning: Unknown: Failed to write session data (files). PHP Warning session.save_path not set.
Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

That was an error message our customer recently got while accessing his website.

Usually, this error occurs due to improper settings of the PHP directive session.save_path.

At Bobcares, we often get requests to fix PHP session errors as a part of our Server Management Services.

Today, let’s have a look into the error and see how our Support Engineers fix it.

 

What is PHP Warning session.save_path not set error?

The main function of a PHP session file is to make data accessible across the various pages of an entire website.

It’s a simple way to store data for individual users.

If we receive the error means, there is a problem with session.save_path configuration and sessions will not work.

Recently one of our customers contacted us with this PHP Warning session.save_path not set error while accessing his website contents.

The typical error was like this:

The error indicated that the session.save_path not configured correctly.

 

How to find the PHP Warning session.save_path not set on the server?

To find out the session.save path value set on the server, we do the following steps.

1. First, we login to the server.

2. Then we test if session.save_path is set on the server. For that, we create a file with any text editor and name it with phpinfo.php.

example:    vi phpinfo.php   (add below code to this file)

<?php
phpinfo();
?>

Then we save the file phpinfo.php.

3. Then we upload this file to the customer’s site and then access this in web browsers using the link http://yourwebsite.com/phpinfo.php

4. After that, we look for the entry that says: session.save_path  like below.

In the value of the directive, session.save_path is no value, it means session.save_path is not configured and sessions will not work.

So we need to update the session save path in the php.ini file.

 

How we fix PHP Warning session.save_path not set error?

So far, we discussed the php session error. Now, let’s see how our Support Engineers fix this error for our customers.

The session.save_path is a PHP directive that needs to be set in PHP configuration settings (the php.ini file).

To fix the error, we do the following steps.

1. We login to the server.

2. Then we check for the PHP Handler in use. For instance, in cPanel servers, we use

/usr/local/cpanel/bin/rebuild_phpconf --current

3. We get the output as below.

Available handlers: dso cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: dso
SUEXEC: enabled

Enabling the session save path depends on the type of the PHP handler. Let’s take a look at the exact steps on DSO and SuPHP.

Case 1: PHP handler – DSO  (using .htaccess file)

1. If the handler is dso then we move on to the document root of the user.

2. Then we create a temporary directory called /tmp with 777 permission in the website folder.

Example :

[#root@server#:cd /home/username/public_html]
(root)> ll |grep tmp
drwxrwxrwx 2 p9r11734 p9r11734 23552 Oct 12 09:08 tmp
[#root@server#/home/username/public_html]

3. After that, we open the .htaccess file and add the following lines to it.

php_value session.save_path /home/username/public_html/tmp

4. We Save and quit the file.

5. Then we check this using a PHP info page and search for session.save_path. If it shows /home/username/public_html/tmp, then we make sure that we have set the correct path.

 

Case 2: PHP handler – suphp   (using php.ini file)

Similarly, if the PHP handler is suphp, then we do the following steps.

1. We create a custom php.ini file inside the website.

vi /etc/php.ini

2. And add the entry for  session.save_path to /home/username/public_html/tmp  in this php.ini file.

3. Then we save and quit the file.

This fixes the PHP Warning session.save_path not set error for our customers.

 

[Need more assistance in PHP Warning session.save_path not set error? We’ll fix it for you.]

 

Conclusion

In short, the php session error occurs due to no value set in the directive session.save_path or session.save_path not configured. Today, we saw how our Support Engineers fix this error for our customers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

2 Comments

  1. Juan Carlos Aldazosa

    Very detailed tutorial, solved some problems thanks to this post.

    Reply
    • Hiba Razak

      Hi Juan ,
      Thanks for the feedback. We are glad to know that our article was helpful for you 🙂 .

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.