Things to be careful when using session_start() with nginx

ERROR

An error occurred in session_start.

When I was creating a website using nginx and php.

I tried to start a session with the following method:

session_start()

I am getting this error.


Warning: session_start(): open(/var/lib/php/session/sess_83pdkl32p3d7fav8c7betn8mkg, O_RDWR) failed: Permission denied (13) in /var/www/html/gallery/admin/includes/session.php on line 9

Warning: session_start(): Failed to read session data: files (path: /var/lib/php/session) in /var/www/html/gallery/admin/includes/session.php on line 9

Line 9 is where session_start is written, but it seems that I don't have permission to write (or read?) to the file.

Check the permission settings

path: /var/lib/php/session

So I checked the permission settings for the directory where the session data is written.
(By the way, this time the error was displayed,phpinfo()The method also tells you where the session is written to.)

ls -la /var/lib/php/session

total 0
drwxrwx---. 2 root apache 45 Dec 20 13:35 .

The owner group is apache.

Change owner group to nginx

I changed the owner group to nginx with the following command:

chgrp nginx /var/lib/php/session

This solved the error! It seems that nginx can read and write to the session directory properly.

When setting up a PHP environment with nginx, Apache is often the default, so you have to make some tweaks here and there.

I'm somehow used to using nginx, but I wonder if it would be easier to use Apache...

comment

Copied title and URL