Warning: mkdir(): Permission denied
Solution 1
To avoid spending too much time on permissions problems between the CLI user and the Apache user, an easy configuration is to use same user for both processes.
Get your user id and group by doing
$ id
uid=1000(my_user), gid=1000(my_group), ...
And then:
$ sudo service apache2 stop
$ sudo vi /etc/apache2/envvars
export APACHE_RUN_USER=my_user
export APACHE_RUN_GROUP=my_group
$ sudo chown -R my_user /var/lock/apache2
it's better and safer than to change you whole directory permission to 777
Solution 2
I think you should try this -
mkdir("../images/".$accountID, 0777, 'R');
Recursive folder creation may causing the problem. Also get more information from - mkdir
Also check for folder permission.
BRBT
Updated on July 09, 2022Comments
-
BRBT almost 2 years
I am trying to make a directory when a new account is created.
The directory should be in my images folder and is used to better separate uploaded images.//get the ID of the new account that was just created/inserted $accountID = mysqli_insert_id($dbc); //create a new directory path for that account $directoryPath = "../images/" . $accountID; // check if the directory exists if (!is_dir($directoryPath)) { //create the directory mkdir($directoryPath, 0777); //breaking here }
I had no problem getting this to work a few days ago, however when testing it today I am having problems.
I have included
ini_set('display_errors', 'On');
in my page to see what error I am being thrown and it is a permission error.Warning: mkdir(): Permission denied
The images folder has full read/write permissions for all users and groups as well as any parent folders so I don't understand how that would be an issue, that and it had worked several times before.
I am working on windows if that matters.
Any ideas?