# Php chmod doesn't see file



## Zenoxio (Jul 18, 2006)

```
[[email protected] data]# cat testconfig.php
<?php echo "test"; ?>

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

[[email protected] data]# php -r "chmod ("testconfig.php", 777);"

Warning: chmod(): No such file or directory in Command line code on line 1
```
The file exists. But why does chmod not see it?


----------



## tomdkat (May 6, 2006)

Do you need to give the path to the file in the chmod command? What if you did this:

php -r "chmod ("./testconfig.php", 777);"

Peace...


----------



## Zenoxio (Jul 18, 2006)

Doesn't seem to help. Here is a test script I tried:

```
<?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);
?>
```
Which output:


> 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


----------



## tomdkat (May 6, 2006)

Well, this message:

Warning: chmod() [function.chmod]: Operation not permitted in /home/protect/public_html/data/test.php on line 11

means the id the chmod() is running under doesn't have permission to perform that operation which is different from the file not being found. You will need to address that problem first.

Peace...


----------



## Zenoxio (Jul 18, 2006)

php is run as root. Root can chmod the file just fine using SSH.


----------



## tomdkat (May 6, 2006)

Are you running the PHP script via a web server or via the command line? If you're running via web server, is the web server running as root or some other id? Can you run your script using the PHP CLI and post the output here?

Peace...


----------

