I ran into this simple, but annoying, problem after I migrated my development workstation to Fedora 12.
Problem:
A large PHP application that I have developed at Submerged Solutions (SandPiper Accounting) began throwing Permission Denied (13) system exceptions when attempting to send mail through Zend Framework’s Zend_Mail library.
All the phpunit unit tests worked fine and could send e-mail, but would fail when the usability tests started and any HTTP requests that sent e-mail were handled through Apache.
The Apache instance was being run as user apache / group apache, and php (mod_php) is run as user apache / group apache.
The exception occurred in Zend_Mail_Protocol_Abstract->_connect(), immediately following the socket opening call “stream_socket_client(…)”.
File: Zend/Mail/Protocol/Abstract.php; Line 224
50: abstract class Zend_Mail_Protocol_Abstract
51: {
...
218: protected function _connect($remote)
219: {
220: $errorNum = 0;
221: $errorStr = '';
222:
223: // open connection
224: $this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
225: ...
fopen() calls using http and ftp protocols also failed:
Warning: fopen(…) [function.fopen]: failed to open stream: Permission denied in …
The fix:
The problem turned out to be the “httpd_can_network_connect” SELinux setting that is on by default in Fedora 12.
In a shell console, run as root:
# /usr/sbin/setsebool httpd_can_network_connect=1
Thanks to durwood, who pointed this out on PHP.net.
“Bug” Report at RedHat.com.
More info on SELinux.
Technorati Tags: apache, Debugging, permission denied, php, selinux, stream_socket_client, zend framework, zend_mail