shell commands with php
Hello, I am trying to create a screen capture program with Xvfb server, ImageMagick and Khtml2PNG.
I seem to be having some issues and was hoping someone could help me out.
I have everything installed and working on a centos WHM/CPanel system and am able to generate the screen shots and save them to root folder from shell with the following commands.
Xvfb :2 -screen 0 1024x768x24&
khtml2png2 --sw 200 --sh 150 http://www.example.com example.png
It works 100% fine when you run it from shell.
I have created the following php script to run the exact same commands but get no results.
$connection = ssh2_connect('xxxxxxxxxxxxxx', 22);
ssh2_auth_password($connection, 'root', 'xxxxxxxxxxxxxx');
$stream = ssh2_exec($connection, 'Xvfb :2 -screen 0 1024x768x24&');
$stream = ssh2_exec($connection, 'export DISPLAY=localhost:2.0');
$stream = ssh2_exec($connection, 'khtml2png2 --sw 200 --sh 150 http://www.example.com example.png');
echo "All done!";
Does anyone know why this would work fine from shell but NOT work at all when I run it from the php script?
Thanks in advance!
Are you running those commands as root on the CLI as well? Also, why do you use ssh2_connect rather than system or exec or popen?
Well I am using ssh2 to run the commands cause it's the only way I know how to run them as root. Do you know of another way to login as root though php without ssh2_connect? When I use system() or exec() it's always as user nobody when I do whoami... any suggestions?
Setup up a sudoers to allow your php user to execute the particular commands you would like and then you can use system or exec.
That's the only solution to that I've found as well, but then it's not executing over the network which is slightly better.
I have tried to set it up like the following but still doesn't work.
www-data ALL = NOPASSWD: export DISPLAY=localhost:2.0
www-data ALL = NOPASSWD: /usr/bin/Xvfb
www-data ALL = NOPASSWD: /usr/local/bin/khtml2png2
www-data ALL = NOPASSWD: /root
Am I doing this right?
|All times are GMT -5. The time now is 09:42 PM.|