Skip to content
Advertisement

Linux can’t find process started by PHP [closed]

I’m currently running an own Minecraft Server, and I wanted to build an option to restart the Minecraft server via PHP, so my friends can restart the MC server without needing access to my actual server.

Thus, first I wanted to create a script to start the server:

startup.php

JavaScript

start

JavaScript

After a bit of permission pain etc, by calling the webadress the server can be started.
Now, my problem is that I have no access to the screen process.

When running ps -ef I get:

JavaScript

When running sudo pwdx 29642 to get the process location I get:

JavaScript

But when I go into the /home/minecraft/minecraft_serverdirectory and run either screen -ls or sudo screen -ls, both times I get:

JavaScript

In contrast: When executing the start file manually in the terminal, when running screen -ls I can actually see the process (or open it with screen -r):

JavaScript

I also get the same working directory, but I cannot run the start file manually while the process started py PHP is still running.

I’m really not an expert at all at Linux, I guess theres some user permission interference or something that PHP is treated as an own user, I really don’t know, which is why I’m asking.

How do I access this process started by PHP?

Advertisement

Answer

To create a service using systemd :

Create a file in /etc/systemd/system/ called minecraft-server.service with the following content:

JavaScript

Replace server.jar with full path.

Now lets create the new group and user.

To create new group run the following command:

JavaScript

Now lets create the new user and it it to a group.

JavaScript

Now your service is created, we need to enable it and run it for first time.

JavaScript

Last step to write php script to restart the services:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement