开发者

Execute Bash script on a different server through PHP

开发者 https://www.devze.com 2023-03-10 12:12 出处:网络
I think I understand how to execute a bash script on the same server exec(\'./myshell.sh\'); Completely new to this kind of thing so excuse me if this is completely wrong. But I\'m wondering how I

I think I understand how to execute a bash script on the same server

exec('./myshell.sh');

Completely new to this kind of thing so excuse me if this is completely wrong. But I'm wondering how I would execute a bash script 开发者_开发问答on a different server? Reason is I want the bash script to execute some stuff on my dedicated Minecraft server but our website is hosted on another.

Thanks for any help in advance.


Well, I see two ways to do it:

  1. Make your php application ssh into the minecraft server and run the command as seen here.
  2. Put your php app on the remote server

I think choice 1 will be the one you have to go with. If you do that, you'll also need to follow the tutorial at Moravec.net in order to allow password-less login to the remote system.


Do you absolutely need to trigger events on your minecraft server on demand, instead of checking against your webserver on a regular basis? It may be worth it to use a cronjob on the minecraft server and have it poll the webserver via wget for whether or not it should execute that bash script.

This keeps your webserver and minecraft server isolated, and keeps you from having to install additional services like a webserver (which will eat up a bunch of resources that you NEED for the minecraft dedicated server program) or writing your own micro socket-server to listen for a request to run the script.


You can use PHPs very own ssh2_exec after connecting to a prepared remote server.

If that extension is not available, you can of course just do:

exec('ssh user@server.name ./myshell.sh');

(Where a certificate authorization setup would be preferrable.)


You could execute a remote shell script from your PHP program using ssh.


There is the following option:

http://php.net/manual/en/book.ssh2.php

Which is probably your worst bet, but it would work. I would, however, suggest a RESTful type of service. Have a web script that runs on your "minecraft server" and just send a request to that script to execute the bash file you want. You could apply this to anything, but a web based service is probably the easiest.

0

精彩评论

暂无评论...
验证码 换一张
取 消