PHP, Apache, FreeBSD permissions issue

1.2k views Asked by At

Persumably, this is a *nix permissions question. I'm a Java dev trying to write some simple PHP code. We have a production machine running FreeBSD+Apache.

I'm trying to create a directory called 'ccc' as in '/var/www/aaa/bbb/ccc'

Directories 'aaa' and 'bbb' already exist.

This is ls -ltrh output for directory 'aaa':

drwxr-xr-x  7 root     root      12K Jun 10 05:27 aaa

This is ls -ltrh output for directory 'bbb':

drwxr-xr-x 3557      858      856 116K May 28 06:15 bbb

This PHP code does not create the directory '/var/www/aaa/bbb/ccc'. Says 'mkdir FAILED'.

<?php

$path = "/var/www/aaa/bbb/ccc";
if(!file_exists($path)) {
        echo "Path does not exist, creating [".$path."]...";

        if(mkdir($path, 0777, true)) {
                echo "mkdir PASSED...";
        }
        else {
                echo "mkdir FAILED...";
        }
}
else {
        echo "Path does exist[".$path."]...";
}

?>

This is ls -ltrh output for the php code:

-rw-r--r-- 1 root     root      366 Jun 10 07:14 mdtest.php

How can I create the directory 'ccc'? Any pointers would be appreciated.

2

There are 2 answers

2
venca On

So the problem is that your apache web server has not write permission to /var/www/aaa/bbb. I dont know BSD, in debian is Apache running under www-data user. So you have to change owner of /var/www/aaa/bbb to apache user.

Run chown -hR apache /var/www

2
rominokun On

You may set all to write permission: chmod a+rw /var/www/aaa/bbb