Kill a process from website

centos, kill-process, linux, php, su

Solution

The problem is, that the process you want to kill does not belong to the apache user (apache usually runs as `www-data` with group `www-data`). If you give apache more rights (say run it as user `root`), your PHP script would run with more rights and could do things like this. But this would be dangerous, because if there is a security flaw in apache or your php script, a malicious attacker could take over your system.

Instead I suggest using the setuid bit.

- Create a file `kill.sh` with the content `pkill python`

- Make it executable (`chmod a+x kill.sh`)

- Make it belong to root (`chown root:root kill.sh`)

- Make it setuid (`chmod u+s kill.sh`)

- Invoke this script from your php script

Problem

I have the code and everything which is: ``` pkill python ``` However I wanted to run it from a php script like this: ``` echo shell_exec("pkill python"); ``` I get an output which says: ``` bash: pkill: (1503) - Operation not permitted ``` I know what the problem is, which is that pkill is su command. Anyway to change this so that the php script can run it?

Original source

Related problems