downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/security.apache.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'security.apache.php',
   
1 => 'Installed as an Apache module',
  ),
 
'up' =>
  array (
   
0 => 'security.php',
   
1 => 'Security',
  ),
 
'prev' =>
  array (
   
0 => 'security.cgi-bin.shell.php',
   
1 => 'Case 4: PHP parser outside of web tree',
  ),
 
'next' =>
  array (
   
0 => 'security.filesystem.php',
   
1 => 'Filesystem Security',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div>
   <h1>Installed as an Apache module</h1>

   <p class="simpara">
    When PHP 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
    PHP 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 PHP scripts.
   </p>
   <p class="simpara">
    Often, once security is established to the point where the PHP user
    (in this case, the apache user) has very little risk attached to it,
    it is discovered that PHP 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.sect.safe-mode.php#ini.open-basedir" class="link">open_basedir</a> you can control and restrict what
    directories are allowed to be used for PHP. 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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites