0

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?

IMB
  • 15,163
  • 19
  • 82
  • 140

1 Answers1

0

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.

Kevin
  • 350
  • 3
  • 13
  • Same error: `chown: invalid user: ‘www-data:vagrant’` – IMB Dec 11 '18 at 08:38
  • Apologies! Totally didn't see that you were on CentOS. In a Cent environment data should be owned by `apache` to be able to modify them. – Kevin Dec 11 '18 at 17:01
  • You mean to say there's no solution to this because `vagrant` is the owner? – IMB Dec 11 '18 at 17:40
  • Not too familiar with Cent but I believe the command I recommended should work if you swap `vagrant` for `apache` – Kevin Dec 11 '18 at 17:42
  • Both `www-data:apache` and `apache:apache` returns `chown: invalid user` – IMB Dec 11 '18 at 17:43
  • Have you created the `www-data` user? Try `grep www-data /etc/passwd` to see if it exists. – Kevin Dec 11 '18 at 17:48
  • I created the user `www-data` but `chown` doesn't do anything. The dir is still owned by `vagrant`. – IMB Dec 11 '18 at 18:01
  • I managed to change the folder group/owner to `www-data` via [vagrant config file](https://stackoverflow.com/a/19706318/748789) however I still get the same error `session_start(): Session data file is not created by your uid` – IMB Dec 11 '18 at 18:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/185082/discussion-between-kevin-and-imb). – Kevin Dec 11 '18 at 18:18