{"id":339,"date":"2012-01-24T20:16:59","date_gmt":"2012-01-24T20:16:59","guid":{"rendered":"http:\/\/corbdesign.com\/blog\/?p=339"},"modified":"2012-01-24T20:16:59","modified_gmt":"2012-01-24T20:16:59","slug":"enabling-php-and-apache-in-mac-osx","status":"publish","type":"post","link":"https:\/\/corbinrose.com\/blog\/technology\/enabling-php-and-apache-in-mac-osx\/","title":{"rendered":"Enabling PHP and Apache in Mac OSX"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Enabling PHP and Apache in Leopard<\/h2>\n\n\n<p>[entirely borrowed from&nbsp;<a href=\"http:\/\/foundationphp.com\/tutorials\/php_leopard.php\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/foundationphp.com\/tutorials\/php_leopard.php<\/a>]<\/p>\n\n\n\n<p>Mac OS X 10.5 (Leopard) comes with both Apache 2.2.6 and PHP 5.2.4 preinstalled, but they&#8217;re not enabled by default. The following instructions should help you get up and running.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open BBEdit or TextWrangler (a free, cut-down version of BBEdit available from <a href=\"http:\/\/www.barebones.com\/products\/textwrangler\/index.shtml\" target=\"_blank\" rel=\"noopener noreferrer\">www.barebones.com<\/a>). From the&nbsp;<strong>File<\/strong>&nbsp;menu, select&nbsp;<strong>Open Hidden<\/strong>. In the&nbsp;<strong>Open<\/strong>&nbsp;dialog box, select&nbsp;<strong>All Files<\/strong>&nbsp;from the&nbsp;<strong>Enable<\/strong>&nbsp;drop-down menu. Then navigate to&nbsp;<code>Macintosh HD:private:etc:apache2:httpd.conf<\/code>, and click&nbsp;<strong>Open<\/strong>.<\/li>\n\n\n\n<li>This opens the main configuration file for Apache 2.2.6. It&#8217;s a system file, so you need to unlock it by clicking the icon of a pencil with a line through it at the top-left of the toolbar, as shown in the following screenshot:<\/li>\n\n\n\n<li>You will be told that the document is owned by &#8220;root&#8221;, and be asked to confirm that you want to unlock it. Click&nbsp;<strong>Unlock<\/strong>. This removes the line through the pencil, and readies the file for editing. Normally, when editing system files, it&#8217;s a good idea to make a backup. However, it&#8217;s not necessary in this case, because backup copies of all the Apache configuration files are in the&nbsp;<code>original<\/code>&nbsp;subfolder of the&nbsp;<code>Apache2<\/code>&nbsp;folder.<\/li>\n\n\n\n<li>Scroll down until you find the code shown on line 114 in the following screenshot (although the line number is likely to be the same in your version, it&#8217;s the code that&#8217;s important, not which line it&#8217;s on):<\/li>\n\n\n\n<li>Position your cursor at the beginning of that line, and remove the hash or pound sign (<code>#<\/code>). It should now look like this:<code>LoadModule php5_module &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;libexec\/apache2\/libphp5.so<\/code>This enables PHP 5 on your computer.<\/li>\n\n\n\n<li>Save the file. Because it&#8217;s owned by &#8220;root&#8221;, you will be prompted to enter your Mac password. That takes care of the basic configuration. In theory, you could now start Apache and PHP would be up and running. However, the default installation doesn&#8217;t use the PHP configuration file&nbsp;<code>php.ini<\/code>. You need to need to make a copy of a file called&nbsp;<code>php.ini.default<\/code>, and edit it.<\/li>\n\n\n\n<li>Unfortunately, you can&#8217;t open&nbsp;<code>php.ini.default<\/code>&nbsp;in BBEdit or TextWrangler and save it with a different name. You need to go under the hood of OS X by opening&nbsp;<strong>Terminal<\/strong>in the&nbsp;<code>Applications:Utilities<\/code>&nbsp;folder. Similar to the Command Prompt in Windows, Terminal gives you direct access to the underlying operating system on a Mac.<\/li>\n\n\n\n<li>With Terminal open, type the following series of commands, each followed by Return:<code>cd \/private\/etc sudo cp php.ini.default php.ini<\/code>This moves you into the&nbsp;<code>private:etc<\/code>&nbsp;folder, and then copies&nbsp;<code>php.ini.default<\/code>&nbsp;to&nbsp;<code>php.ini<\/code>&nbsp;in the same folder, using the&nbsp;<code>sudo<\/code>&nbsp;command. You need to use&nbsp;<code>sudo<\/code> because it&#8217;s a system file. Enter your Mac administrator password when prompted. Terminal should now look something like this:<\/li>\n\n\n\n<li>Open&nbsp;<code>php.ini<\/code>&nbsp;in BBEdit or TextWrangler using&nbsp;<strong>Open Hidden<\/strong>&nbsp;in the same way as with<code>http.conf<\/code>. You should find&nbsp;<code>php.ini<\/code>&nbsp;in&nbsp;<code>Macintosh HD:private:etc<\/code>. Click the icon of a pencil with a line through it to enable editing.<\/li>\n\n\n\n<li>How you edit&nbsp;<code>php.ini<\/code>&nbsp;is mainly a question of preference, but the most important change is to a command called&nbsp;<code>error_reporting<\/code>. The default setting (it should be on line 305) looks like this:<code>error_reporting = E_ALL &amp; ~E_NOTICE<\/code>Change it to this:<code>error_reporting = E_ALL<\/code>This ensures that PHP reports all errors. Although no one likes error messages, it&#8217;s vital to eliminate any errors (even seemingly minor ones) before deploying scripts on a live web server.\n<p><strong>NOTE:<\/strong>&nbsp;There are several lines that look similar. Make sure that you edit the line that does NOT begin with a semicolon. A semicolon at the beginning of a line in&nbsp;<code>php.ini<\/code>indicates a comment, which is ignored by the server.<\/p>\n<\/li>\n\n\n\n<li>Save&nbsp;<code>php.ini<\/code>.<\/li>\n\n\n\n<li>You can now start Apache by going to&nbsp;<strong>System Preferences<\/strong>. Click&nbsp;<strong>Sharing<\/strong>&nbsp;in<strong>Internet &amp; Network<\/strong>. Then place a checkmark in&nbsp;<strong>Web Sharing<\/strong>. When Apache starts up, System Preferences should display&nbsp;<strong>Web Sharing: On<\/strong>.<\/li>\n\n\n\n<li>Click the link under&nbsp;<strong>Your computer&#8217;s website<\/strong>. This should launch Safari and display an Apache web page.<\/li>\n\n\n\n<li>Create a page called&nbsp;<code>test.php<\/code>, and type in the following code:<code>&lt;?php phpinfo(); ?&gt;<\/code>Save it in&nbsp;<code>Macintosh HD:Library:WebServer:Documents<\/code>.<\/li>\n\n\n\n<li>Load the following URL into your browser:<code>http:\/\/localhost\/test.php<\/code>If you see the PHP configuration screen, you&#8217;re up and running!<\/li>\n<\/ol>\n\n\n\n<p><strong>NOTE:<\/strong>&nbsp;If you did an upgrade install of Leopard, you cannot view pages stored in your personal&nbsp;<code>Sites<\/code>&nbsp;folder, because the necessary file(s) won&#8217;t have been copied to the correct folder for Apache 2. To copy the file(s), open Terminal and type the following commands, both followed by Return:<\/p>\n\n\n\n<p><code>cd \/private\/etc\/httpd\/users ls<\/code><\/p>\n\n\n\n<p>You should see at least one file that uses your Mac username followed by&nbsp;<code>.conf<\/code>. For example, on my computer, it&#8217;s called&nbsp;<code>davidpowers.conf<\/code>. You need to copy this file for each user to a folder where Apache 2 can find it. Type the following command, using the name of the file on your computer instead of&nbsp;<code>davidpowers.conf<\/code>:<\/p>\n\n\n\n<p><code>sudo cp davidpowers.conf \/private\/etc\/Apache2\/users<\/code><\/p>\n\n\n\n<p>If there are several&nbsp;<code>.conf<\/code>&nbsp;files to copy, you can use the following command instead:<\/p>\n\n\n\n<p><code>sudo cp *.conf \/private\/etc\/Apache2\/users<\/code><\/p>\n\n\n\n<p>However, if you have previously installed the Mac PHP package from&nbsp;<a href=\"http:\/\/www.entropy.ch\/home\/\">Marc Liyanage<\/a>, do<em>not<\/em>&nbsp;copy&nbsp;<code>entropy-php.conf<\/code>.<\/p>\n\n\n\n<p>For this (or any other) change to take effect, go to Sharing in System Preferences, deselect Web Sharing, and then reselect it. This restarts Apache and implements any changes made to the Apache or PHP configuration.<\/p>\n\n\n\n<p>My thanks to Dan Brown for the additional information he provided for these instructions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enabling PHP and Apache in Leopard Mac OS X 10.5 (Leopard) comes with both Apache 2.2.6 and PHP 5.2.4 preinstalled, but they&#8217;re not enabled by default. The following instructions should help you get up and running. NOTE:&nbsp;If you did an upgrade install of Leopard, you cannot view pages stored in your personal&nbsp;Sites&nbsp;folder, because the necessary [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4908,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[17,19],"tags":[],"class_list":["post-339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","category-tutorials","clearfix","post-index"],"acf":[],"jetpack_featured_media_url":"https:\/\/corbinrose.com\/blog\/wp-content\/uploads\/2012\/01\/pexels-photo-177598-1.jpeg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":0,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media\/4908"}],"wp:attachment":[{"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corbinrose.com\/blog\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}