Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Log errors with permissions
  • This is a really strange issue that only appears to be happening in 1.5, but I can’t pin it down.

    New log files are being written using the user www-data, rather than the logged in user.

    We get a permissions error each day trying to write to the new file.

    Sound familiar to anybody?

    PHP 5.4, Apache 2.2, FuelPHP 1.5
  • Here’s an example:

    image
  • Do you have the "User" and "Group" directives defined in your httpd.conf file?
  • You could also probably:

    sudo chown -R www-data:www-data fuel/app/logs
  • Note that if you use oil, the files created will get the rights settings assigned to the current logged in user, which might conflict with your apache user. This might be the case here?
  • Yeah that appears to be the problem – but why was it working before 1.5? All of our 1.5 apps are having the same problem, it’s driving us nuts!

    Here’s a couple of errors

    Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/Users/fuse/Sites/client/fuel/app/logs/2013/04/18.php" could not be opened: failed to open stream: Permission denied' in /Users/fuse/Sites/client/fuel/packages/log/src/Monolog/Handler/StreamHandler.php on line 71

    If oil creates it, then Fuel can’t write. If Fuel writes to it, oil can’t edit it.
  • This probably has to do with umask() being removed from the code. PHP is switching to a threaded model, and umask() is not thread-safe, so it's best not to use it.

    So the problem is that the chmod mask is applied, but taking the system's umask into account. This has been fixed in 1.6, where a separate chmod is executed after the file has been created to make sure it has the correct rights. For Fuel's internal code that is.

    I've checked the code of the log package in 1.5.3, and it too does a separate chmod() on the created logfile, based on the permissions set for files in the file.php config file, or setting 0666 if that doesn't exist.

    With which rights are the files created?
  • It depends – because sometimes Oil does it, so it’s thehub, other times it’s the server, so it’s www-data.
  • Without proper permissions set you'll never avoid this.

    If you create a file in linux, it will always receive the current user as UID, and the users default group as GID. For a commandline user, the UID will be different then for your webserver.

    So if multiple users need rw access to specific files, the only thing you can play with is the group, make it sticky on directories, make sure all relevant users are member of this group, and make sure the permissions (in the file.php config file) have at least rw for the group on files, and rwx for the group on directories.

    The only way to avoid this is the hand out world rights, but I would suggest to avoid that at all cost.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion