Reputation: 73
I'm trying to make some sort of cloud application on a headless raspbian machine. The testing happens on a wamp-server running on windows8.1. PHP version is 5.6
The code works fine on my testing windows, but I run into issues when running the same code on my linux server. I've narrowed down the issue to the fact that (the linux user behind) my PHP code doesn't have write permissions on the folder where it should store files.
I can think of two ways to solve the issue: either give that php-user permissions, or change the user behind the php code. The last one would be quite interesting if it was possible to change per-script.
So, for my concrete question:
1) Where can I find what user is being used by my PHP code?
2) Can I change what user my PHP code uses, preferably on a per-project basis?
EDIT:
My script was running as root, as is shown by echo get_current_user();
. I changed ownership of all files to root:webhosting, which was previously ftpuser:ftpgroup. However, when setting permissions to 770
I get access denied
EDIT2:
When using var_dump(posix_geteuid());
instead of get_current_user();
, i get UID 33, which matches user www-data.
SOLUTION:
By looking at the EUID with var_dump(posix_geteuid();
I was able to validate the actual user, which does NOT match the get_current_user();
. Changing the directroy and all files in it with sudo chown -R www-data:www-data <root of site>
I managed to set the correct permissions.
Upvotes: 1
Views: 77
Reputation: 2633
I am not sure what the specifics are but normally when I have issues like that I change the ownership to www-data:www-data and if necessary for upload folders I change the folder permissions to 0755 and inside files permissions to 0644.
EDIT
I changed the permissions setting for security purposes.
Upvotes: 1
Reputation: 4821
You're PHP/Apache user is probably www-data
. You probably want to run something like this.
sudo find path/to/project/ -exec chown www-data:root {} \;
File permissions may also be a problem. If so, run something like this.
sudo find path/to/project/ -type d -exec chmod 775 {} \;
sudo find path/to/project/ -type f -exec chmod 664 {} \;
Upvotes: 1