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.