简体   繁体   中英

How to execute sh file by PHP from web page

/root/script/test.sh

echo 'test';

/var/www/html/sh.php

<?php

echo 'start'.PHP_EOL;
echo shell_exec('/bin/sh /root/script/test.sh');
echo 'end'.PHP_EOL

If I run the PHP at local php sh.php , I got start test end , but if I run the php from url, http://example.com/sh.php , I only got start end , the script is not executed, but if I execute echo shell_exec('ls -al'); , it will show the list on web page.

Try This by using file_get_contents :

$path = file_get_contents('/root/script/test.sh');
echo shell_exec($path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM