I have the following PHP script:
<?php
$fortune = `fortune`;
echo $fortune;
?>
but the output is simply blank (no visible errors thrown).
However, if I run php -a, it works:
php > echo `fortune`;
Be careful of reading health books, you might die of a misprint.
-- Mark Twain
php >
Am I missing a config directive or something that would cause this?
Edit: So, I tried running my script using $ php-cgi fortunetest.php and it worked as expected. Maybe the issue is with Apache2?
Anyways, I found the solution:
fortunelived in/usr/games, so I thought it might be a$PATHissue, but when I didsu www-dataand ran$ fortuneit worked as expected, and/usr/gameswas in$PATH. Apparently, Apache was using a different$PATHvariable even though it was running under userwww-data, so I rewrote the script to use/usr/games/fortuneinstead of plainfortuneand it worked. Sincefortunewasn’t the point of the script, it was kind of a waste of time, but lesson learned.