Reputation: 3228
I use mkdir()
to create a directory on my server:
// $var_name is equal to an md5() hash
$path = "/var/www/publish/" . $var_name;
if(mkdir($path)) {
echo "success";
} else {
echo "error";
}
This will yield an error due to a permission denied. Looking up on my server, by doing ls -lh
drwxr-xr-x 2 root root 4.0K Aug 17 09:05 publish
But if my $path
is equal to $path = "/var/www/" . $var_name;
it will create the folder I expected. What seems to be the issue in here.
Upvotes: 5
Views: 16922
Reputation: 686
Fix permissions for publish folder (owned by root!). An insecure way: chmod 777 /var/www/publish
It's better to run suphp and change owner of publish folder to your php user (+w permission).
Upvotes: 0
Reputation: 12904
The permissions for the /var/www/publish
folder are wrong. You need to make sure the apache user has the required permissions to create a directory.
You are able to create directories in /var/www/
as it will have different permissions.
Check the name of the user that the httpd process is running as and chown -R user:group /var/www/publish
to that user/group. On debian, this appears to be www-data/www-data, so you need to run the following command chown -R www-data:www-data /var/www/publish
.
Upvotes: 10
Reputation: 2288
when using mkdir() with PHP it is executed with apache user (www-data on ubuntu), you may set the same rights on publish that you have on /var/www using chown
on ubuntu :
chown www-data.www-data /var/www/publish
Regards
mimiz
Upvotes: 2