PHP exec command issue

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
dave_c00

PHP exec command issue

Post by dave_c00 »

Hi,

I am having trouble executing the following imagemagick command within my PHP code:

Code: Select all

exec('/usr/local/bin/mogrify -rotate 90 /home/s/test.jpg');
The command:

Code: Select all

/usr/local/bin/mogrify -rotate 90 /home/s/test.jpg
works fine from my command line so am confused as to why it doesn't work when using exec. I have successfully executed a cp command from the script ok so exec is working If I run the PHP script with the exec command in it from the command line using:

Code: Select all

php5 /home/s/test.php


it runs fine.

Anyone any ideas..? It is really frustrating as i'm sure it isnt a big problem.

Cheers,

Dave
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PHP exec command issue

Post by Bonzo »

Its probably a path problem and comes up a lot - comand knows where IM is but php does not.

I can not remember the fix; you could search the users and developers sections and see if you can find an answer. The answer may depend if you are on a shared server or one of your own.

What result do these give you:

Code: Select all

<?php
echo "<pre>";
system("type convert"); 
echo "</pre>";
?> 

Alternative method
<?php
echo "<pre>";
system('which convert',$path); print_r($path); 
echo "</pre>";
?> 
If you are on a windows server you need to change the ' to " I do this anyway.

May be of help:
Set PATH environment variable in the PHP or tell your administartors that the PHP command path is not set right for IM and GS. If the web server has the right path PHP usally inherits it and then it can find things properly!
dave_c00

Re: PHP exec command issue

Post by dave_c00 »

Thanks for your reply,

For some reason when running those 2 commands within PHP I get no response at all for the first one and a 1 for the second.

From the command line on my Linux Server I get the correct paths:

Code: Select all

root@ds6580:~# type convert
convert is /usr/local/bin/convert

Code: Select all

root@ds6580:~# type mogrify
mogrify is /usr/local/bin/mogrify
It seems that the imagemagick commands using the system and exec call are not working.. Getting "type convert" within a PHP script to work will probably get it all to work me thinks..

I am using PHP 5.1.2 and ImageMagick 6.6.2-3.

Any ideas?

Interstingly enough this works:

Code: Select all

echo "<pre>";
system("type cp");
echo "</pre>";
returning:

Code: Select all

cp is /bin/cp
Cheers
dave_c00

Re: PHP exec command issue

Post by dave_c00 »

Funny I can do a:

Code: Select all

system('type /usr/local/bin/mogrify');
and I get:

Code: Select all

/usr/local/bin/mogrify is /usr/local/bin/mogrify
but not a:

Code: Select all

system('type mogrify');
so I am thinking its maybe a user problem or a path problem...
Post Reply