<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/security.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'security.apache.php',
    1 => 'Installed as an Apache module',
    2 => 'Installed as an Apache module',
  ),
  'up' => 
  array (
    0 => 'security.php',
    1 => 'Безпека',
  ),
  'prev' => 
  array (
    0 => 'security.cgi-bin.shell.php',
    1 => 'Case 4: PHP parser outside of web tree',
  ),
  'next' => 
  array (
    0 => 'security.sessions.php',
    1 => 'Session Security',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'security/apache.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="security.apache" class="chapter">
   <h1 class="title">Installed as an Apache module</h1>

   <p class="simpara">
    When <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> is used as an Apache module it inherits Apache&#039;s user
    permissions (typically those of the &quot;nobody&quot; user). This has several
    impacts on security and authorization. For example, if you are using
    <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> to access a database, unless that database has built-in access
    control, you will have to make the database accessible to the
    &quot;nobody&quot; user. This means a malicious script could access and modify
    the database, even without a username and password. It&#039;s entirely
    possible that a web spider could stumble across a database
    administrator&#039;s web page, and drop all of your databases. You can
    protect against this with Apache authorization, or you can design
    your own access model using LDAP, <var class="filename">.htaccess</var> files, etc. and include
    that code as part of your <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> scripts.
   </p>
   <p class="simpara">
    Often, once security is established to the point where the <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> user
    (in this case, the apache user) has very little risk attached to it,
    it is discovered that <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> is now prevented from writing any files
    to user directories. Or perhaps it has been prevented from accessing
    or changing databases. It has equally been secured from writing
    good and bad files, or entering good and bad database transactions.
   </p>
   <p class="simpara">
    A frequent security mistake made at this point is to allow apache
    root permissions, or to escalate apache&#039;s abilities in some other
    way.
   </p>
   <p class="simpara">
    Escalating the Apache user&#039;s permissions to root is extremely
    dangerous and may compromise the entire system, so sudo&#039;ing,
    chroot&#039;ing, or otherwise running as root should not be considered by
    those who are not security professionals.
   </p>
   <p class="simpara">
    There are some simpler solutions. By using
    <a href="ini.core.php#ini.open-basedir" class="link">open_basedir</a> you can control and restrict what
    directories are allowed to be used for <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>. You can also set up
    apache-only areas, to restrict all web based activity to non-user,
    or non-system, files.
   </p>
  </div>
<?php manual_footer($setup); ?>