title: How to prevent access to folder in Apache2 and allow access in PHP?
body: <p>I know this question has been asked several times, however I tried many combinations and none appears to be working.</p>
  
  <p>This is a section from my <code>apache.conf</code> file:</p>
  
  <pre><code>&lt;Directory /&gt;
      Options None
      AllowOverride None
      Require all denied
  &lt;/Directory&gt;
  
  &lt;Directory /var/www/&gt;
      Options -Indexes -FollowSymLinks -ExecCGI
      AllowOverride Limit
  
      # Restrict access controls to all HTTP methods except the named ones (GET)
      &lt;LimitExcept GET&gt;
          Require all denied
      &lt;/LimitExcept&gt;
  
      # Restrict access controls to the GET HTTP method, by only allowing
      # requests coming from the specified IPs
      &lt;Limit GET&gt;
          # Clients in the specified IP address ranges can access the resource,
         Require ip &lt;list of IPs here&gt;
      &lt;/Limit&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>How do I configure <code>apache.conf</code> file so that directory <code>/var/www/html/somefolder</code> is not accessible from the outside but it is accessible from PHP scripts running on the server?</p>
  
  <p>I tried adding this right below the above code:</p>
  
  <pre><code>&lt;Directory /var/www/html/denied_directory&gt;
      Order allow,deny
      &lt;Files some_private_file.txt&gt;
          Order deny,allow
      &lt;/Files&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>I also tried with <code>Files</code> and <code>Location</code>, but they either do not work (that is, clients from the outside are still being able to access the folder) or they work <em>too well</em> (that is, PHP scripts are not able to access the folder and files).</p>
  
  <p>Thank you in advance to anyone who will spend some of his/her time trying to help me.</p>