mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
211 lines
7.8 KiB
XML
211 lines
7.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 xml:id="install.macosx.bundled" xmlns="http://docbook.org/ns/docbook">
|
|
<title>Using the bundled PHP prior to macOS Monterey</title>
|
|
<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 <filename>httpd.conf</filename> whereas the
|
|
<acronym>CGI</acronym> and/or <acronym>CLI</acronym> are enabled by
|
|
default (easily accessible via the Terminal program).
|
|
</simpara>
|
|
<simpara>
|
|
Enabling PHP using the instructions below is meant for quickly setting up
|
|
a local development environment. It's <emphasis>highly recommended</emphasis>
|
|
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.
|
|
</simpara>
|
|
<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:
|
|
</simpara>
|
|
<para>
|
|
<orderedlist>
|
|
<listitem>
|
|
<simpara>
|
|
Locate and open the Apache configuration file. By default, the location
|
|
is as follows: <filename>/private/etc/apache2/httpd.conf</filename>
|
|
</simpara>
|
|
<simpara>
|
|
Using <literal>Finder</literal> or <literal>Spotlight</literal> to find
|
|
this file may prove difficult as by default it's private and owned by
|
|
the <literal>root</literal> user.
|
|
</simpara>
|
|
<note>
|
|
<simpara>
|
|
One way to open this is by using a Unix based text editor in the
|
|
Terminal, for example <literal>nano</literal>, and because the
|
|
file is owned by <literal>root</literal> we'll use the <literal>sudo</literal> command
|
|
to open it (as <literal>root</literal>) so for example type the following into the
|
|
<literal>Terminal</literal> Application (after, it will prompt for
|
|
a password):
|
|
<literal>sudo nano /private/etc/apache2/httpd.conf</literal>
|
|
</simpara>
|
|
<simpara>
|
|
Noteworthy nano commands: <literal>^w</literal> (search),
|
|
<literal>^o</literal> (save), and <literal>^x</literal> (exit) where
|
|
<literal>^</literal> represents the Ctrl key.
|
|
</simpara>
|
|
</note>
|
|
<note>
|
|
<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 <filename>/etc/httpd/httpd.conf</filename>.
|
|
</simpara>
|
|
</note>
|
|
</listitem>
|
|
<listitem>
|
|
<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):
|
|
<screen>
|
|
<![CDATA[
|
|
# LoadModule php5_module libexec/httpd/libphp5.so
|
|
|
|
# AddModule mod_php5.c
|
|
]]>
|
|
</screen>
|
|
Notice the location/path. When building PHP in the future, the above
|
|
files should be replaced or commented out.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
Be sure the desired extensions will parse as PHP (examples: .php .html
|
|
and .inc)
|
|
</para>
|
|
<para>
|
|
Due to the following statement already existing in
|
|
<filename>httpd.conf</filename> (as of Mac Panther), once PHP is
|
|
enabled the <filename>.php</filename> files will automatically
|
|
parse as PHP.
|
|
<screen>
|
|
<![CDATA[
|
|
<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>
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
<note>
|
|
<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's to 4's.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
Be sure the DirectoryIndex loads the desired default index file
|
|
</simpara>
|
|
<simpara>
|
|
This is also set in <filename>httpd.conf</filename>. Typically
|
|
<filename>index.php</filename> and <filename>index.html</filename> are
|
|
used. By default <filename>index.php</filename> is enabled because
|
|
it's also in the PHP check shown above. Adjust accordingly.
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
Set the &php.ini; location or use the default
|
|
</simpara>
|
|
<simpara>
|
|
A typical default location on macOS is
|
|
<filename>/usr/local/php/php.ini</filename> and a call to
|
|
<function>phpinfo</function> will reveal this information.
|
|
If a &php.ini; is not used, PHP will use all default values.
|
|
See also the related FAQ on
|
|
<link linkend="faq.installation.phpini">finding php.ini</link>.
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
Locate or set the <literal>DocumentRoot</literal>
|
|
</simpara>
|
|
<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
|
|
<filename>/Library/WebServer/Documents</filename> but this can be set to
|
|
anything in <filename>httpd.conf</filename>. Alternatively, the default
|
|
<filename>DocumentRoot</filename> for individual users is
|
|
<filename>/Users/yourusername/Sites</filename>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
Create a <function>phpinfo</function> file
|
|
</simpara>
|
|
<para>
|
|
The <function>phpinfo</function> function will display information about PHP.
|
|
Consider creating a file in the DocumentRoot with the following PHP code:
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php phpinfo(); ?>
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
Restart Apache, and load the PHP file created above
|
|
</simpara>
|
|
<para>
|
|
To restart, either execute <literal>sudo apachectl graceful</literal> in
|
|
the shell or stop/start the "Personal Web Server" option in the
|
|
macOS System Preferences. By default, loading local files in the browser
|
|
will have an <acronym>URL</acronym> like so:
|
|
<filename>http://localhost/info.php</filename> Or using the DocumentRoot
|
|
in the user directory is another option and would end up looking like:
|
|
<filename>http://localhost/~yourusername/info.php</filename>
|
|
</para>
|
|
</listitem>
|
|
</orderedlist>
|
|
</para>
|
|
<simpara>
|
|
The <acronym>CLI</acronym> (or <acronym>CGI</acronym> in older versions) is
|
|
appropriately named <filename>php</filename> and likely exists as
|
|
<filename>/usr/bin/php</filename>. Open up the terminal, read the
|
|
<link linkend="features.commandline">command line section</link> of the PHP
|
|
manual, and execute <literal>php -v</literal> to check the PHP version of
|
|
this PHP binary. A call to <function>phpinfo</function> will also reveal
|
|
this information.
|
|
</simpara>
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|