CloudInsidr

Cyber security, infotech

  • Subscribe!
  • Privacy Policy
  • Legal
  • Contact Us

Join us on Twitter: @CloudInsidr

Follow us on Twitter: @cloudinsidr
  • news & alerts
    • events
    • industry analysis
    • industry gossip
    • people
  • cloud, edge & co.
    • AWS
    • administration & orchestration
      • web servers in the cloud
      • mail servers
      • databases
  • cybersec & warfare
    • encryption
  • blockchain
Home Uncategorized How to Fix PHP Session Errors while Respecting Security with Correct Permissions
How to Fix PHP Session Errors while Respecting Security with Correct Permissions

Cloud Insidr 2015-11-25 Leave a Comment

How to Fix PHP Session Errors while Respecting Security with Correct Permissions

Have you ever seen one of these weird redirects? WordPress, for example, may refuse to show the log-in page, leaving you out of its admin interface for good. Here is what to do about it.

The log file may hold the secret to the weird behaviour:

tail /var/log/nginx/error.log

You might see something like this:

2015/11/18 18:23:51 [error] 16852#16852: *18847 FastCGI sent in stderr: "PHP message: PHP Warning: session_start(): open(/var/lib/php/session/sess_hk123na6l228eui7odqub6rghej6, O_RDWR) failed: No such file or directory (2) in /mnt/www/www.yourdomain.com/somefolder/somepath/watever-legit-script-is-trying-to-read-sessions.php on line 715" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: www.yourserver.com, request: "GET /content/? HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sockets/www.yourserver.com.sock:", host: "www.yourserver.com", referrer: "https://auth.somereferrer.com/whatever"

or something like this:

2015/11/18 18:23:51 [error] 16852#16852: *18847 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open(/var/lib/php/session/sess_hk123na6l228eui7odqub6rghej6, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
PHP message: PHP 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 0" while reading upstream, client: XXX.XXX.XXX.XXX, server: www.yourserver.com, request: "GET /content/? HTTP/1.1", upstream: "

These errors occur because PHP has no way of saving sessions on disk. Correcting permissions should fix the problem, but the trick is not to overdo it. Incorrect permissions on session files can open a can of worms to session hijacking.

The location of the PHP session path can be found in /etc/php.ini under session.save_path. The default path is

/var/lib/php/session

If this directory does not exist (even though it should exist precisely in this path), create it, then change permissions on it:

chown -R nginx:nginx /var/lib/php/session
chmod -Rf 700 /var/lib/php/session

This assumes that you are running NGINX as the user nginx. (Be careful to change access privileges correctly–this always means: restrictively–in order not to facilitate session hijacking!).

Restart php-fpm and you should be good to go.

Filed Under: Uncategorized, web servers in the cloud Tagged With: error, Linux, log, NGINX, permissions, PHP, php-fpm, session, session hijacking

Leave a Reply Cancel reply

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

Subscribe

SSL/TLS Certificate Square (250 x 250)

Pearson Education (InformIT)

SSL/TLS Certificate Medium Rectangle (300 x 250)

Recent Posts

  • Upgrading from CentOS 6 to CentOS 7 and Beyond?
  • How To Figure Out Who is Signing In To Dovecot to Send or Retrieve Email
  • OpenSSH 9.9 Introduces Enhanced Quantum-Resistant Algorithms
  • OpenSSL 3.3 Final Release is now live!
  • How to Activate HTTP/2 with TLS 1.3 Encryption in NGINX for Secure Connections without a Performance Penalty
  • Is AWS sucking your budget dry? Strip it down to the nitty-gritty (without breaking stuff)
  • How to attach and mount an NVMe EBS volume on EC2
  • SELinux security contexts: correcting SELinux labels on a file system
  • Intel gobbling up Israeli Tower Semiconductor, Stock Goes Through The Roof
  • NGINX on AWS EC2: setting up a web server from scratch on a domain of your choice
  • Log4j RCE and mitigation techniques
  • Set up logrotate for Postfix

Symantec

Categories

  • administration and orchestration
  • alerts
  • AWS
  • Bitcoin
  • cloud, edge and everything in between
  • cryptocurrencies
  • cybersecurity and cyber warfare
  • databases
  • DNS
  • encryption
  • events
  • FinTech and InsurTech
  • homeland security
  • HTTP Security Headers
  • industries
  • industry analysis
  • industry gossip
  • Java
  • Linux
  • mail servers
  • networking
  • news
  • NGINX
  • people
  • php-fpm
  • reviews
  • SELinux
  • tips and tricks
  • Uncategorized
  • web servers in the cloud

Tags

AMI AWS AWS EBS Azure certificate cipher suites cryptography cyber defense cybersecurity cyber security Diffie-Hellman DNS DNS over HTTPS Dovecot EBS EC2 email encryption Fedora HTTP/2 HTTPS IBM letsencrypt Linux logs MariaDB MFA MySQL NGINX OpenSSL permissions php-fpm PHP 7 postfix RegEx Route 53 RSA SELinux SQL SSH SSL TLS TLS 1.3 TLS vulnerabilities WordPress

Archives

  • January 2025
  • November 2024
  • October 2024
  • May 2024
  • January 2023
  • March 2022
  • February 2022
  • December 2021
  • December 2020
  • November 2020
  • September 2020
  • January 2020
  • November 2019
  • August 2019
  • July 2019
  • April 2019
  • December 2018
  • October 2018
  • September 2018
  • August 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • December 2017
  • November 2017
  • October 2017
  • August 2017
  • April 2017
  • February 2017
  • January 2017
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • July 2015
  • February 2015

Recent Comments

    Wicked fast Networking (With a Government Clearance to Boot)

    ©2022 CybrAnalytiqa OÜ

    • Content purchasing and syndication