I am trying to spool a file to a printer attached to the server using PHP.
I send a command such as lp -d 'Brother_QL-570' '/Users/user_name/Documents/wwwroot/mmsprint/mmsUw8Vv9 using EXEC in PHP and get a return value of 5. The command works fine in the terminal window.
If I send ls, whoami etc, the command executes fine.
whoami and ls live in /bin, so I created a symbolic link for lp and that made no difference.
Also tried /usr/bin/lp and that did not work either. I’m pulling what little hair I have left out over this.
Safe mode is off. The path variables are the same between PHP and my terminal environment.
I am running MAMP on Lion.
FWIW, the command cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570 has a return value of 133.
This is my code:
$temp_file = tempnam("./", 'mms');
$pdf->Output($temp_file, "F");
$pdf->Close();
$cmd = "lp -d 'Brother_QL-570' '".$temp_file."'";
exec($cmd,$output,$retval);
error_log("-----cmd=".$cmd."\n", 3, "printCard.log");
foreach ($output as $a) {
error_log("-----output=".$a."\n", 3, "printCard.log");
}
error_log("-----retval=".$retval."\n", 3, "printCard.log");
Any thoughts? What am I missing? This should be easy. Argh!!
What is the output from the command?
Most likely the PHP user (apache probably) has no permission to print things. Add that user to the lp group. (Assuming macs work similar to unix in this.)