简体   繁体   中英

Running command-line application from PHP which can be run with sudo

I am a newbie here, I am having a bash script which can be executed through terminal with sudo permission only. I want to run it from PHP with proper security. I dont know where to start to accomplish this considering security in mind. Should I create a additional user or what Will be the better way to achieve this. I got a reference with Running command-line application from PHP as specific user , but I am using Nginx and the mentioned solution does not work for me.

NGINX is a web server and not the interpreter. It is not very relevant.

In the standard NGINX + PHP-FPM setup, you should have a separate system user for your website anyway. So you don't need to create an extra user just for that command.

Simply ensure that this "website user" is able to sudo run your script, without being prompted for their password. This is achieved by visudo .

example ALL=/path/to/your/script

Where example is the PHP-FPM pool user, aka, the "website user" and the owner of the website's files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM