I want to work on a custom linux hosting control panel based on my experience in managing LEMP/LAMP stack. This is just a pet project. I believe I have ran into some hurdle.
The CP is being written in PHP and server by NginX as default server on port 8000. I am not using any framework, just vanilla PHP.
In putty, logged in as root, I can get the system uuid like this:
[root@localhost ~]# dmidecode -s system-uuid
997C4DE8-213B-4ACC-8E23-01E79D6CC12F
When I try this in PHP with the following script:
var_dump(shell_exec('dmidecode -s system-uuid 2>&1'));
I get the following:
sh: dmidecode: command not found
How can I execute that above command get the output in PHP?
Nginx/PHP-FPM is running as user nginx
. Do i need to add nginx user to root group?
I want to be able to execute very specific commands like: /etc/init.d/php-fpm restart
from my control panel (to restart php-fpm gateway).
How can I achieve this? What are my options? How does control panel like cPanel, DirectAdmin, etc... do it?
Update
I have tried the following method also. Installed sudo
and used the sudo visudo
command and added the following lines at the end:
nginx ALL=(ALL) NOPASSWD:/path/to/php_shell.sh
Defaults:nginx !requiretty
and the content of php_shell.sh
is:
#!/bin/bash
dmidecode -s system-uuid
Now, I tried to execute it like this:
var_dump(shell_exec('sudo sh /path/to/php_shell.sh 2>&1'));
I get: sudo: no tty present and no askpass program specified