I am building a dashboard to control couple different websites (each is in a cPanel separate account (including the Dashboard), but all hosted on the same server).
The dashboard will use php’s shell_exec
for example to execute shell commands inside a website’s directory:
shell_exec('cd /home/website/www/app/ && php artisan config:cache')
Or simply read a file:
file_get_content('/home/website/www/app/license');
Of course, by default, accounts are not allowed to have access to each other like this! Is there a way to allow one account/user to access/modify other accounts?
2
Answers
I would use SSH as this would not restrict you having to be on a single server and means that you do not have to breach the isolation of each cPanel account.
https://www.php.net/manual/en/function.ssh2-connect.php
I would suggest using this or alternatively this:
How To Execute SSH Commands Via PHP
Supposing Apache is running as
www-data
in the groupwww-data
any file you need the server to have access to should be group-readable and have the groupwww-data
.You can see what Apache is running as by running:
Also remember, the whole path to the file needs to be readable by the group. In other words, given a file
/path/to/some/file.txt
the directoriespath
,to
, andsome
all need to be group readable and have the groupwww-data
(or whatever Apache is running as).