使用PHP执行终端命令 [英] Using PHP to execute terminal commands

查看:176
本文介绍了使用PHP执行终端命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用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

推荐答案

看看 exec 系统等: http:/ /www.php.net/manual/en/book.exec.php

显然,如果你打算使用 sudo 对于根访问的东西(不推荐),那么你需要提供一个密码以某种方式或设置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.

可能最好使用 SSH 调用,并提供通过该命令执行的命令。

It may be better to use an SSH call for this and supply the command to execute via that command.

总之,我真的不建议使用PHP(或任何语言)来运行一系列命令,然后使用 sudo

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

这篇关于使用PHP执行终端命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆