Page 1 of 1

Executing commands (linux) with PHP

Posted: Tue Jan 18, 2005 12:34 pm
by xrob
Hi,
I'm not really sure the best way to appoach this but basically i want to be able to run game server commands in a specific linux account eg.

'screen -A -m -d -S hlds_server1 ./hlds_run -game cstrike -autoupdate +servercfgfile server1.cfg &' from the account game-servers pw = 'xxxxample'

Whats the best way to go about this?
is the best way todo this with sockets? and sending like ssh commands?
because i want to run this from a webserver not local to the game-servers is this even possible?

Could someone point me in the right direction please.

If this has been discussed before i'm sorry for repost but i couldnt find anything on the net that really made me any the wiser. If there have been previous threads relating to this subject please link me.

regards
rob

Posted: Tue Jan 18, 2005 12:51 pm
by feyd
since the game server will be remote, I'd go in the ssh direction. Although I have no idea how that'd be done. It'll depend a lot on your web server's configuration and the amount of access your host provides.

What about running a secured web server on the game server?

There's a PECL package for SSH2 connectivity: http://pecl.php.net/package/ssh2 it's in beta right now..

Posted: Tue Jan 18, 2005 2:58 pm
by xrob
hmmm... this is a possability... in fact, i think i'll play around with it tonight. I'll let you know how i got on tommorow
Regards
Rob

Posted: Wed Jan 19, 2005 2:02 am
by xrob
I am using Debian Woody with kernel 2.6.9
I have apache and apache-ssl installed working with PHP and MySql
I do './configure' to my extracted libssh2-0.5.tar.gz
This all Runs perfectly and say Yes to everything bar these 2 are they important? or needed?

Code: Select all

'checking whether we are cross compiling... no
checking whether byte ordering is bigendian... no'
Everything else in the './configure' has yes or the related file it needs.

Code: Select all

'configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating include/libssh2_config.h'
Ok so next i exec 'make all install'

Code: Select all

'makeї1]: Entering directory `/usr/lib/php4/20010901/ssh2/src'
gcc -o channel.o channel.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o comp.o comp.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o crypt.o crypt.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o hostkey.o hostkey.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o kex.o kex.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o mac.o mac.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o misc.o misc.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o packet.o packet.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o scp.o scp.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o session.o session.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o sftp.o sftp.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o userauth.o userauth.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Wall -g -I../include/ -fPIC
gcc -o libssh2.so  channel.o comp.o crypt.o hostkey.o kex.o mac.o misc.o packet.o scp.o session.o sftp.o userauth.o  -L/usr/local/ssl/lib -lcrypto -L/usr/local/lib -lz -shared
makeї1]: Leaving directory `/usr/lib/php4/20010901/ssh2/src'
gcc -o ssh2_sample.o ssh2_sample.c -c -g -O2 -I/usr/local/ssl/include -I/usr/local/include -Iinclude/ -Wall -g
gcc -o ssh2_sample ssh2_sample.o -lssh2 -Lsrc/
./mkinstalldirs /usr/local/include
./mkinstalldirs /usr/local/lib
makeї1]: Entering directory `/usr/lib/php4/20010901/ssh2/src'
/usr/bin/install -c libssh2.so /usr/local/lib'
Are any of these errors ?
After this i changed the php.ini extension_dir=/usr/local/lib
I then added the line extension=libssh2.so at the end of php.ini (with debian when i used apt-get install it arranges the files in weird places, but all the other PHP/MySQL works fine. all i had todo was move mysql.so to /usr/local/lib)
Now heres the problem when i stop and start apache/apache-ssl servers this error appears (on both of them).

Code: Select all

'PHP Warning:  Invalid library (maybe not a PHP library) 'libssh2.so'  in Unknown on line 0'
It still starts by the way
Apache SSL phpinfo()
Apache phpinfo()

So what exactly do i need to do to get this thing working properally?
Is there anything i need to do to apache-ssl to get this to work? does anything need putting in the httpd.conf ?
Same goes for the php.ini does anything else need changing in that ?
You can see what exactly is being loaded on those links above so u should be able to see if i am missing anything.

regards
rob

Posted: Thu Jan 20, 2005 8:47 am
by xrob
I got it working in the the end

'pear install ssh2-beta'

cheers