Apache2 mkdir(): Permission denied




I refer to this post and would like to report that my .php script will NOT create files. The bug that was reported, and rectified in the referred post is persisting in my current workspace.

In the /etc/apache2/envvars file the (standard) settings are:
export APACHE_RUN_USER=ubuntu
export APACHE_RUN_GROUP=ubuntu

the users and groups for the web folder is ubuntu:ubuntu

My code is as follows:

$location = $_SERVER["DOCUMENT_ROOT"] . "/uploads/somedir";
if( !file_exists($location) ) {
    $oldmask = umask(0);
    mkdir($location, 0644, true);

Okay, after further experimentation I have some further results which may assist with debugging / troubleshooting:

After running the commands that @vasilenko93 suggested I have some partial success however the issue still persists, albeit in a changed manner.

The way I am calling mkdir() is with the boolean recursive parameter, this results in total failure.

When I change the parameters of the mkdir() call to only provide a single folder location and remove the boolean recursive flag, the directory is created, but I can NOT get a successive call on that newly created directory to work, so it will only allow you to create a single directory, which is NOT satisfactory.

Here is an Example workspace demonstrating the issue


You are using wrong permission when creating the directory. It is not possible to create a dirctory inside a direcory with 0644 permissions. see http://stackoverflow.com/questions/35677089/is-using-mode-0664-in-php-mkdir-a-good-idea


Thank you for your prompt response Harutyun. I have been successful in creating the directories using the 0755 permissions. I apologise for taking your time unnecessarily.