botshara Posted December 24, 2016 Share Posted December 24, 2016 (edited) Hello im trying to start a server via php script, but the server doesn't starting.. shell_exec is enabled and I have renamed a mta-server to mta-server.sh.. I know that start server using root is not securely and cool, but Im just trying <?php if ($_GET['start'] == 'true') { shell_exec("echo 'rootpw' | sudo -u root -S /home/mtarp/mta-server.sh"); echo 'Server started'; } else { echo 'something wrong'; } ?> Edited December 24, 2016 by botshara Link to comment
Arran Posted December 24, 2016 Share Posted December 24, 2016 According to http://php.net/manual/en/function.shell-exec.php shell_exec returns some information in a string so change these 2 lines: shell_exec("echo 'rootpw' | sudo -u root -S /home/mtarp/mta-server.sh"); echo 'Server started'; Into this: $result = shell_exec("echo 'rootpw' | sudo -u root -S /home/mtarp/mta-server.sh"); echo 'Result of shell_exec: ' . $result; And maybe it will give you an error message. 1 Link to comment
Rataj Posted December 25, 2016 Share Posted December 25, 2016 I'm not entirely sure about this, but you shouldn't rename mta-server to .sh file. So try to run it as it is, to execute the file you can also try ./ at the start. Example (untested): shell_exec("echo 'rootpw' | sudo -u root -S ./home/mtarp/mta-server"); I hope it will help you, otherwise tell us more about your problem. Does it give you any errors? Is problem within PHP or Linux? Link to comment
myonlake Posted December 27, 2016 Share Posted December 27, 2016 On 25.12.2016 at 11:20 PM, Rataj said: I'm not entirely sure about this, but you shouldn't rename mta-server to .sh file. So try to run it as it is, to execute the file you can also try ./ at the start. Example (untested): shell_exec("echo 'rootpw' | sudo -u root -S ./home/mtarp/mta-server"); I hope it will help you, otherwise tell us more about your problem. Does it give you any errors? Is problem within PHP or Linux? Well, if you want to run it as a screen or do something else while at it, that's why he's not running the server directly. Link to comment
Rataj Posted December 27, 2016 Share Posted December 27, 2016 1 hour ago, mgmmcaobbm said: Well, if you want to run it as a screen or do something else while at it, that's why he's not running the server directly. That would be reason for creating .sh file (that will for example start the server with screen utility), not renaming "mta-server" to that. Link to comment
myonlake Posted December 27, 2016 Share Posted December 27, 2016 Just now, Rataj said: That would be reason for creating .sh file (that will for example start the server with screen utility), not renaming "mta-server" to that. I see now, I just didn't expect anyone to do that in the first place. Link to comment
botshara Posted December 28, 2016 Author Share Posted December 28, 2016 Thanks for help, but I fixed this. I added after command '2>&1' and it showed "debug", I needed to create a new user which run a .php script, because password for that user which runed php script was false. There is any chance run a server via start paramters? Something like that ./mta-server.sh --IP blabla --password blabla Link to comment
myonlake Posted December 28, 2016 Share Posted December 28, 2016 30 minutes ago, botshara said: Thanks for help, but I fixed this. I added after command '2>&1' and it showed "debug", I needed to create a new user which run a .php script, because password for that user which runed php script was false. There is any chance run a server via start paramters? Something like that ./mta-server.sh --IP blabla --password blabla No. You'll need to make your own script to handle multiple server configurations and instances. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now