averagecoder Posted October 3, 2019 Share Posted October 3, 2019 I have a PHP file in /var/www/html/ called foobar.php with the following content: Quote <?php shell_exec('/usr/bin/env > /tmp/output'); ?> From the backend I can run php foobar.php. It works as expected. When I browse to my website and go to foobar.php, the /tmp/output file does not receive anything. I set the permissions of the foobar.php file to different settings. I set the owner and group of foobar.php and /tmp/output to different values. I tried modifying the httpd.conf file. When I placed this stanza in the httpd.conf file Quote LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so I could not restart the httpd service. I tried using just Quote LoadModule php7_module modules/libphp7.so But this failed too. I thought PHP would interpret the file regardless of how I access it (e.g., via a web page and with the php command from a Linux terminal). How do I get PHP to invoke a Bash command when someone visits a .php web page? Quote Link to comment https://forums.phpfreaks.com/topic/309321-how-do-i-get-php-to-invoke-a-bash-command-when-someone-browses-the-page-in-a-web-browser/ Share on other sites More sharing options...
requinix Posted October 3, 2019 Share Posted October 3, 2019 PHP will execute the file - assuming, of course, you have a functioning PHP setup and don't mess with it. Try executing env normally (from within PHP) and see if you get output. Otherwise try creating/writing to /tmp/output and see if that's the problem. Quote Link to comment https://forums.phpfreaks.com/topic/309321-how-do-i-get-php-to-invoke-a-bash-command-when-someone-browses-the-page-in-a-web-browser/#findComment-1570242 Share on other sites More sharing options...
gizmola Posted October 3, 2019 Share Posted October 3, 2019 The /tmp directory is typically setup with the "sticky bit" set. Let's assume that you created the /tmp/output file using your command line execution. What is the ownership of that file? What web server are you running? There are many different configurations possible. It's possible that your script is running but it can't overwrite the original file due to ownership issues and the sticky bit. Also you might attempt to capture the return value from shell_exec and look at that: $output = shell_exec('/usr/bin/env > /tmp/output'); echo "<pre>$output</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/309321-how-do-i-get-php-to-invoke-a-bash-command-when-someone-browses-the-page-in-a-web-browser/#findComment-1570245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.