编程语言
首页 > 编程语言> > PHP exec() has been disabled for security reasons

PHP exec() has been disabled for security reasons

作者:互联网

一、问题

exec('php ' . $path . 'think optimize:schema --table ' . $tableName);

二、分析

exec()被禁用,这应该是个配置,而PHP的配置文件就在php.ini

三、解决

1、法一(推荐):使用shell_exec()方法代替exec()方法

shell_exec('php ' . $path . 'think optimize:schema --table ' . $tableName);
shell_exec(sprintf('cd %s', $file));

2、法二:php配置文件中不禁用exec方法

1)、找到php.ini文件位置

Configuration File (php.ini) Path: /www/web/php/72/etc
Loaded Configuration File:         /www/web/php/72/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

2)、在php.ini文件中找到disable_functions配置并去除exec

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names.
; http://php.net/disable-functions
disable_functions = passthru,exec,system,chroot,chgrp,chown,popen,proc_open,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru
disable_functions = passthru,system,chroot,chgrp,chown,popen,proc_open,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru

3)、重启php服务

标签:functions,shell,exec,reasons,been,disable,ini,php
来源: https://blog.csdn.net/qq_36025814/article/details/115375912