1

I am trying to run a bash script from an html file using php. I've read this question (how to run a .sh file from php?) and followed it exactly but cannot seem to get it to work.

I have two files in my downloads folder on my mac. These are the file names and their content:

hello.sh

echo hello world

test.html

<?php
echo shell_exec('sh /Users/fred/downloads/thing.sh');
?>

I ran this command in command line while in the downloads folder:

open test.html

This resulted in a blank page being opened in chrome while I was expecting to get a page with "hello word" in it.

Thanks for the help.

Community
  • 1
  • 1
fred
  • 11
  • 2

2 Answers2

1

rewrite your bash file in nano as

#! /bin/bash

echo "hello world"

In the command line type "bash hello.sh" to execute, this will test if it is working or not.

test.html rewrite to test.php php code only work with *.php extension.

Komal Bandi
  • 67
  • 1
  • 7
0

rename 'test.html' to 'test.php'. also check the file name here

echo shell_exec('sh /Users/fred/downloads/thing.sh');

i think this should be

echo shell_exec('sh /Users/fred/downloads/hello.sh');

If again you face the same issue then may be your apache server doesn't have permission to access 'hello.sh'.

Yash Goel
  • 530
  • 1
  • 6
  • 15