LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2010, 02:43 PM   #1
unknown1
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Rep: Reputation: 0
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&
export DISPLAY=localhost:2.0
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&');
sleep(15);
$stream = ssh2_exec($connection, 'export DISPLAY=localhost:2.0');
sleep(2);
$stream = ssh2_exec($connection, 'khtml2png2 --sw 200 --sh 150 http://www.example.com example.png');
sleep(7);

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!
 
Old 01-10-2010, 02:03 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
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?

Regards,

Alunduil
 
Old 01-10-2010, 11:33 PM   #3
unknown1
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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?


Quote:
Originally Posted by alunduil View Post
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?

Regards,

Alunduil
 
Old 01-11-2010, 11:08 AM   #4
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
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.

Regards,

Alunduil
 
Old 01-12-2010, 12:50 PM   #5
unknown1
LQ Newbie
 
Registered: Dec 2009
Posts: 3

Original Poster
Rep: Reputation: 0
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?





Quote:
Originally Posted by alunduil View Post
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.

Regards,

Alunduil

Last edited by unknown1; 01-12-2010 at 01:04 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
executing shell commands in PHP mohtasham1983 Programming 7 09-14-2007 11:04 AM
Executing shell commands through PHP!!! Richtown Linux - Newbie 6 04-12-2006 02:57 PM
Running shell commands thru PHP JonathonReinhart Linux - Software 1 12-23-2005 02:05 AM
[PHP] Sending shell commands from PHP pEeDy Programming 4 11-04-2005 08:06 PM
PHP to run Shell commands Gear_freak2000 Linux - Software 4 06-04-2003 05:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration