PHP on domain running via CGI/FastCGI can't use session by default

Created:

2016-11-16 13:17:07 UTC

Modified:

2017-05-11 09:51:35 UTC

1

Was this article helpful?


Have more questions?

Submit a request

PHP on domain running via CGI/FastCGI can't use session by default

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk 10.4 for Linux
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Linux

This issue has been completely fixed since Plesk 10.4. In case if you upgrade to 11.x or 12 versions, please ignore this warning. It occurs in case if permissions on the '/var/lib/php/session/' directory are set incorrectly Upgrade in fact fixes the permissions

Symptoms

In CGI or FastCGI mode, PHP runs with the permissions of the domain's FTP user.

PHP support mode can be configured for each domain on the Web Hosting Settings page found at Plesk > Domains > domain.tld > Web Hosting Settings :

Also following PHP warnings can appear:

**Warning**: session_start() [function.session-start]: open(/var/lib/php/session/sess_vr12g68afa365jenb96han4k24, O_RDWR) failed: Permission denied (13) in **/var/www/vhosts/domain.tld/httpdocs/script.php** on line ******Warning**: Unknown: open(/var/lib/php/session/sess_vr12g68afa365jenb96han4k24, O_RDWR) failed: Permission denied (13) in **Unknown** on line 
**Warning**: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in **Unknown** on line

Cause

In Plesk versions prior to 10.4, PHP configuration is set in the /etc/php.ini file and by default has a session path set as following:

# grep session.save_path  /etc/php.ini  
session.save_path = "/var/lib/php/session"

The default permissions value for this directory is 770:

# ls -ld /var/lib/php/session  
drwxrwx--- 2 root apache 65536 Dec 16 07:48 /var/lib/php/session

As the PHP scripts are processed in CGI/FastCGI mode under the <ftpuser>:psacln account, the process cannot read/write that directory and it will pick up the session file.

Resolution

Upgrade Plesk to the latest version.

If upgrade is not possible, follow the instructions below:

  1. Set up Customized PHP Configuration for the domain.

  2. Create a subdirectory under the domain's private directory and set permissions as shown below:

     # mkdir /var/www/vhosts/domain.tld/private/php_sess  
    # chown <ftpuser>:psacln /var/www/vhosts/domain.tld/private/php_sess
    # chmod 0700 /var/www/vhosts/domain.tld/private/php_sess
  3. Edit the customized PHP configuration file php.ini and overwrite the session.save_path directive as shown below:

    # grep session.save_path /var/www/vhosts/domain.tld/etc/php.ini
    session.save_path = "/var/www/vhosts/domain.tld/private/php_sess"
Have more questions? Submit a request
Please sign in to leave a comment.