Dewan159
Dewan159

Reputation: 3084

Access a different hosting account using PHP

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?

Upvotes: 0

Views: 304

Answers (2)

Vince
Vince

Reputation: 3288

Supposing Apache is running as www-data in the group www-data any file you need the server to have access to should be group-readable and have the group www-data.

You can see what Apache is running as by running:

ps aux | egrep '(apache|httpd)'

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 directories path, to, and some all need to be group readable and have the group www-data (or whatever Apache is running as).

Upvotes: 1

Josh Young
Josh Young

Reputation: 1366

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

Upvotes: 1

Related Questions