How can PHP be used to create a number of commands in the terminal? For example, if I want to change the permissions on a folder or a file, I might run
Sudo Chmod 777 FileName
from the command line. How could I do this with PHP?
How can PHP be used to create a number of commands in the terminal? For example, if I want to change the permissions on a folder or a file, I might run
Sudo Chmod 777 FileName
from the command line. How could I do this with PHP?
Look at exec
, system
etc: http://www.php.net/manual/en/book.exec.php
Obviously, if you are going to use sudo
for root access stuff (not recommended) then you would need to either supply a password somehow or set the user which PHP is running as to not require a password.
It may be better to use an SSH
call for this and supply the command to execute via that command.
To sum up, I really don't recommend using PHP (or any language for that matter) to run a series of commands which then uses sudo
To give permission to folder or file in php use following line of code
chmod($file,0777);
this will change the permission of file or folder.