DanielaWaranie
DanielaWaranie

Reputation: 1415

PHP file is not writeable: how to check via php if chmod, chown or chgrp is required

When my install script recognizes that a file (log file) is not writable - by:

 is_writable('myerror.log');

I want to show the "surfer" (software admin) how to solve this issue. Oh boy not every "software admin" is well skilled :-(

Show messages: I want to show to the software admin that he should set the owner of the file to the user the webserver runs with if user / group of the file are different to the webservers user / group (I do not want to suggest to make it world writable).

If the webservers user or group fits to the file user or group I want to show that the software admin should run chmod.


Background I realized that my apache processes runs under 9x www-data and 1x root. If I call

$scriptRunnerUserId = getmyuid();
$scriptRunnerGroupId = getmygid();

I will get 0 for each, means "root" and "root". But if I have a file with owner="root" and group="root" and with 0664 is_writeable() still returns false. It returns true only if I set 0666 (world writeable). If I set owner="www-data" and chmod 0644 it is writable. Means: getmyuid() does not return the expected value.

A case of "developer not well skilled"? ;-) (if possible I do not want to make exec() calls)

PS: Please do not blame about giving my apache the root user (it is a virtual machine for development).

Upvotes: 2

Views: 1058

Answers (1)

Jeffrey Pfau
Jeffrey Pfau

Reputation: 274

Assuming you're running on a POSIX system (which is probably true if you have a root user), you might try something like posix_geteuid to find out your effective user id.

Upvotes: 2

Related Questions