简体   繁体   中英

Using PHP to execute ssh/command line properly

So I need a bit of help in regards to ssh/command lines being run from php.

Out of the gate - yes exec is enabled on the server - its our own dedicated box

The setup. I have created a script that uses cpanel's api to create sub domains for a particular account. That's all fine and dandy and everything works as expected. Now - we have a wildcard SSL installed as well.

The long and short of it is this. Under the present conditions if you pulled up: https://user.domain.com you would only see the top root directory for the account, NOT the directory it should be in. But if you use it without the https - it does what it should. Now it's a dedicated box with HostGator and they had this script they installed for me to do what needs to be done - and that works as expected.

The script HostGator installed is located at: /var/cpanel/userdata/account/mdssl

So the line they gave me to run the script and do what it should do is as follows:

./mdssl clone domain.com user.domain.com

So my question is - because I have never really worked with shell stuff inside of php, would the following line be a workable example of how to execute the script?

shell_exec('/var/cpanel/userdata/account/mdssl clone domain.com user.domain.com');

or do I just need the exec command? And should the opening line be any different? I just need to tap that line using php and pass the 'user' field to it and have the script do its thing to clone the setup for the SSL so that the wildcard features work properly and the users account lands in the proper directory it should.

Any insight is appreciated! :)

Thank you very much.

I've only used exec() or system()

They're always tricky and tend not to behave as expected.

I would start off with

ini_set("display_errors", 1);

exec('/var/cpanel/userdata/account/mdssl clone domain.com user.domain.com', $output);

var_dump($output);

See what the output says or if a PHP error is occurring.

You may also need to escape out of the current directory of whatever default you're in with ../ and make sure apache user has access to mdssl (or whatever user your system uses). You may need to sudo it.

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