AV1611 Posted January 2, 2008 Share Posted January 2, 2008 I've seen this question before, but never gotten a good answer to it: I want to start a problem on my linux box via my personal web site. I know it's possible with PHP because I use webmin to start and stop programs all the time. I know it's more than a simple string, as I have to log to the local machine etc. Can someone point me in the right direction or a howto or tutorial or something? Thanks. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 Like this? http://us.php.net/function.exec I assume you mean start a process and not a problem. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 No, that won't work. If you do exec('xterm'); it doesn't start an xterm on the server. (it doesn't show up in "top".) The program I want to run is not xterm, but it will do for this discussion. I think apache user is not allow to start local processes, so there's a mod that webmin uses or something. If I do $e=exec('ls'); echo $e it works. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 The reason xterm will fail is because it will fail to find a display (a window). Its not called xterm for nothing, and needs to be called from within an x windows system. Exec will give you direct access to the shell however and can easily execute programs which have a command line interface. What program do you wish to run exactly? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 Ah, that makes sense about no x handle I run an america's army server, for example. It's not up all the time. I want to create a way to start it up via a web page. (I can do it via ssh, but don't like giving ssh out to people...) The command is "/path/to/file/server-bin -some -switches" via ssh I use "&" so I can close the session and leave the server running. I don't need to be able to kill the server, but may change my mind on that... Quote Link to comment Share on other sites More sharing options...
revraz Posted January 2, 2008 Share Posted January 2, 2008 My clanmate wrote some cpanels for various games, I'll see if he has one for AA. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 I see no reason why exec wont work. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 <?php exec('/path/to/file/server-bin -switches mapname.aao'); ?> that doesn't do anything. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 So, thats your actual code then? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 <?php exec('/home/username/apps-lnxded-2.8.1/server-bin GLOBAL map_name.aao -nohomedir ini=server.ini &''); ?> That's the exact script except the user name Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 What is the permissions on /home/username/apps-lnxded-2.8.1/server-bin Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 -rwxrwxrwx Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 sorry about the double post... Maybe the whole folder needs to be -rwxrwxrwx ? Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 I see no reason why it wont execute then. PHP isn't running in safe mode is it? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 as far as I know it's not, but can you tell me how to verify that? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 The server runs in a chrooted jail. I run ISPConfig on Linux. Could that be part of it? Is exec() limited by that? Just a thought Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Shouldn't effect it. Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Sorry, you'll need to check a phpinfo() page to see whats enabled / disabled. Either that or take a look at your php.ini Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 looks off to me but here: http://truthsoldiers.com/server2.php Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Actually, thinking about the jail. Unless the program your trying to execute is within the same filesystem (which it does not look like) then you won't be able to execute it. The entire /home directory will not exist within the chroot environment. Sorry I didn't click to it earlier but I should imagine that is your problem. the only work around I can see would be to install the application within the same chroot. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 2, 2008 Author Share Posted January 2, 2008 Let's review: Because the virtual domain is chrooted to /var/www/virtualname/ then /home doesn't exist. "/" is actually "/var/www/virtualname/" If I mkdir /var/www/virtualname/home then copy /home/username/foldername to /var/www/virtualname/home/foldername all is well. Is my understanding of how the chrooted jail work correct? Quote Link to comment Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Is my understanding of how the chrooted jail work correct? Your understanding of a chroot seeams sound. I suppose it depends on what exactly this server-bin file is. Is it the complete executable for this server? How in fact did you install this server application? Is it linked to the actual system in any way? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 3, 2008 Author Share Posted January 3, 2008 I untared and mod'ed the ini's. no install, no compiling. I did notice that when I try to execute it with ssh it gives me an error if I don't do it from the /home/username/aops-lnxded-2.8.1/System folder. It complains about not finding ../System/somefile I make a shell script that does cd /path/to/System /path/to/server-bin then did exec('sh /path/to/file.sh'); but it still doesn't work, but the sh works in ssh from anywhere. Quote Link to comment Share on other sites More sharing options...
trq Posted January 3, 2008 Share Posted January 3, 2008 You could try using chdir prior to calling exec. Quote Link to comment Share on other sites More sharing options...
AV1611 Posted January 3, 2008 Author Share Posted January 3, 2008 That did it. Now I need to figure out how to kill the process. I figured out how to get the PID, but I guess I need to kill it as root... any clue how to do that with exec? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.