Page 1 of 1

PHP rights perhaps?

Posted: Tue Jun 02, 2009 5:15 pm
by pvermont
Hello,

I am battling an issue and hope a kind soul will help me

My PHP script calls Ghostscript to convert a file using an exec call.

The call is:

"gs" -dNOPAUSE -dBATCH -q -sDEVICE=bbox "/var/www/vhosts/FULLPATH/media/images/525.eps"

This call works fine from the command line when I rlogin to my hosted box with root rights. I see the results that I seek. No error message. Life is good.

However when PHP makes the exec call, I receive an error message:

"gs: error while loading shared libraries: libgs.so.8: cannot open shared object file: No such file or directory"

Are there rights or paths I can set so that PHP can make the call properly?

Regards,

pvermont

Re: PHP rights perhaps?

Posted: Tue Jun 02, 2009 6:30 pm
by mikemike
Hi,

I've created a PDF merger in PHP that uses ghostscript in exactly the same way and I have never had this issue.

Ensure your PHP script has been chmod'd to 0777, this was enough for me.

I'm assuming you're calling it with exec()? Could you paste the code?

Re: PHP rights perhaps?

Posted: Tue Jun 02, 2009 6:53 pm
by pvermont
mikemike,

Thanks for the offer to help. I checked chmod and it is set to 777.

Host is running CentOS. Here is the code:

Code: Select all

 
Function apcCreateStandardImageFromEPS ($apcS, $apcD, $apcType, $apcTargetWidth)
{
 
   $apcCommand = '"gs" -dNOPAUSE -dBATCH -q -sDEVICE=bbox "'.$apcS.'" 2>&1'; 
 
   $fred = exec ($apcCommand, $apcResult);
    
    $apcSize = explode(" ",$fred);
    
    $apcWidth = (int) ($apcSize[3] - $apcSize[1]) ;
    
    if ($apcWidth == 0) { //bbox not found, return error
        
        $apcError['0'] = 1;
        $apcError['1'] = '<div class="uploadStatus">'._t("_Unrecognized EPS").'</div>';
                
    } else { //bbox found, do conversion
    
    $apcFactor = $apcTargetWidth / $apcWidth;
    
    $apcWidth = $apcTargetWidth;
    $apcHeight = (int)(($apcSize[4] - $apcSize[2]) * $apcFactor) ;
    
 $apcCommand = '"gs" -dPARANOIDSAFER -dNOPAUSE -dNOPROMPT -dBATCH -dUseCIEColor -sDEVICE=jpeg -dEPSFitPage -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDEVICEHEIGHT='.$apcHeight.' -dDEVICEWIDTH='.$apcWidth.' -dCOLORSCREEN "-sOutputFile='.$apcD.'" "'.$apcS.'"';   //jpg
                                        
exec ($apcCommand, $apcResult);
       
}
Return $apcError;
 
Regards,

pvermont

Re: PHP rights perhaps?

Posted: Tue Jun 02, 2009 7:06 pm
by mikemike
I'm on the same OS. Can you paste an example value of $apcCommand and I'll try it here to see if it's something environment-based. Also, whats version of gs are you running? (gs -v)

Re: PHP rights perhaps?

Posted: Tue Jun 02, 2009 7:24 pm
by pvermont
Problem Resolved.

I installed dependencies using:

yum install libgs.so.8

and all of a sudden it worked. Strange that it worked from the command line (prior to installing dependencies) but not from PHP and even stranger that dependencies from an older version of GS solved the problem.

pvermont