LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Start/Stop and Restart server by PHP (https://www.linuxquestions.org/questions/linux-server-73/start-stop-and-restart-server-by-php-697487/)

Tomek58 01-15-2009 07:44 AM

Start/Stop and Restart server by PHP
 
Hello!
I would like write panel with start/stop/restart my server.

I start my server in console this command:

Quote:

screen -A -m -d -S hlds ./hlds_run1 -game cstrike -nomaster +exec server.cfg
And i write: ps x

Quote:

vz138:/# ps x
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 init [2]
1692 ? Ss 0:00 SCREEN -A -m -d -S hlds ./hlds_run1 -game cstrike -no
1693 pts/1 Ss+ 0:00 /bin/sh ./hlds_run1 -game cstrike -nomaster +exec ser
1702 pts/1 S+ 18:26 ./hlds_i686 -game cstrike -nomaster +exec server.cfg
7727 ? Rs 0:00 vzctl: pts/2
7728 pts/2 Ss 0:00 -bash
7732 pts/2 R+ 0:00 ps x
It's OK. I wrote script SHELL: start.sh

Quote:

#!/bin/sh
screen -A -m -d -S hlds ./hlds_run3 -game cstrike -nomaster +exec server.cfg
And script: start.php

PHP Code:

<?PHP
exec
("sh /var/www/cs1/start.sh");
?>

But server isn't start. Why?

robertjinx 01-15-2009 07:55 AM

Because PHP runs as user apache or httpd and your script or cs server runs with different user.

You need to run apache as root, but thats a very very bad idea, or cs server which the same user rights as php is running.

Tomek58 01-15-2009 08:16 AM

I have lighttpd. So i change in lighttpd.conf:

Quote:

server.username = "www-data" >>>> server.username = "root"
server.groupname = "www-data" >>>> server.groupname = "root"
??

Now LIGHTTPD isn't start:

Quote:

vz138:/# /etc/init.d/lighttpd start
Starting web server: lighttpd2009-01-15 15:13:59: (server.c.706) I will not set uid to 0

robertjinx 01-15-2009 09:26 AM

Seems like lighttpd is build to not allowed to run the web server with root user, which is a super good idea. Try to run the lighttpd and cs server with a normal user, like "joe" ... you get my point, and make sure that the rights for the cs server belong to joe... because I suppose that server can run also as a normal user not just root.

rweaver 01-15-2009 09:47 AM

Quote:

Originally Posted by Tomek58 (Post 3409689)
I have lighttpd. So i change in lighttpd.conf:



??

Now LIGHTTPD isn't start:

The log told you exactly why it wouldn't start- It refuses to set it's id to root (which is a very good thing.) A better answer is to setup the cs server to run as the same user as the webserver (www-data).


All times are GMT -5. The time now is 08:03 AM.