View Full Version : PHP: Script generated files - ownership issue
Aceman
02-09-2006, 02:39 PM
On my server php scripts that generate files are doing so fine, however the files that the script makes sets the owner of that file as "apache.apache" and I can not remove/overwrite those files unless I log in as root and do so. The script is chmod 777. And the ownership is aceman.aceman, but the files it creates are always apache.apache.
I chown -R aceman.aceman public_html - which recursively sets all the files in the folder and it's sub folders to owner-aceman / group-aceman.
Is there a way to setup the server so that the ownership is maintained? In the php.ini file or the httpd config file?
Any guidance or help would be greatly appreciated.
From Zend's Page on File Creation (http://www.zend.com/zend/tut/tutorial-jenkins2.php):
Permissions
It is important to remember a few key things when working with PHP and file creation. PHP runs via your webserver and therefore has the same rights as your webserver. Since most webservers do not run with super-user status (root in Unix/Linux, or administrator in Windows) you will need to make sure the folders and files you want to edit allow the webserver write access.
Got that all set? If you already know what you are doing with permissions, you can skip to the next section.
If you are running Unix or Linux with Apache you will need to change the owner of your files to ?nobody? or ?www? depending on your install. If you don?t know what user simply type:
ps -aux | grep httpd
This will show you the apache processes running on your server, look to see the name of the user running the process. Now you need to change the permissions of your files.
File: chown www file.txt
Directory: chown www folder1/
This will change the owner of the file file.txt (or the directory folder1/) to www, thus allowing PHP via Apache to edit the file.
Aceman
02-09-2006, 03:32 PM
I actually found that page on another site myself via google. I ran the command they indicated and my server says it's apache. Not nobody or www.
maybe it's a setting issue with the server because mine doesn't say nobody or www - it's apache. Where can I set it so that nobody is the default owner when a file is generated?
Just a heads up: in my httpd.conf file I did notice a line that reads:
User apache
Group apache
Would changing that too nobody for user and group help? And then restart apache?
Aceman
Paul M
02-09-2006, 04:13 PM
It doesn't really matter whether it runs as apache or nobody, it just means the files will be owned by the user "nobody" instead. You need to alter the script that creates them to make sure the created files are global write.
Boofo
02-09-2006, 04:25 PM
You shouldn't have to alter any scripts. It worked fine on the old server but this one is giving us fits for some reason. There has to be a setting somewhere that sets it. And no ones else seems to be having this problem so it has to be server side.
Paul M
02-09-2006, 04:42 PM
You could try addind a user aceman, group aceman to the apache definition for that site.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.