Home > php教程 > php手册 > body text

php的exec()函数执行外部Linux脚本问题

WBOY
Release: 2016-06-06 19:52:20
Original
2243 people have browsed it

环境:PHP+linux下的apache php中的exec函数可以执行很多命令(脚本)使用比较方便,但是在linux下需要给与权限。修改/etc/sudoers文件,做两处改动: 1)在文件中添加apache的用户,我用的apache2的用户名是nobody,有的是httpd,www-data等(查看一下自己的

  环境:PHP+linux下的apache
  
  php中的exec函数可以执行很多命令(脚本)使用比较方便,但是在linux下需要给与权限。修改/etc/sudoers文件,做两处改动:

1)在文件中添加apache的用户,我用的apache2的用户名是nobody,有的是httpd,www-data等(查看一下自己的apache的配置文件即可)。添加的格式:nobody ALL=(ALL) NOPASSWD: ALL(格式在/etc/sudoers文件中有)。

2) 注释掉default requiretty.(大部分时候,exec不能正确执行都是由这一行没有注释掉引起的)

 

  后记:之所以发文是因为每次总是忘记了第二条。导致在网上搜索,不过好像没有人真正解释过。希望此文能提醒自己,帮助别人吧。......

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!