14 Jan, 2008, Zeno wrote in the 1st comment:
Votes: 0
[root@server data]# cat testconfig.php
<?php echo "test"; ?>

[root@server data]# php -r 'if (file_exists("testconfig.php")) echo "File exists.\n" ;'
File exists.

[root@server data]# php -r "chmod ("testconfig.php", 777);"

Warning: chmod(): No such file or directory in Command line code on line 1

Wtf?
[EDIT] Messed up quotes. Now I'm getting permission issues, see below.
14 Jan, 2008, David Haley wrote in the 2nd comment:
Votes: 0
Not sure what's up with the file, but note from the function documentation that you probably want mode 0777, not 777.

Also check that the user as which PHP runs has permission to edit the file.
14 Jan, 2008, Zeno wrote in the 3rd comment:
Votes: 0
Yeah, tried 0777. Doesn't change anything. This happens on every file, not just this one.

How do I check what user PHP runs as?
14 Jan, 2008, David Haley wrote in the 4th comment:
Votes: 0
If you can run the shell command "whoami" and print the results, you'll see the current user running the program. PHP probably has a builtin for this but I don't know it offhand.
14 Jan, 2008, Zeno wrote in the 5th comment:
Votes: 0
Quote
php -r 'echo "PHP runs under the user: [" . system('whoami') . "]";'
PHP runs under the user: [root]

So I'm pretty sure root has permission to edit the file…

Test script:
<?php
$filename = "testconfig.php";
if (file_exists($filename)) {
echo "The file $filename exists<br />";
} else {
echo "The file $filename does not exist<br />";
}
echo "Attempting to chmod ".$filename;
chmod($filename, 0777);
?>

Gives me:
Quote
The file testconfig.php exists
Attempting to chmod testconfig.php
Warning: chmod() [function.chmod]: Operation not permitted in /home/protect/public_html/data/test.php on line 11
14 Jan, 2008, David Haley wrote in the 6th comment:
Votes: 0
Want to know something fascinating? It works if you don't use the variable $filename but instead put the filename directly as the argument to chmod…
14 Jan, 2008, David Haley wrote in the 7th comment:
Votes: 0
Actually, now it's working for me exactly as-is (using the variable). Hmm.

What are the permissions on your file?
14 Jan, 2008, Zeno wrote in the 8th comment:
Votes: 0
Doesn't matter heh, I've tried 777 and it gets the same error.
14 Jan, 2008, David Haley wrote in the 9th comment:
Votes: 0
So the file is rwxrwxrwx root:root and php running as root can't chmod it?

I'm not sure what changed on my end to let php chmod work. First it wasn't working, now it's working. I might have accidentally changed the permissions halfway through during my attempts at poking it and therefore made it work, which is why I asked about permissions.
14 Jan, 2008, Zeno wrote in the 10th comment:
Votes: 0
Perms seem fine to me.
-rwxrwxrwx  1 root    root         22 Jan 14 15:14 testconfig.php
14 Jan, 2008, David Haley wrote in the 11th comment:
Votes: 0
You don't have any funny php config settings or anything do you?
15 Jan, 2008, Guest wrote in the 12th comment:
Votes: 0
Perhaps PHP safe mode is enabled in the php.ini file? Other than that I can't see any reason for why a file marked as 0777 would fail - no matter who the user is or who ultimately owns it.
15 Jan, 2008, David Haley wrote in the 13th comment:
Votes: 0
Samson said:
Other than that I can't see any reason for why a file marked as 0777 would fail - no matter who the user is or who ultimately owns it.

I believe that you can only change the permissions on files you own.

[david@thebalrog:~]$ ls -l foo.txt
-rw-rw-rw- 1 root root 0 2008-01-14 20:13 foo.txt
[david@thebalrog:~]$ chmod 0777 foo.txt
chmod: changing permissions of `foo.txt': Operation not permitted
[david@thebalrog:~]$ ls -l foo.txt
-rw-rw-rw- 1 root root 0 2008-01-14 20:13 foo.txt


Even though I had write permission, I couldn't change the file's permissions to add +x. I also tried chmod o+x foo.txt, which didn't work either.
15 Jan, 2008, Guest wrote in the 14th comment:
Votes: 0
Right. But if PHP runs as root, and the file is owned by root, why can't it change the permissions?

I know why it doesn't work in a normal Apache/PHP install in linux, the webserver is normally run by the apache user. Which generally doesn't own anything the actual user uploaded to their web directory. This is one of the biggest pains in the ass in QSF/QSFP in fact. Skinning becomes a bigtime pain in the ass since Apache hasn't got ownership of any of the files in the default install.
15 Jan, 2008, David Haley wrote in the 15th comment:
Votes: 0
Samson said:
Right. But if PHP runs as root

Oh… right… I'd forgotten about that. :tongue:
15 Jan, 2008, Zeno wrote in the 16th comment:
Votes: 0
Someone needs to correct my stupid mistakes. :P First the quote issue in the first post, now I notice I ran the php user check at the command line (thus it shows root).

php is actually run by "nobody". So how would I correct the permissions in this case? I don't want to chown the files to 'nobody'…
15 Jan, 2008, Kjwah wrote in the 17th comment:
Votes: 0
nuggs
PHP runs under the user: [nuggs]nuggs@localhost


That's what I get when I check the user.. heh

However, not sure how recent it was or if it's still a problem but I have read somewhere that the chmod with PHP could be a real PoS sometimes. Meaning that it doesn't always function correctly or at all.. Not sure what version of PHP that was or if was actually true.. I've only had problems with chmod in PHP once and I did an upgrade and I've never had a problem since.. heh
15 Jan, 2008, David Haley wrote in the 18th comment:
Votes: 0
Zeno said:
Someone needs to correct my stupid mistakes. :P First the quote issue in the first post, now I notice I ran the php user check at the command line (thus it shows root).

You know, I was actually going to ask if all of this was from the command line or if it was happening from Apache, but then I saw the user check from the command line and figured it was all from the command line. :tongue:

Zeno said:
php is actually run by "nobody". So how would I correct the permissions in this case? I don't want to chown the files to 'nobody'…

Well, you could try having your cake and eating it too, but that might not work… but, if the files are 777, then it doesn't really matter who owns them, everybody can edit them. 'nobody' is a user like any other.
15 Jan, 2008, Zeno wrote in the 19th comment:
Votes: 0
Er yeah, I'm not a fan of having files stay as 777. :P

I went ahead and enabled php suexec. Problem solved.
0.0/19