My issue is getting an error as following while try to create a folder using php script in /opt/lampp/htdocs/.

mkdir(): permission denied

Am am using ubuntu system and lampp installed. In my application I need to create a folder in /opt/lampp/htdoc/ for temporary storage of files.

I can able to create files and folders dynamically by php script.

I have checked my folder owner and group and changed it to www-data:www-data as same as in inner folder, but still same error.

Here is my code for creating folder:

$old = umask(0); 
mkdir($UploadDirectory, 0777,true);

My $UploadDirectory path is also the correct /opt/lampp/htdocs/mydirectory.

I have tried all the available answers in StackOverflow, that's why I am creating new question. Please help.

  • Did you check your PHP configuration for whenever safe_mode or basedir is set? Where does the script that runs those commands reside? Why are you setting the umask? – Seth Feb 17 '17 at 11:57

Since you are running ubuntu, check out AppArmor as this is likely what is preventing you writing. You can run aa-logprof and follow the prompts.


I have noticed other sites with a few others that asked this question with varying answers that worked, none of which worked for me. I have included the answer that ended up working in my case. I hope this information will help some people at least.

The solution that did NOT work for me but might work for some people was:

$old = umask(0);
mkdir("/path/some_dir/", 0755, true);

The one that did work for me though with a somewhat peculiar behavior:

$old = umask(0000);
mkdir("/var/www/html/somewebsite/images/somefolder/somefolder/", 6640, true);

The created folders seem to end up with the 640 permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.