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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look at
exec,systemetc: http://www.php.net/manual/en/book.exec.phpObviously, if you are going to use
sudofor 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
SSHcall 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