Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing .sh scripts via PHP

Tags:

linux

php

sh

I have a few game servers that that I need to run shell scripts for frequality. I'm trying to figure out how to run these scripts via a webpage on the same server. It's a Ubuntu Dedicated server.

The website files are located via /var/www/... The .sh files I need to manually run are located in /home/amservers/.../start.sh.

I've looked at other answers and I still can't figure it out. How do locate the files and store it and then run exec()?

like image 236
devs Avatar asked Jan 13 '23 00:01

devs


1 Answers

You could just use the shell_exec() function in PHP:

http://php.net/manual/en/function.shell-exec.php

shell_exec('sh script.sh');

And if you want to use the variables ($1, $2 etc. in bash) you could just type:

shell_exec('sh script.sh variable1 variable2');
like image 63
Daniel Gelling Avatar answered Jan 16 '23 01:01

Daniel Gelling