Upgrading the Native PHP Installation on OS X Mountain Lion

Upgrading the Native PHP Installation on OS X Mountain Lion

Tutorial Details
  • Topics: PHP, Web Development
  • Difficulty: Advanced
  • Estimated Completion Time: 45 Minutes

Let’s see how we can manually upgrade the native OS X 10.8 PHP installation to the newest version (currently 5.4.5) and get some other useful software installed while we’re at it. *AMP packages are practical, but rarely up-to-date, so absorbing the procedure depicted in this article is invaluable to every PHP developer.


The Theory of Building From Source

If you’re only interested in the practical aspect of installing PHP, feel free to skip this section, but it might be useful for you later on to know how it actually works and why certain commands are necessary.

Every installation of software from source follows basically the same chain of commands: Download the source files, configure, make, optionally test, install.

Configure

The “configure” script tells “make” what’s going to be built. Executed by typing “./configure”, the configure script analyzes dependencies, verifies you’re running a supported OS, sets up the necessary files for the given OS and finally generates a makefile, which when “make” is called, dictates how and what exactly is to be built.

“configure” tells “make” what’s going to be built

If the configure script finds missing dependencies or errors, it performs an exit and stops execution, allowing the user to remove or work around any obstacles before proceeding. The configure command always comes first when building from source.

Make

Next, “make” builds what configure told it to build. “make” is initialized by simply typing “make”, and is actually a GNU utility which is generally used to maintain a set of files and recompile them if necessary.

“make” builds what configure told it to build

To function, it requires a makefile – a file in which its directives are described and relationships between the files in question are noted. Once run, the make command reads the makefile and performs the tasks.

The “make test” command runs the make command but also tests the compilation against a test target. Not all source distributions support “make test”, so unless explicitly specified in the installation documentation of the software being installed, one is to use the regular “make”.

The “make test” command runs the make command but also tests the compilation against a test target.

“sudo make install” installs the files that “make” built into predefined folders. It handles all inclusions, updates and resolves paths and moves everything to where it should be. Effectively, it finishes the installation and the user typically doesn’t need to do anything else.

This is actually exactly what Homebrew – the package manager we install in the next section – can do. It can execute the same flow, internally. You don’t really see any of it directly, but more or less the same chain is executed, if the “formula” submitted by the “brewer” is made that way.

It makes the entire process less cumbersome by automatically checking for dependencies and installing them before moving onto the main designated package. It then downloads and unarchives it and executes the configure, make, make install chain to finish up the installation.

Almost every installation from source follows the same steps: download, configure, make, install.

Homebrew

In order for the installation of PHP to go as smoothly as possible, we need to install Homebrew, a package manager for OSX which can handle a lot of installations for you – installations that might otherwise require complex build procedures and can have critical dependencies which take hours to resolve.

Having Homebrew installed will benefit you in the long run.

Having Homebrew installed will benefit you in the long run, not just for the purpose of this article. It offers a quick way to install common libraries and software without having to build from source.
To install it, we need to do the following (skip this section if you have Homebrew installed):

  1. Install XCode via the App store. Once installed, install Command Line Tools through the XCode app itself, or download and install from http://developers.apple.com. We need XCode and CLT because Homebrew requires them.
  2. Install X11 from here. This is also a Homebrew requirement. Pick the latest version available, not necessarily the one linked here.
  3. Install Homebrew from GitHub.
  4. If you run into problems, you might have to do the following after step 1 and 2:
    $ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    $ ln -s /opt/X11 /usr/X11
    

    ..taken from this post. This happens on some instances of Mountain Lion for some reason.

Once done, run brew doctor and verify that everything works (as per instructions on Homebrew’s website).


PHP

Predictably, installing PHP requires you to have certain libraries installed. Luckily, Homebrew is here to handle these installations for us. Install the following:

brew install libjpeg
brew install pcre
brew install libxml2
brew install mcrypt

Once done, download the PHP source files from Php.net. Unpack the archive, open your terminal, and switch to the source folder (e.g. cd ~/Downloads/php-5.4.5/ or wherever else you downloaded the sources).

If you’re planning to work with Zend Framework 2 and want to start with the sample skeleton application as made by Rob “Akrabat” Allen, or if you intend to deploy your application in multiple langauges, you need php-intl support. To allow the configure script to take php-intl into consideration while building the makefile, we need to install another dependency – ICU. Download this from ICU-Project.org and execute:

tar xzvf icu4c-4_8_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
make
sudo make install

This handled all the basic dependencies PHP could ever want from us (for now). We can now finally build and install it.

Installing

First, while in PHP’s unarchived source folder, execute the following configure command:

./configure  \
--prefix=/usr  \
--mandir=/usr/share/man  \
--infodir=/usr/share/info  \
--sysconfdir=/private/etc  \
--with-apxs2=/usr/sbin/apxs  \
--enable-cli  \
--with-config-file-path=/etc  \
--with-libxml-dir=/usr  \
--with-openssl=/usr  \
--with-kerberos=/usr  \
--with-zlib=/usr  \
--enable-bcmath  \
--with-bz2=/usr  \
--enable-calendar  \
--with-curl=/usr  \
--enable-dba  \
--enable-exif  \
--enable-ftp  \
--with-gd  \
--enable-gd-native-ttf  \
--with-icu-dir=/usr  \
--with-iodbc=/usr  \
--with-ldap=/usr  \
--with-ldap-sasl=/usr  \
--with-libedit=/usr  \
--enable-mbstring  \
--enable-mbregex  \
--with-mysql=mysqlnd  \
--with-mysqli=mysqlnd  \
--without-pear  \
--with-pdo-mysql=mysqlnd  \
--with-mysql-sock=/var/mysql/mysql.sock  \
--with-readline=/usr  \
--enable-shmop  \
--with-snmp=/usr  \
--enable-soap  \
--enable-sockets  \
--enable-sysvmsg  \
--enable-sysvsem  \
--enable-sysvshm  \
--with-tidy  \
--enable-wddx  \
--with-xmlrpc  \
--with-iconv-dir=/usr  \
--with-xsl=/usr  \
--enable-zip  \
--with-imap=/usr/local/imap-2007 \
--with-kerberos \
--with-imap-ssl \
--enable-intl \
--with-pcre-regex  \
--with-pgsql=/usr  \
--with-pdo-pgsql=/usr \
--with-freetype-dir=/usr/X11 \
--with-jpeg-dir=/usr  \
--with-png-dir=/usr/X11

Once done, execute

$ make test

”make test” runs make and tests the compilations for errors

As mentioned in the section on Build Theory, this runs make and tests the compilation. This might take a while, up to 30 minutes, because every single facet of PHP is being tested. When finished, if PHP found any errors (and it probably will) report them to the developers by following the on-screen instructions. Don’t worry, everything is still fine – the errors it finds are usually less than important.

Make Test
As you can see, some 11503 tests are to be performed. This will take a while.

If you have the original PHP already activated and configured, make a backup of your php.ini file now. It should be in /etc/php.ini

Finally, run the following to actually install PHP.

$ sudo make install

It is best not to overwrite the new php.ini file with your old one if you made a backup. Instead, copy the values you need manually, to stay on the safe side – that way we make sure the new php.ini file is fully compatible with the newly installed version.


Apache configuration

Almost finished! If you had already activated PHP on your machine before this and the only purpose of reading this article was actually upgrading the existing PHP, then you’re done – everything should work.

If not, however, we need to enable PHP in OSX’s native Apache installation. Since the httpd.conf file will probably be in the default location, open it via Terminal in TextEdit like so:

$ SUDO_EDITOR="open -FWne" sudo -e /etc/apache2/httpd.conf

I am using the SUDO EDITOR command here in order to open the file in TextEdit, simply because I deem it much easier to edit files in than Vim or Nano. I could just as well have used “$ sudo vim /ect/apache2/httpd.conf” to edit it in vim.

Next, Uncomment the following lines (they are not next to each other – use the Find command to locate them)

LoadModule php5_module        libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-vhosts.conf

The first line activates the use of PHP as an Apache module. The second line is there so that the main httpd.conf (Apache’s configuration) file harvests the virtual hosts from the vhosts file and saves us the trouble of excessive editing in the overly sensitive httpd.conf. This has the additional benefit of letting you save a vhosts file somewhere outside /etc, and backing it up for other development machines or reinstallations.

A very practical approach to this is hosting it on a cloud service like Google Drive or Dropbox and linking to it directly from httpd.conf. That way, when you add a new virtual host, it is automatically installed on every one of your machines just as soon as you restart the local Apache server.


Adding a Vhost and Wrapping Up

A virtual host is a locally hosted imaginary domain. It basically lets you test out your projects in the browser by entering different URLs. For example, on my machine, I could visit http://mactuts.tutorial and see the Hello World app this sections ends with, or I could visit http://mw.dev to see the development version of a project I’m working on. Quite simply, a different URL triggers a different source folder and opens a different project as a website. Here’s a quick guide on how to add a vhost – if you have vhosts set up already or understand everything about them, feel free to skip this section.

Step 1: Editing the hosts file

First, we’ll name our sample vhost “mactuts.tutorial”. To do this, add an entry into /etc/hosts that looks like this:

127.0.0.1        mactuts.tutorial

This means accessing the url http://mactuts.tutorial in the browser will go to 127.0.0.1:80 or, in other words, to port 80 of our local server (Apache).

Hosts
This is an example hosts file. Notice I also have some other virtual hosts set up on this machine

Step 2: Add an Apache vhost

Next, add a block into etc/apache2/extra/httpd-vhosts.conf that looks something like this:

<VirtualHost *:80>
    ServerName mactuts.tutorial
    DocumentRoot "/Users/{USERNAME}/Sites/mactuts"
    ServerAdmin bruno@skvorc.me
        <Directory "/Users/{USERNAME}/Sites/mactuts">
            Options Indexes FollowSymLinks
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
</VirtualHost>

Replace {USERNAME} with your own username, without the curly braces. This tells Apache the following: If you have something on port 80, check its original url name. If it’s mactuts.tutorial, then set up all those options.

Step 3: Restart Apache

Next, restart Apache with

$ sudo apachectl restart

Step 4: Create the Index File

3) Create a the folder “/Users/{USERNAME}/Sites/mactuts” (naturally, replace {USERNAME} with your OSX user’s name) and place an index.php file into it with the following content:

<?php echo 'Hello world'; ?>

Step 5: Check it out!

Go to http://mactuts.tutorial. You should see “Hello World”!


Alternatives

Recently, an alternative to this approach popped up – installing PHP through Homebrew itself. The problem is, there are no official channels at the time of this writing (early August 2012) so an alternative tap needs to be activated for Homebrew.

Also, the OS X version I tested this on, Mountain Lion, unfortunately failed to install that way and threw vague errors at me which I could not resolve. If you feel adventurous check this post out and try to modify it according to your own OS and desired PHP version.

A more stable alternative seems to be available here, but the feedback is lax and there’s not much to go on, so I’ll leave these methods up to the experimentation of the readers.

Updates

Here are a few alternatives suggested by commenters since the post was published.

php_osx
Another (seemingly smooth-working) alternative to this was brought to my attention by commenter DaftViking and includes installing PHP via php_osx.

Macports
Although I encourage the phasing out of Macports in favour of Homebrew, it seems Macports added a stabilized version of PHP as well, so it might provide another working alternative. I have personally not tested this approach, but for those proficient with Macports, further information can be found here. Thanks to Redditor nemeth88 for the heads up!


Conclusion

OS X comes with a preinstalled PHP and Apache configuration. Sadly, the PHP version that it comes with is severely outdated, and it never updates except when a new OS version is being installed. By then, the new PHP version included is already out of date, so besides fetching an *AMP (Apache/Mysql/Php) package (which rarely, if ever, has up-to-date versions of PHP), what can one do except update it manually?

In this tutorial we’ve covered the basics of building from source, we’ve built a new up-to-date version of PHP and installed it, and we’ve even installed Homebrew which will make further installations of software and libraries super easy. We also covered the creation of a virtual host and tested our installation to make sure it works. I hope you’ve enjoyed it and that everything worked as planned. If you run into problems, feel free to post in the comments and we’ll work through the issues together.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • DaftViking

    I haven’t upgraded to 10.8 yet, but on 10.7, I found http://php-osx.liip.ch/ to be a very easy way to get an up-to-date installation of PHP (5.3 or 5.4) on my machine with a single line of shell code, no messing around with homebrew, configure, make, etc.

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      This is an excellent resource I hadn’t encountered yet. Thank you! I’ll make sure it gets added as an alternative approach, though I still believe knowing how to do it all from scratch is valuable knowledge.

  • jav

    isnt it easier to install MAMP?

    • Paul

      I concur! Or XAMPP.

      • http://about.me/bruno.skvorc Bruno Skvorc
        Author

        As mentioned in the article, those distributions never have the most up-to-date version of PHP.

        • Paul

          Okay, i see.
          Thanks, i really appreciate your tutorial (saved in Evernote :] )

        • Einar

          MAMP comes with PHP 5.4.4

          • http://about.me/bruno.skvorc Bruno Skvorc
            Author

            Which still isn’t the latest version (right now, it’s 5.4.6).

            Besides, the purpose of this article is to upgrade an existing native installation of PHP, something which MAMP doesn’t do (it installs a new stack besides the already existing one), and to teach people how to use Homebrew and how to build software from source code – a very useful skill for every developer / unix user I’d say.

  • Richy

    Will the above work with Snow Leopard? As I’ve currently no intention of upgrading my OS.

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      Yes, in most cases it should be backwards compatible with Lion and Snow Leopard, although I have only tested this full procedure from start to finish on Lion.

  • Joël Matelli

    Hi,

    I’m trying to follow this tutorial to the letter, however when I execute the ./configure part, the console throw me an error:

    configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

    I did a little research and they said it was because of imap, so I downloaded imap-2007, I put it in my /usr/local, I renamed c.client.a by libc.client.a, but I still got the error.

    Additionaly, when I try to execute ‘make test’ the console give me that:

    make: *** No rule to make target `test’. Stop.

    I suppose it’s because the ./configure couldn’t finish its task but I’m not sure.

    Does me using zsh instead of bash has to do with anything?

    Thanks.

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      Note that there is a typo in the configure directive, the –with-imap has a duplicated equals sign. I’ll let my editor know immediately. Please try without it first.

      If this does not work…

      Using zsh instead of bash shouldn’t cause any problems. Please try the following and let me know if anything worked, so that I may update the article:

      1) Install openssl with brew install openssl
      2) Compile the IMAP extension by itself. Go to your php source folder, /ext/imap, there run “phpize” followed by

      ./configure –with-imap==YOUR_IMAP_FOLDER \
      –with-kerberos \
      –with-imap-ssl \

      (replace YOUR_IMAP_FOLDER with your imap folder)

      Then, while still in the ext/imap folder run “make”. This should build just the IMAP extension. Then try re-running the general configure, or simply run it without the IMAP options and manually add imap.so from ext/imap/modules/ to your PHP extensions folder. Let me know how it goes!

      • Wharenn

        I had the same error message and I managed to solve it by doing step 2 explained in this post :
        http://geek.daohoangson.com/2012/08/imap-module-for-php-in-mac-os-x.html

        After that, I had another error from intl extention that I had to compile manually by doing in ext/intl directory :
        phpize
        ./configure –enable-intl
        make

        • http://about.me/bruno.skvorc Bruno Skvorc
          Author

          Thanks! I hadn’t encountered these issues in my attempts, but it’s definitely valuable to know!

      • http://blog.devcanvas.org Kefaleas Stavros

        I tried ‘brew install openssl’ and I get to an error :

        make: *** [install_sw] Error 13

        Error: openssl did not build

        • http://blog.devcanvas.org Kefaleas Stavros

          I solved the above problem and the new error I get is the following :

          checking for location of ICU headers and libraries… not found
          configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.

          • http://blog.devcanvas.org Kefaleas Stavros

            The latter problem solved by using /usr/local instead of /usr

          • http://www.facebook.com/joel.a.saxton Joel Joel Binks

            this didn’t work for me, I also tried /usr/lib. That’s where the ICU stuff is, but it still fails with the same error.

          • http://www.facebook.com/joel.a.saxton Joel Joel Binks

            So I installed the ICU libraries, fiddled with a few things, and the compiler finally worked. Amazing how much tinkering must be done with a factory install of Mountain Lion to get this working.

          • http://www.facebook.com/joel.a.saxton Joel Joel Binks

            Now I run the sudo make install and I get this error:

            clang: error: no such file or directory: ‘ext/imap/php_imap.o’

            Yep, there is no such file there, just a php_imap.lo file. DAMN!

          • http://www.facebook.com/joel.a.saxton Joel Joel Binks

            Downloaded php 5.4.9 a second time, re-ran the config and install, and YES I got it to work!

      • http://www.facebook.com/joel.a.saxton Joel Joel Binks

        Bruno,

        Unfortunately, this did not work for me. I am running OSX 10.8.2. I installed openssl using step 1:

        $ brew install openssl
        ==> Downloading http://openssl.org/source/openssl-1.0.1c.tar.gz
        ######################################################################## 100.0%
        ==> perl ./Configure –prefix=/usr/local/Cellar/openssl/1.0.1c –openssldir=/usr/local/etc/openss
        ==> make
        cd ..
        ==> make test
        ==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1c/share/man MANSUFFIX=ssl

        I then tried every which way to configure:

        ./configure –with-imap==/usr/local/Cellar/openssl/1.0.1c
        –with-kerberos
        –with-imap-ssl

        or

        ./configure –with-imap==/usr/local/Cellar/openssl/1.0.1c
        –with-kerberos
        –with-imap-ssl

        or

        ./configure –with-imap==/usr/local/Cellar/openssl/1.0.1c/share/man
        > –with-kerberos
        > –with-imap-ssl

        but I still get that error: “configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL
        is missing. This should not happen. Check config.log for additional
        information.”

        What am I missing?

    • http://twitter.com/_wsilva Wellington

      Hello there… to solve it:
      configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

      I just installed imap with homebrew:
      `brew install imap-uw`

      after it I had another error trying to ./configure:
      configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.

      it was solved changing /usr to /usr/local as I could see here in the comments

      Thanx folks

      • fungus_soup

        this worked for me, thanks

  • Jordan G.

    The link for X11 is dead….I tried to find an alternative on Google, but wasn’t sure which one to download.

    • Josh H

      @Jordan G – Google “XQuartz” for the correct website. The writer forgot to add http:// to the URL, which causes the link to be interpreted as a directory on Mactuts+.

  • Lehnhard Lützen

    after i done all this steps i have on the console when i call php -v the php Version 5.4.7 when i open a website from the server where i have a phpinfo() call i get version 5.3.13. Any suggestions?

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      Sorry, didn’t see this before. I wish the site contacted me on new replies…

      Are you sure everything went fine during configuration/installation? I just reinstalled my PHP again and it worked as planned. Be careful – if you update your OS (say, from 10.8.1 to 10.8.2), OSX will reinstall your PHP to the original version which is yet another of Apple’s horrible practices. So it’s possible it reverted for you if you updated your OS between installing PHP and running phpinfo();

      • RS

        It’s happening the same for me. I followed all the steps and my php -v = 5.4.13 but when I checked on website from the server I get 5.3.15. I didn’t update my OS

  • http://about.me/bruno.skvorc Bruno Skvorc
    Author

    Please note that you might be required to change icu-path in the ./configure options to /usr/local, depending on where your ICU gets installed.

  • Phil

    Thanks for this article. PHP is installing, hopefully I will finally be able to get imap-ssl working on php!

  • Klemen

    when i run configure command i get this error message.
    Can anyone help me? Tnx!

    If configure fails try –with-vpx-dir=
    configure: error: png.h not found.

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      Try running “brew install libpng” and then try again

  • penyo

    Great tuts….

    So, can i do this just with Command Line Tools and without Xcode?

    • http://about.me/bruno.skvorc Bruno Skvorc
      Author

      No, you need XCode

  • http://twitter.com/toriqo Flavius Andrei

    you can also run brew install icu4c

  • http://www.facebook.com/profile.php?id=3408210 David Tang

    this was super helpful! will there be a follow up to integrate mysql?

  • CL75

    Hi I tried upgrading PHP on OSX Lion 10.7.5 as explained at http://stackoverflow.com/questions/13547877/upgraded-to-5-4-but-php-v-still-returns-older-version, but for some reason it seems OSX is still defaulting to the native installation. I experimented with $PATH to no avail, if anybody has any advice it would be greatly appreciated!

  • pixelBender67

    I installed PHP 5.4.8 via Jeffery Way’s tutorial and did not include mcrypt, now I can’t get brew to link to it or build from source (“You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net“) but when I installed that I got the same error. What should I do next, re install PHP?

    • pixelBender67

      I just re installed PHP 5.4 and it works great now, thanks anyways and awesome tutorial bye the way :)

  • http://twitter.com/soderlind Per Søderlind

    Just a fyi, php_osx doesn’t include php-cgi. I discovered that when I wanted to test WordPress on Pow. Pow needs php-cgi

  • Joshua

    I get “Nothing to be done for `install’.” “when doing sudo make install”

  • kukat

    php_osx + brew install virtualhost.sh
    Rocks!

  • http://www.facebook.com/joel.a.saxton Joel Joel Binks

    I upgraded to 5.4.9 using this tutorial but apparently I have an outdated IMAP:

    PHP Warning: PHP Startup: imap: Unable to initialize module
    Module compiled with module API=20090626
    PHP compiled with module API=20100525

    Anyone know where I can find one that works with 5.4.9? I am on OSX Mountain Lion.

  • xafar

    I followed all of the above steps but when I do ‘php -v’ I still see ‘PHP 5.3.15′ but when I use this command ‘/usr/local/bin/php -v’ then I do see PHP 5.4.11. Which means I am still using old version of PHP while new version installed. How can I active my newer version of PHP?

    • thanhnguyen

      I guess when you execute ‘php -v’, /usr/bin/php is called, which I think is the native php of Mac (you can check by calling ‘whereis php’. Another way to check which version being active is to use phpinfo(), or phpversion().

    • http://twitter.com/nightshiftc Cristina Solana

      Were you able to fix this? I have the same issue.

      • http://twitter.com/nightshiftc Cristina Solana

        Found the answer, maybe this works for others. I noticed that a php.ini file hadn’t been created. I copied my backup since I didn’t even have a php.ini.default: sudo cp php.ini.old php.ini – looks to be working well.

  • duffy

    Thank you for this!

  • fungus_soup

    great guide, thanks!

  • Kenny

    Thank you for this excellent tutorial. I ran into a few small issues, but they were able to be resolved easily by reading through some of the comments.

  • pixelBender67

    The configuration file still needs to be updated by the way

  • kennedy

    Hey. Thanks for nice tuts. But am stuck little at this point where you start explaining on how to install php from unarchived directory. i run ./configure with all the flags but at the end i got this error

    checking for jpeg_read_header in -ljpeg… yes
    If configure fails try –with-vpx-dir=
    configure: error: png.h not found.

    As a result of that i could not run the make test. I tried and i got this message

    $php-5.4.14 make test
    make: *** No rule to make target `test’. Stop.

  • Vincent Pecoraro

    I am glad I took your route in getting my new AMP stack built but I found a couple of problems with your tut.

    1) To clear up the “U8T_CANONICAL is missing” error I had to install the OpenSSL library.

    2) After I cleared that I also had to install the ICU library, it isn’t optional.

    3) I also had to create the .bash_profile directory and create a path to usr/local/sbin.

    Once PHP was up and running everything went smoothly till I went to view my new virtual hosts and got a can’t find server error. You have to go to System Preferences/Sharing and turn on web sharing. I had installed a localhost the old fashioned way a couple of months ago on my home iMac and should have remembered this but it took an hour of googling to find the answer.

    Overall I am happy with your tutorial and hope these notes will be helpful to others.