简体   繁体   中英

PHP mkdir permission denied on mounted hard drive

I'm trying to use the command mkdir in a php script to create a directory on a mounted hard-drive on a raspberry pi. I have created the directory /mnt/hdd ( sudo mkdir /mnt/hdd ) and i'm mounting the device using the command :

sudo mount /dev/sda1 /mnt/hdd

My php script is :

<?php
     mkdir("/mnt/hdd/storage_1/");
     mkdir("/mnt/hdd/storage_2/");
?>

But when i run this script, the directories are not created, and i have these errors in /var/log/apache2/error.log :

[Sat Dec 03 18:47:44.590884 2016] [:error] [pid 1295] [client 192.168.1.11:50940] PHP Warning:  mkdir(): Permission denied in /home/pi/html/createDir.php on line 2
[Sat Dec 03 18:47:44.591949 2016] [:error] [pid 1295] [client 192.168.1.11:50940] PHP Warning:  mkdir(): Permission denied in /home/pi/html/createDir.php on line 3

Here are the permissions for the directory /mnt/hdd :

drwxr-xr-x  2 root root  32K Jan  1  1970 hdd

My apache server is using default configuration (www-data user and group). There is a permission issue on the folder /mnt/hdd but i can't figure it out, can someone give me a clue ?

Apache is running in www-data group as you said, and hdd folder belongs to root, so Apache cant make directories because of privileges.Try

  1. Make sure all files are owned by the Apache group and user.

     chown -R www-data:www-data /path/to/webserver/www 
  2. Next enabled all members of the www-data group to read and write files

     chmod -R g+rw /path/to/webserver/www 

The problems seems to comes whem i'm mounting the device. it's works when i mount the drive with the following command :

sudo mount /dev/sda1 /mnt/hdd umask=000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM