Admiral Nurupo Admiral Nurupo - 2 months ago 26x
Linux Question

PHP mkdir() is not working in browser

I'm trying to create directory on my local apache server with php.

I tried

<?php mkdir("folder"); ?>


<?php exec("sudo mkdir folder"); ?>

When I try to execute them in browser nothing happens.

But I can execute them from terminal by using sudo. (I also modified sudoers file so it won't prompt for password in second code)

When I don't use sudo I get this error

PHP Warning: mkdir(): Permission denied in /var/www/html/mscr/add.php on line 2

I've also tried this and this .

So I can execute almost everything but directory operations in browser.
I want to be able to create, delete and edit directories in browser.

Thank you!


Sounds like Apache doesn't have permission to create the folder. Either given Apache ownership of the folder (where you're trying to create a new one) or set the folder permissions to 777

sudo chmod 777 /var/www/html/mscr

Warning this will make everything within the mscr folder executable. To get around this most CMS will create a subfolder which is set to 777 so something like /var/www/html/mscr/uploads