Source of: /manual/en/install.macosx.bundled.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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',
),
'up' =>
array (
0 => 'install.macosx.php',
1 => 'Installation on Mac OS X',
),
'prev' =>
array (
0 => 'install.macosx.packages.php',
1 => 'Using Packages',
),
'next' =>
array (
0 => 'install.macosx.server.php',
1 => 'Compiling for OS X Server',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="install.macosx.bundled" class="sect1">
<h2 class="title">Using the bundled PHP</h2>
<p class="simpara">
PHP has come standard with Macs since OS X version 10.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
<acronym title="Common Gateway Interface">CGI</acronym> and/or <acronym title="Command Line Interpreter/Interface">CLI</acronym> 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's <em class="emphasis">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 MAC OS X 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 Mac OS X for the Apache web server (the default web server,
that is accessible via System Preferences) involves the following steps:
</p>
<p class="para">
</p><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 <i>Finder</i> or <i>Spotlight</i> to find
this file may prove difficult as by default it's private and owned by
the <i>root</i> user.
</span>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
One way to open this is by using a Unix based text editor in the
Terminal, for example <i>nano</i>, and because the
file is owned by <i>root</i> we'll use the <i>sudo</i> command
to open it (as <i>root</i>) so for example type the following into the
<i>Terminal</i> Application (after, it will prompt for
a password):
<i>sudo nano /private/etc/apache2/httpd.conf</i>
</span>
<span class="simpara">
Noteworthy nano commands: <i>^w</i> (search),
<i>^o</i> (save), and <i>^x</i> (exit) where
<i>^</i> represents the Ctrl key.
</span>
</p></blockquote>
<blockquote><p><b class="note">Note</b>:
<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: .php .html
and .inc)
</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>
<IfModule mod_php5.c>
# 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
<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
</pre></div>
</div>
</p>
<blockquote><p><b class="note">Note</b>:
Before 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's to 4's.
<br />
</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'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 Mac OS X is
<var class="filename">/usr/local/php/php.ini</var> and a call to
<a href="function.phpinfo.php" class="function">phpinfo()</a> 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 <i>DocumentRoot</i>
</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 <a href="function.phpinfo.php" class="function">phpinfo()</a> file
</span>
<p class="para">
The <a href="function.phpinfo.php" class="function">phpinfo()</a> function will display information about PHP.
Consider creating a file in the DocumentRoot with the following PHP code:
</p><div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php phpinfo</span><span style="color: #007700">(); </span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<p>
</p>
</li>
<li class="listitem">
<span class="simpara">
Restart Apache, and load the PHP file created above
</span>
<span class="simpara">
To restart, either execute <i>sudo apachectl graceful</i> in
the shell or stop/start the "Personal Web Server" option in the
OS X System Preferences. By default, loading local files in the browser
will have an <acronym title="Uniform Resource Locator">URL</acronym> 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>
</span>
</li>
</ol><p>
</p>
<p class="simpara">
The <acronym title="Command Line Interpreter/Interface">CLI</acronym> (or <acronym title="Common Gateway Interface">CGI</acronym> 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 <i>php -v</i> to check the PHP version of
this PHP binary. A call to <a href="function.phpinfo.php" class="function">phpinfo()</a> will also reveal
this information.
</p>
</div><?php manual_footer(); ?>