PHP会话数据文件不是由您的uid(Vagrant CentOS)创建的

I try to do the following:

ini_set('session.save_path', '/var/www/example/sessions');

session_start();

but I get the following error:

session_start(): Session data file is not created by your uid

I check get_current_user() in returns vagrant

I check permission of /var/www/example/sessions it returns:

drwxrwxrwx 1 vagrant vagrant 4.0K Dec 11 01:58 sessions


Note: the answer stated here does not work for me because doing:

chown -R www-data:www-data /var/www/example/sessions/ returns an error:

chown: invalid user: ‘www-data:www-data’.

In Vagrant, it appears vagrant is the PHP user.


Note: The session files appears to get created inside the custom session folder but they are empty. e.g., sess_k92fdn46onm5an0mau6p50tr2g doesn't contain anything.

Any ideas?

You are correct, your user is vagrant. Have you tried running sudo chown -R www-data:vagrant /var/www/example/sessions/? You are getting the error because www-data is not a user. Hope this helps.