Php – Create a folder in the /root directory


I've tried everything online but I couldn't find a real solution, I have a php file that in local on my computer works perfectly, instead when I load it on my seerver it doesn't create the folder.
the php contains this string to create a new folder:

shell_exec("mkdir /root/users/$username");

I guess that maybe it's a problem of permission, I can just create folders in the var/www folder, dI tried a lot of different way to set my permission but I can't figure it out.

Best Solution

You should use mkdir to create folder or chmod to change permissions functions.

for example:

mkdir('newFolder', 775);

or you want to create on some path. Currently you are in /home/username/public_html/project/

mkdir('subproject', 775); // it will create in `project` folder. 

if you want to create with some root like you asked in your question.

mkdir('/root/users/'.$username, 775);

I am sure it will be fix your issue and also a standard way to create.