当前位置:网站首页>PHP executes shell script
PHP executes shell script
2022-07-26 09:49:00 【Color the sky】
original text :https://blog.csdn.net/zhangsheng_1992/article/details/52805760
php As a server-side scripting language , You can also call system commands , This includes execution shell Script
To write test.sh The script is as follows
#! /bin/sh
mkdir /www/a
It's a very simple one shell Script Create a folder
php The script is as follows
system('/usr/bin/test.sh')
Before running The first thing to verify
1.test.sh Whether the script has executable permission
2.apache nginx phttp etc. web Whether the server has test.sh Authority
3. Because it is the command to synchronize files Therefore, it is necessary to ensure that the user has write permission to the directory to be downloaded
4. Because I use php Version higher than 5.4, The security mode has been deleted , There is no such thing as running in safe mode
5. Please use the absolute path for the executed script That's important
however After actual operation I found the output faild It indicates that the script did not execute successfully Check the reason Because apache The user does not have the permission to execute some directories ( No user has no user's executable directory , Your script needs to be in this directory ) Switching directory ownership is easy to cause security problems stay linux Next root Users are not subject to this restriction therefore Temporarily allow users to switch to root jurisdiction It can simply avoid such problems How to operate ?
First View your apache Users or nginx php-fpm user
have access to ps -ef | grep httpd Order to see Others in the same way
After checking my apache The user is _www user
then visudo perhaps vim /etc/sudoers find
## Allow root to run any commands anywhere
root ALL=(ALL) ALL This business Add
_www ALL=(root) NOPASSWD:ALL
The first column is users The second is the user who can switch to I wrote here root If you want to switch freely, you can write here All The third is the executable script path ALL Express all
Last restart apache Let users regain permissions
modify php Script
system('sudo /usr/bin/test.sh')
function Successful implementation ~~~
边栏推荐
- In the same CONDA environment, install pytroch first and then tensorflow
- Solve the problem of storing cookies in IE7 & IE8
- [information system project manager] summary of essence of high-level series for the first time
- 图解用户登录验证流程,写得太好了!
- “互联网+”时代的现代医学
- Why does new public chain Aptos meet market expectations?
- Node memory overflow and V8 garbage collection mechanism
- 2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
- 高斯消元求解异或线性方程组
- Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)
猜你喜欢
Matlab Simulink realizes fuzzy PID control of time-delay temperature control system of central air conditioning
Qt随手笔记(三)在vs中使用QtCharts画折线图
Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice
挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
Gauss elimination solves the inverse of matrix (Gauss)
小白搞一波深拷贝 浅拷贝
Xiaobai makes a wave of deep copy and shallow copy
uni-app学习总结
Fuzzy PID control of motor speed
QT handy notes (III) use qtcharts to draw a line chart in VS
随机推荐
Matlab Simulink realizes fuzzy PID control of time-delay temperature control system of central air conditioning
QT handy notes (III) use qtcharts to draw a line chart in VS
js 表格自动循环滚动,鼠标移入暂停
Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)
asp. Net using redis cache
Smart gourmet C language
QT handy notes (VI) -- update interface, screenshot, file dialog box
Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res
asp. Net using redis cache (2)
一种分布式深度学习编程新范式:Global Tensor
Logical architecture of MySQL
Great reward for interview questions
JS判断数据类型 Object.prototype.toString.call和typeof
Customize permission validation in blazor
Mo team learning summary (II)
Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
(1) Hand eye calibration of face scanner and manipulator (eye on hand)
Uni app learning summary
Node memory overflow and V8 garbage collection mechanism
网站设计需要的基本知识