Jump to content

start server via php


botshara

Recommended Posts

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 by botshara
Link to comment

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.

  • Like 1
Link to comment

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
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
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

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
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.

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...