<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/install.macosx.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'install.macosx.bundled.php',
    1 => 'Using the bundled PHP prior to macOS Monterey',
  ),
  'up' => 
  array (
    0 => 'install.macosx.php',
    1 => 'Installation on macOS',
  ),
  'prev' => 
  array (
    0 => 'install.macosx.compile.php',
    1 => 'Compiling PHP on macOS',
  ),
  'next' => 
  array (
    0 => 'install.windows.php',
    1 => 'Installation on Windows systems',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'install/macos/bundled.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="install.macosx.bundled" class="sect1">
 <h2 class="title">Using the bundled PHP prior to macOS Monterey</h2>
 <p class="simpara">
  PHP is bundled with macOS since macOS X (10.0.0) prior to macOS Monterey (12.0.0).
  Enabling PHP with the default web server requires uncommenting a few lines in the 
  Apache configuration file <var class="filename">httpd.conf</var> whereas the
  <abbr title="Common Gateway Interface">CGI</abbr> and/or <abbr title="Command Line Interpreter/Interface">CLI</abbr> are enabled by
  default (easily accessible via the Terminal program).
 </p>
 <p class="simpara">
  Enabling PHP using the instructions below is meant for quickly setting up
  a local development environment.  It&#039;s <em>highly recommended</em>
  to always upgrade PHP to the newest version. Like most live software,
  newer versions are created to fix bugs and add features and PHP being is
  no different.  See the appropriate macOS installation documentation for
  further details. The following instructions are geared towards a beginner
  with details provided for getting a default setup to work. All users are
  encouraged to compile, or install a new packaged version.
 </p>
 <p class="simpara">
  The standard installation type is using mod_php, and enabling the bundled
  mod_php on macOS for the Apache web server (the default web server,
  that is accessible via System Preferences) involves the following steps:
 </p>
 <p class="para">
  <ol type="1">
   <li class="listitem">
    <span class="simpara">
     Locate and open the Apache configuration file. By default, the location
     is as follows: <var class="filename">/private/etc/apache2/httpd.conf</var>
    </span>
    <span class="simpara">
     Using <code class="literal">Finder</code> or <code class="literal">Spotlight</code> to find
     this file may prove difficult as by default it&#039;s private and owned by
     the <code class="literal">root</code> user.
    </span>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <span class="simpara">
      One way to open this is by using a Unix based text editor in the
      Terminal, for example <code class="literal">nano</code>, and because the
      file is owned by <code class="literal">root</code> we&#039;ll use the <code class="literal">sudo</code> command
      to open it (as <code class="literal">root</code>) so for example type the following into the
      <code class="literal">Terminal</code> Application (after, it will prompt for
      a password):
      <code class="literal">sudo nano /private/etc/apache2/httpd.conf</code>
     </span>
     <span class="simpara">
      Noteworthy nano commands: <code class="literal">^w</code> (search),
      <code class="literal">^o</code> (save), and <code class="literal">^x</code> (exit) where
      <code class="literal">^</code> represents the Ctrl key.
     </span>
    </p></blockquote>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <span class="simpara">
      Versions of Mac OS X prior to 10.5 were bundled with older versions of
      PHP and Apache.  As such, the Apache configuration file on legacy
      machines may be <var class="filename">/etc/httpd/httpd.conf</var>.
     </span>
    </p></blockquote>
   </li>
   <li class="listitem">
    <p class="para">
     With a text editor, uncomment the lines (by removing the #) that look
     similar to the following (these two lines are often not together,
     locate them both in the file):
     <div class="example-contents screen">
<div class="cdata"><pre>
# LoadModule php5_module libexec/httpd/libphp5.so

# AddModule mod_php5.c
</pre></div>
     </div>
      Notice the location/path. When building PHP in the future, the above
      files should be replaced or commented out.
    </p>
   </li>
   <li class="listitem">
    <p class="para">
     Be sure the desired extensions will parse as PHP (examples:
     <var class="filename">.php</var>, <var class="filename">.html</var>
     and <var class="filename">.inc</var>).
    </p>
    <p class="para">
     Due to the following statement already existing in
     <var class="filename">httpd.conf</var> (as of Mac Panther), once PHP is
     enabled the <var class="filename">.php</var> files will automatically
     parse as PHP.
     <div class="example-contents screen">
<div class="cdata"><pre>
&lt;IfModule mod_php5.c&gt;
    # If php is turned on, we respect .php and .phps files.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Since most users will want index.php to work we
    # also automatically enable index.php
    &lt;IfModule mod_dir.c&gt;
        DirectoryIndex index.html index.php
    &lt;/IfModule&gt;
&lt;/IfModule&gt;
</pre></div>
     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      Before Mac OS X 10.5 (Leopard), PHP 4 was bundled instead of PHP 5 in
      which case the above instructions will differ slightly by changing
      5&#039;s to 4&#039;s.
     </p>
    </p></blockquote>
   </li>
   <li class="listitem">
    <span class="simpara">
     Be sure the DirectoryIndex loads the desired default index file
    </span>
    <span class="simpara">
     This is also set in <var class="filename">httpd.conf</var>. Typically
     <var class="filename">index.php</var> and <var class="filename">index.html</var> are
     used. By default <var class="filename">index.php</var> is enabled because
     it&#039;s also in the PHP check shown above. Adjust accordingly.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Set the <var class="filename">php.ini</var> location or use the default
    </span>
    <span class="simpara">
     A typical default location on macOS is
     <var class="filename">/usr/local/php/php.ini</var> and a call to
     <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span> will reveal this information.
     If a <var class="filename">php.ini</var> is not used, PHP will use all default values.
     See also the related FAQ on
     <a href="faq.installation.php#faq.installation.phpini" class="link">finding php.ini</a>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Locate or set the <code class="literal">DocumentRoot</code>
    </span>
    <span class="simpara">
     This is the root directory for all the web files. Files in this directory
     are served from the web server so the PHP files will parse as PHP before
     outputting them to the browser. A typical default path is
     <var class="filename">/Library/WebServer/Documents</var> but this can be set to
     anything in <var class="filename">httpd.conf</var>.  Alternatively, the default
     <var class="filename">DocumentRoot</var> for individual users is
     <var class="filename">/Users/yourusername/Sites</var>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     Create a <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span> file
    </span>
    <p class="para">
     The <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span> function will display information about PHP.
     Consider creating a file in the DocumentRoot with the following PHP code:
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </p> 
   </li>
   <li class="listitem">
    <span class="simpara">
     Restart Apache, and load the PHP file created above
    </span>
    <p class="para">
     To restart, either execute <code class="literal">sudo apachectl graceful</code> in
     the shell or stop/start the &quot;Personal Web Server&quot; option in the
     macOS System Preferences. By default, loading local files in the browser
     will have an <abbr title="Uniform Resource Locator">URL</abbr> like so:
     <var class="filename">http://localhost/info.php</var> Or using the DocumentRoot
     in the user directory is another option and would end up looking like:
     <var class="filename">http://localhost/~yourusername/info.php</var>
    </p>
   </li>
  </ol>
 </p>
 <p class="simpara">
  The <abbr title="Command Line Interpreter/Interface">CLI</abbr> (or <abbr title="Common Gateway Interface">CGI</abbr> in older versions) is
  appropriately named <var class="filename">php</var> and likely exists as
  <var class="filename">/usr/bin/php</var>. Open up the terminal, read the
  <a href="features.commandline.php" class="link">command line section</a> of the PHP
  manual, and execute <code class="literal">php -v</code> to check the PHP version of
  this PHP binary. A call to <span class="function"><a href="function.phpinfo.php" class="function">phpinfo()</a></span> will also reveal
  this information.
 </p>
</div><?php manual_footer($setup); ?>