Using PHP to execute terminal commands

泪湿孤枕 提交于 2019-12-13 04:47:22

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/10598561/using-php-to-execute-terminal-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!