title: CentOS 7 unable to connect clamd.sock file (Permission denied error)
body: <p>I am trying to scan uploaded files on PHP server using clamAV. I've installed ClamAV on my server (Centos 7). Currently, I am using PHP 7, so I am using Clamd socket connection to scan uploaded files. I've enabled PHP sockets, clamd.sock file is present at <code>/var/run/clamd.scan/</code> folder with apache owner. </p>
  
  <p>My Socket connection code - </p>
  
  <pre><code>        $socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
  
          if(socket_connect($socket, '/var/run/clamd.scan/clamd.sock')) {
              return $socket;
          }
  </code></pre>
  
  <p>When I try to run above code on the browser I am getting error as <code>socket_connect(): unable to connect [13]: Permission denied</code>, But if I run the PHP code through command line with a user as root it is working fine.</p>
  
  <p>I know there is some issue with SELinux policy with Centos as if I disable SELinux policy everything is working fine from the browser as well. I have checked <code>httpd_can_network_connect --&gt; on</code> and <code>antivirus_can_scan_system --&gt; on</code> both are on. </p>
  
  <p>The issue is with accessing anything inside <code>/var/run/</code> folder for <code>apache</code> user, there is something (some policy) from SELinux which is stopping apache to connect to clamd socket file. Any ideas? </p>