This question already has an answer here:
I'm trying to create directory on my local apache server with php.
I tried<?php mkdir("folder"); ?>
and<?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 errorPHP 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!
</div>
Sounds like Apache doesn't have permission to create the folder. Either give Apache ownership of the folder (where you're trying to create a new one)
sudo chown www-data /var/www/html/mscr
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
<?php mkdir("folder", 777, true); ?>