通过PHP Exec()或类似函数启动Minecraft_Server.jar

I'm trying to build a script that starts minecraft_server.jar (location: user directory / mineserver / minecraft_server.jar ).

I have PHP and Apache installed, and I'm trying trying to start the server JAR from /var/www/html/interface.php.

Via console, the server starts fine by running:

java -Xmx1024M -Xms1024M -jar mineserver/minecraft_server.jar nogui

... from the user directory. So in the interface.php file I have the following (note location listed above):

system('java -Xmx1024M -Xms1024M -jar /home/ec2-user/mineserver/minecraft_server.jar nogui', $retval);

But the server never starts after I visit the file. What am I doing wrong?

Thanks for any and all clues.

I want to say thank you for your help on Thanksgiving. While I haven't found the solution yet, I appreciate the efforts. Thanks again.

Have you checked the error log? It's at /var/log/httpd by default. If anything went wrong, it should be there. Otherwise, it could be starting wrong and I would recommend launching it in a screen so you can hop in and check on anything it's doing.

Install screen through whatever method your distribution uses, and then change the launch string to be:
screen -dmS "minecraft" java -Xmx1024M -Xms1024M -jar /home/ec2-user/mineserver/minecraft_server.jar nogui

The command will be executed with the permissions, and the environment of whatever user account the web server runs under.

In particular, it may have a different PATH entry, and the java command might not even be found, or it might be found somewhere else etc...

Also, be aware of what current working directory it is inheriting from your PHP script.

See exec() and check the output to help yourself do some basic debugging.

Also, you probably want something more like

exec('nohup java etc... > /dev/null 2>&1 &');

so that the process gets properly backgrounded and disconnected from the webserver parent process.