How can I allow php to create files with the same ownership as the files that created them?

PHP creates files with apache: apache privileges, which seem to cause problems with other php scripts accessing the file.

How can I allow php to create files with the same property as the files that created them?

I read elsewhere that enabling safe_mode may affect this, but I disabled it and reloaded the files and I still get the same problem.

I am sure this will be a simple question for someone more familiar with apache, but I did not find a solution by doing a search.

thanks

+6
php apache permissions
source share
5 answers

If the ownership and several users / projects are on the same server, you may want to view SuExec in Apache: PHP files will be launched by the user specified in the settings, therefore by default the ownership of the files is automatically accepted from. This saves a lot of chown / chmod'ing, and user-executed processes are more easily limited.

Otherwise, I usually create a group with both the owner and apache and set the default umask to 007.

+2
source share

If you are using Windows, you can start Apache as a service and let apache use its own account permissions at startup.

0
source share

Try using fileowner ( http://www.php.net/manual/en/function.fileowner.php ) to get the owner ID of the current script, posix-getpwuid, to get the username for this id ( http: // www. php.net/manual/en/function.posix-getpwuid.php ) and chown ( http://php.net/manual/en/function.chown.php ) to set the user for files.

0
source share

Why sort through all the software issues to change ownership? apache.apache in any case a very unsafe owner. Why not just a chmod 0777 file that provides reading, writing and execution to all owners. This will fix the problem.

If you still have problems, you may need to check if open_basedir is enabled. If so, this is not a file affiliation or permission, but a location. This basically means that you need to put the file in a location that apache / php has already included in its path.

0
source share

am chown () mentioned above, remember that usually chown () can only be used as root, and your web server account is unlikely to be root, which is a very bad idea.

You can configure sudo to allow other users to use certain areas and only for specific users. You just need to create a suitable entry in / etc / sudoers, usually using the visudo program. If you do not have root access, then your hosting provider will have to do this for you, if any.

For more information: http://www.sudo.ws/sudo/sudo.html

0
source share

All Articles