0

I bought a VPS server, and I want to run terminal commands from the file /var/www/html/command.php. I want to run this command:

cd /A_DIR

and

bash start.sh

I tried this in command.php:

<form action="" method="POST">
<input type="submit" name="run" id="id" value="run" />
<?php
if(isset($_POST['run'])){
     exec('cd /A_DIR');
     exec('bash start.sh');
}    
?>
</form>

But it doesn't work. I'm new to VPS server hosting :( I don't know how to set permissions for server's users.

user: root
New contributor
Bogdan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

put on hold as off-topic by George Udosen, dessert, Thomas, Tom Brossman, vanadium Jan 14 at 11:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – George Udosen, dessert, Thomas, Tom Brossman, vanadium
If this question can be reworded to fit the rules in the help center, please edit the question.

0

I suspect that each exec is a new shell so the cd doesn't "stick". Try a single exec instead:

 exec('cd /A_DIR; bash start.sh');

Not the answer you're looking for? Browse other questions tagged or ask your own question.