EverKB

Knowledge Base Ever

Linux上提升PHP運行exec命令權限的方法

2019-12-14 13:41:14

標籤: Linux, PHP, exec, sudoers, PHP提升權限

在Linux上,PHP部署在apache的場景中,運行exec命令時的權限是apache用戶的,此用戶的權限受限制,能執行的系統命令很少。此時我們可以通過修改Linux的sudoers配置來允許sudo執行命令。
vim /etc/sudoers

apache ALL=(ALL) NOPASSWD: ALL
配置完成後,PHP運行命令時,需要在命令前加上sudo。
exec('sudo dmidecode -s system-serial-number', $result);

標籤

CentOS7 CentOS PHP Linux Python3 Python MySQL MariaDB YUM JavaScript CSS Redis MySQL8 caching_sha2_password HTML mysql_native_password PHP7 PostgreSQL sub folder availability eth0 MariaDB10.4 SOCKS5 Web Server date Install MongoDB pdo_sqlsrv register_shutdown_function Symfony File Upload mssql-tools sqlsrv Zend Framework ADDDATE DevExpress JetBrain php-fpm Shadowsocks-Libev unixODBC-devel height network interface Port 80 string Aura error_get_last SOCKS Web Development data INDENTIFIED BY password policy requirements Redis5 SVN Fedora Media Writer msodbcsql SQLAlchemy absolute Deepin jemalloc Shadowsocks toggle convert FuelPHP mysqlclient PHPUnit Framework ss5.passwd at-symbol Error Control Operator margin SOCKET vps daemon process IIS password sudoers center Fatal Errors MongoDB4 SQL Server 2017 WiFi .htaccess DATE_SUB Phalcon set_error_handler TestCase Compiling PHP frequency conflict ss5.conf apr Elasticsearch7.3 PHPUnit Slim Vincent Garreau daemon HTTP particles.js Sudo Failed to build these modules: _uuid MongoDB SQL Server width DATE_ADD ip command pg_bha.conf scrollbar Tcp BBR Compiling Apache Frameworks MySQL-python ss5-3.8.9 Apache2.4 Elasticsearch libpython3.7m.so.1.0 PHPStorm show VIM CURLOPT_POSTFIELDS NodeJs substr Bluetooth Failed to build these modules: _ctypes Minimal ISO SQL Date Funcitons Wi-Fi date sub INTERVAL PECL root Tag Cloud CodeIgniter font-size ss5 apache httpd dual network interfaces Laravel ShadowsocksR vertical-align CURLFille horiz-align node.js PyCharm SUBDATE BarManager exec mb_substr SOCKS5 Proxy Server WebStorm date add IntelliJIDEA PEAR remi Tag Chrome find src Apache du jQuery PHP5.5 Shadowsocks-Python V2Ray cURL hide nginx