简体   繁体   中英

Php exec can't print using cups

If i run lpr from root, or even run from apache

runuser -l apache -c 'lpr -P RICOH_Aficio_2032 -r /var/www/html/website/tmp/test.txt'

works like a charm.

However, when i print using php_exec

exec('lpr -P RICOH_Aficio_2032 -r /var/www/html/website/tmp/test.txt 2> /var/www/html/website/tmp/error.txt');

i get the following error

lpr: Permission denied

I even set apache as the owner of test.txt

Php exec works when i use ls, cat ecc. But lpr and lpstat don't work.

What's wrong?

Note: i'm on Centos 6.8 with php 5.6

After some research, i found the problem.

Selinux didn't let the httpd service access lpr/cups.

Disabling Selinux solved the problem. Note: i don't need Selinux in my situation, but if you faced the same problem, note that disabling Selinux can be a security flaw, especially if the server is accessible outside of your network. Just add the rules to Selinux to let httpd/php do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM