创建一个web应用程序,可以在我的ubuntu服务器上一键安装、卸载软件包


create a web application that could one-click install, uninstall packages on my ubuntu server

我只需要创建一个web应用程序,它可以在我的ubuntu服务器上单击包,我真的不知道从哪里开始。。想到用php来做,但由于安全问题,这不是一个公平的想法。

对不起,我是新手。

谢谢你的帮助。

您不应该这样做

回答你的问题,是的,这是可能的。这可以通过在shell_exec()中执行"sudo apt-get…"来完成。这将要求Web服务器具有对root权限的无密码访问权限。

我有没有说过你不应该这样做

如果你试图远程管理一台计算机,你应该使用SSH登录它,避免使用PHP的不必要的体操,或者使用Webmin这样的基于web的界面,它可以正确地为你做这些事情。

使用system()/shell_exec()是正确的。我认为它对您来说"不起作用",因为您的Apache进程所有者没有root权限(您需要root才能安装软件包)。顺便说一句,你使用的任何其他编程语言实现都是一样的:你需要root才能安装软件包。

你可以将你的Apache进程所有者设置为"root",但当你尝试重新启动它时,你会得到这个:

Error:    Apache has not been designed to serve pages while
running as root.  There are known race conditions that
will allow any local user to read any file on the system.
If you still desire to serve pages as root then
add -DBIG_SECURITY_HOLE to the CFLAGS env variable
and then rebuild the server.
It is strongly suggested that you instead modify the User
directive in your httpd.conf file to list a non-root
user.

您可以自己编译Apache,以允许使用root用户运行Apache,如上所述。

总之,你想做的是可能的,但你正在打开一个非常大的安全漏洞。

你不应该这样做。

请改用SSH。