krishnanunni Posted January 16, 2012 Share Posted January 16, 2012 Hi all, I am a newbie to PHP. I'm trying to execute a program from my PHP script by calling the exec() function of PHP. It works fine when i try it from command line, or execute the script in command line. But when i call it from a php script in my apache, it does nothing. No errors are thrown. What i get in return is only an empty array. i'm using Ubuntu 11.10 and Apache 2.2 with PHP 5.3.3 thanks for helping me. Quote Link to comment https://forums.phpfreaks.com/topic/255135-the-exec-call-does-not-work-from-web-server/ Share on other sites More sharing options...
trq Posted January 16, 2012 Share Posted January 16, 2012 We can't help you without seeing code. Quote Link to comment https://forums.phpfreaks.com/topic/255135-the-exec-call-does-not-work-from-web-server/#findComment-1308134 Share on other sites More sharing options...
krishnanunni Posted January 17, 2012 Author Share Posted January 17, 2012 <?php $htmlcontent=$_POST['source']; $pngname=$_POST['pngname']; $height=$_POST['height']; $width=$_POST['width']; if(!isset($htmlcontent)){die('No HTML Cannot Proceed');} $sourcefile='/var/www/CutyCapt/Sources/sourcefile.html'; $pngfile='/var/www/CutyCapt/Captures/'.$pngname; $hyperlink='http://my.domain.com/CutyCapt/Captures/'.$pngname; $htmlfile=fopen($sourcefile,'w') or die('Source Initialization Failed'); fwrite($htmlfile,$htmlcontent); fclose($htmlfile); if(!file_exists($sourcefile)){die('Parser Source Does not Exist! Operation aborted');} //Generate SnapShot shell_exec('/usr/bin/CutyCapt --html='.$sourcefile.' --out='.$pngfile.' --min-height='.$height.' --min-width='.$width); //shell_exec('/usr/bin/CutyCapt --html=source.htm --out=test.png --min-height=600 --min-width=800'); if(!file_exists($pngfile)){die('Image Not Created');} else echo $hyperlink; ?> This is my code. This can work fine, when i try from terminal, with php interpreter the script works fine. But when it comes to webserver, it wont execute at all. All libs and CutyCapt resides in /usr/bin/ only. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/255135-the-exec-call-does-not-work-from-web-server/#findComment-1308449 Share on other sites More sharing options...
trq Posted January 17, 2012 Share Posted January 17, 2012 It's likely your servers user doesn't have sufficient permissions. Quote Link to comment https://forums.phpfreaks.com/topic/255135-the-exec-call-does-not-work-from-web-server/#findComment-1308482 Share on other sites More sharing options...
krishnanunni Posted January 17, 2012 Author Share Posted January 17, 2012 Thanks all for replies. I got the solution, as it was because, in Apache user context, the XServer is not available. So I just executed it using xvfb-run. It worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/255135-the-exec-call-does-not-work-from-web-server/#findComment-1308487 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.