I'm trying to execute a binary on my Linux web server. The binary is called 'phantomJS' which is used mainly to create screenshots of a webpage.
I logged into my cPanel and found the following information about my server:
Operating system : Linux
Architecture : i686
So I went ahead and downloaded phantomjs-1.9.0-linux-i686.tar.bz2
from the phantomJS website. I also uploaded three more files to the same folder in which phantomjs
was present:
- test.php (which is the main file which will be executed in the browser)
- test.js (which contains the code to start phantomjs)
- createScreenshot.php (which contains code that outputs some HTML)
So all the files are in the same folder. Thus, there shouldn't a problem arising out due to a wrong path.
exec('phantomjs test.js');
var page = require('webpage').create();
var url = 'createScreenshot.php';
page.open(url, function (status) {
page.render('test.png');
phantom.exit();
});
echo '<h1>This should be converted to an image</h1>';
Now when I browse to www.mydomain.com/test/test.php
, all I get is a blank page, which is fine as the only thing that should happen is the creation of an image in the test folder, but that never happens. No error is being output. I also tried putting error_reporting(E_ALL)
inside test.php
, but still no error was shown, just a blank page.
I decided to test whether exec is at all enabled on my server. I did so by using
echo exec('whoami');
This printed out my cPanel username. So this means exec is working.
The next thing I did was to check for folder permissions. test folder had 755
permission and so did phantomjs. I tried changing both to 777
but that didn't help either.
This makes me believe that something is wrong with phantomjs file. I'm out of ideas on what to try next. I sure think that I downloaded the correct package from the phantomJS website (phantomjs-1.9.0-linux-i686.tar.bz2
).
Is there anything else that I can do to debug the issue?
Running
echo exec("ls -lh");
printed out
-rw-r--r-- 1 abc abc 1.8K Apr 6 05:15 third-party.txt
This third-party.txt is in the folder which holds the phantomjs binary, but I wonder why only one file name was printed. There are php and js files too in the same folder as third-party.txt. Not really sure 1 stands for in the above output though