Search code examples
redhatapache2.4php-7.2

Cannot use session_start() on apache RedHat


The full error is...

Warning: session_start(): open(../../ses/sess_38tlqpsudl0vr77vsipikik025, O_RDWR) failed: Permission denied (13) in /var/www/html/UK_Libraries_Site/shared/classes/StaffUtils.class.php on line 361

Warning: session_start(): Failed to read session data: files (path: /var/www/html/UK_Libraries_Site/ses) in /var/www/html/UK_Libraries_Site/shared/classes/StaffUtils.class.php on line 361

Using Red Hat Enterprise Linux release 8.3 (Ootpa)

777 permissions on full project directory and ownership matches httpd apache:apache

I know this has been referenced everywhere but I'm failing at getting this to work and its making me think its a Red Hat thing, it's not the first time I've had a RedHat specific issue on this server. Everything works fine locally.

I also changed the ownership and permissions on the library directory at "var/lib/php/session" (I know the error states its in a different directory but why not try everything) like they mentioned in Cannot start session without errors in phpMyAdmin.

I've tried different browsers, clearing cookies & cache, different devices, and even pulling my hair out and nothing is working.

The method calling session_start() is below $path = "../../ses"; (directory given in the error)

ini_set("session.save_path", "$path");
ini_set("session.gc_maxlifetime", "3600");

//start the session
session_start();

If you know what the issue is or even other methods not mentioned, please let me know.


Solution

  • The issue was RedHat specific see https://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/

    Command used below (ses is a directory name) sudo chcon -R -t httpd_sys_rw_content_t ses