OS X Mavericks and Apache

Web Development with Apache, PHP and ColdFusion on OS X Mavericks

Getting your web development environment set up on OS X Mavericks is very similar to setting it up on Mountain Lion, or other previous releases of Apple’s OS.  If you already had your environment set up previously, and upgraded to OS X 10.9 (Mavericks), then you will notice that your httpd.conf configuration has been replaced.  But, don’t fret.  You can find your old configuration located at: /private/etc/apache2/httpd.conf.pre-update.  Let’s go ahead and get started!


OS X comes with Apache already installed, so it’s as simple as starting up the server.  Previously, you could start this using the System Preferences > Sharing panel, but it has been removed from there in 10.9.  To start the server, first start up Terminal app via Utilities > Terminal, and then enter the command below.  You can read the full documentation on the apachectl command.

Start Apache:

$ sudo apachectl start

Stop Apache:

$ sudo apachectl stop

Restart Apache:

$ sudo apachectl restart

Another useful command is to verify your httpd.conf configuration via the -t test switch.

$ sudo apachectl -t

Once you have started the Apache server, open your favorite browser to: http://localhost and you should see the screen below.


Customizing Apache

After getting the initial localhost working, you may want to make some changes.  I suggest:

  • Create a /www directory
  • Put all your web sites in this directory
  • Add virtual hosts for each web site you are working on
  • Add an entry to your hosts file to point a local domain name to your local Apache server

First, let’s create the /www directory:

$ cd /
$ mkdir www

Second, let’s create our local web site local.example.com (replace with your own web site):

$ mkdir local.example.com

Open up the httpd.conf file located in /private/etc/acpache2.  I am using TextMate, so I will use the “mate” command.

$ mate /private/etc/apache2/httpd.conf

Make the following changes to the httdp.conf file.

  • On line 170, change the DocumentRoot:
    DocumentRoot “/www”
  • On line 197, change the Directory location:
    <Directory “/www”>
  • On line 217 (within the Directory location we just updated), change the AllowOverride to “All” so that we can use .htaccess to modify any settings for our local sites:
    AllowOverride All
  • On line 429, uncomment the Include of the httpd-vhosts.conf file:
    Include /private/etc/apache2/extra/httpd-vhosts.conf

We will also add a new virtual hosts to the httpd-vhosts.conf file (located at /private/etc/apache2/extra/httpd-vhosts.conf).  If you open this file, you will notice that there is already some dummy-host.example.com entries.  You can just modify these as necessary for your web site.  My virtual host entry looks like this:

<VirtualHost *:80>
	DocumentRoot "/www/local.example.com"
	ServerName local.example.com
	ErrorLog "/private/var/log/apache2/local.example.com-error_log"
	CustomLog "/private/var/log/apache2/local.example.com-access_log" common

The last thing we need to do is modify our hosts file so that when we type in “local.example.com” into our browser we use the local Apache web server, rather than trying to go out find this fictitious domain on the Internet.  So, let’s open up the hosts file for editing in TextMate.

$ mate /private/etc/hosts

Add a new entry for your web site:      local.example.com


PHP is already installed for you in OS X 10.9 Mavericks.  It’s as simple as modifying the httpd.conf file again.

  • On line 118, uncomment the LoadModule for PHP:
    LoadModule php5_module libexec/apache2/libphp5.so
  • On line 231, add index.php as a default document if a directory is requested:
    DirectoryIndex index.html index.php

Lastly, we need to tell Apache to use the PHP handler when requesting files that end in .php or .phps.  Append the following code to the end of your httpd.conf file.

#PHP Settings
<IfModule php5_module>
	AddType application/x-httpd-php .php
	AddType application/x-httpd-php-source .phps

Don’t forget to restart the Apache server after making any changes to your httpd.conf file.


ColdFusion is not shipped with OS X 10.9 Mavericks (bummer), but it’s pretty simple to install.  During the installation you can provide the web server connection utility with the necessary information about your Apache server, which will automatically add the necessary configuration parameters to your httpd.conf file for you.  If you have already installed ColdFusion previously, you can copy the code out of the httpd.conf.pre-update file, or use the web server connection utility again.

ColdFusion9 web server configuration utility
ColdFusion9 web server configuration utility



This is an update to the original blog article, as I ran into some issues with my MySQL connection after posting this article.

Upgrading also replaces your php.ini file (located at /private/etc/php.ini), with a new php.ini.default (located at /private/etc/php.ini.default).  To get MySQL working (along with error reporting), I needed to update some settings:

  • One line 478, display errors (this is only for development, not a production environment):
    display_errors = On
  • One line 986, add the location to the MySQL socket file:

If you are running into the same issue, you probably need to enable the pdo_mysql extension by uncommenting the line: extension=php_pdo_mysql.dll.

That’s it.  Happy web developing!

65 thoughts on “OS X Mavericks and Apache

  1. I had trouble with my local sites working after updating to Mavericks too and I noticed that what I had to do was go into /private/etc/apache2 and delete httpd.conf and then rename httpd.conf.pre-update back to httpd.conf and also had to go into /private/etc and delete php.ini and then rename php.ini.5.2-previous back to php.ini

  2. Hi,
    Thank you, that helped me !!
    I meet a new issue, my database connection seems to be impossible.
    Error message:
    Link to database cannot be established: SQLSTATE[HY000] [2002] No such file or directory

    Any idea how to solve it ? It worked well before upgrading to Mavericks.

    Thanks !!

  3. Thanks a million for your article, was exactly what I was looking for! You have a typo in the command line under ‘Stop Apache’: it says ‘$ sudo apachectl start’ but you probably mean ‘$ sudo apachectl stop’.

  4. Thanks! This really helped! I ran into one more issue after uncommenting the PHP module, and vhost line. The timezone needed to be set again.

  5. @Pete, yes, you can do that also. I did notice that there were some other changes in the httpd.conf and php.ini.default files that ship with OS X Mavericks. I wanted to preserve those new changes (just in case), so I manually copied over my necessary changes. However, you’re method of copying them over will also work.

  6. @Lo, I just made an update to the article. I also ran into an issue with my MySQL database connection. I had to also update the pdo_mysql.default_socket setting in php.ini to point to the MySQL socket file located at /tmp/mysql.sock. I hope that helps and gets you back up and running!

  7. Thanks for the heads up! This helped me out. Just for those coming across this page, I had done a homebrew install of PHP and I wound up looking into a file named httpd.conf~previous to get the changes I need.

  8. I am ripping my hair out. I cannot get things to work properly since I installed Mavericks. On Mountain Lion I had it set up that I could type local.mysite.com in my browser and be served files from /Users/Me/Sites/mysite.

    When I change the Document Root to /Users/Me/Sites, the browser won’t connect to the server. When I change the Document Root to /Library/WebServer/Documents, and still have the virtual hosts pointed to their respective folders in Sites, I get Access Forbidden. Even if I open up the permissions wide.

    Incredibly frustrating.

  9. Thank you!!! Just upgraded to Mavericks and was figuring out how to get my environment working again. Such a time saver!

  10. Pingback: php | Annotary
  11. Thanks a lot. This is a VERY useful post. Save me a lot of frustration. Do you know why the move from /etc to / private/etc?

  12. @Gerard, I’m glad that this post was useful for you. It didn’t really move from /etc to /private/etc. You can still use /etc/apache2, as /etc is just a symlink to /private/etc. If you open terminal:

    $ cd /
    $ ls -al

    You will see that /etc is a symlink to /private/etc:

    lrwxr-xr-x@ 1 root wheel 11 Oct 23 12:17 etc -> private/etc

  13. During the mavericks upgrade several configuration files were saved as previous and replaced by the install including:


  14. Hey, guys.

    Nice hint! However, I can’t put PDO to work. For some unknown reason, my Mavericks just don’t have the pdo_mysql extension installed. I’m stuck since I just can’t put it to work. I have tried to install it using pecl, but compilation fails since it can’t find the mysql_config, even knowning that this fellow is installed and accessible through PATH variables. Anyone?

  15. If you were using a version of Apache that was not the Mac OS built-in version (such as a version installed using MacPorts,) you need to disable the built-in Apache (the one that came with Mavericks) using this command:

    sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

    Then you can simply start up your existing/previous copy of Apache using the appropriate ‘apachectl start’ command.

  16. I’m running into same issue #2002 Error. Made all the changes suggested in the article, and still having the same problem.

    Did anyone solved this problem in a different way?

  17. Solved the #2002 MySQL Error with:

    mysql.default_socket = /tmp/mysql.sock
    mysqli.default_socket = /tmp/mysql.sock

  18. Does anyone encounter error in iTunes store after installing mySQL on Maverick? I got an iTunes error 12002. Can’t connect to “Music/Movies/App Store” with the same error, but no issues in connecting to “Books/Podcast/iTunes U”. I’m using Macbook Air 13″ mid-2011, and installed mySQL from this site: http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg and downloaded “Mac OS X 10.6 (x86, 64-bit), DMG Archive”. iTunes works fine on my other user accounts in which mySQL was not installed. Any feedback/ideas are welcome.

  19. Thanks very much, this helped me get everything up and running again after upgrading in-place from 10.7 Lion to 10.9 Mavericks. My vhosts weren’t working anymore, and now they are. Thanks again!

  20. Thanks a bucket! This article saved another live. Was just wondering why I couldn’t use a folder created within my user profile folder. Always got a 403 error. I tried to change the permissions on the folder without success…

  21. Thanks a bunch for this ..worked well for me. I used Pete’s comment, except I saved the maverick files to another name just in case I needed to look at it later.

  22. Followed the steps but get no results. New to macs, created the /www/dev.local.com folder and put an index.html file inside. Amended the httpd file as suggested and the extra/http-vhosts. Check the server has started and it is. In chrome is get It Works! first load then refresh i get connection issue, FF doesnt connect and IE neither, am I doing something wrong? Help greatly appreciated

  23. I had a problem.. i’v got 403 forbidden after updating from Lion to Mavericks..
    i’v tried to change rules for directories in filesystem by CHMOD 777… but it’s not working

    Finally a found here ( http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/ ) simple thing in /private/etc/apache2/extra/httpd-vhosts.conf that i’ve forgotten:

    AllowOverride All
    Order allow,deny
    Allow from all

    becouce and if you look in /private/etc/apache2/httpd.conf

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all

    p.s. sorry for my english (not mach practice last years), but i hope my post help you to fix this very little mistake that take a lot of time to me.

  24. For those suffering from 403 Forbidden Errors, the following site had the solution for me (near the end, in the Losing Localhost section): http://www.coolestguidesontheplanet.com/downtown/how-set-virtual-hosts-apache-mac-osx-109-mavericks-and-osx-108-mountain-lion

    In the article, the author uses “DocumentRoot /Library/WebServer/Documents/” in his VirtualHost record. I changed it to “DocumentRoot /Users/username/Sites/” as it was changing the DocumentRoot that triggered the 403 error in the first place.

  25. Hi Brian

    Your post is very useful, but do you know how the web server can be started automatically at system startup ? (That’s what the “web sharing” entry in previous versions of System Preferences did) It’s a pain to have to manually turn it on every time I start my Mac… There must be a way, but I don’t know how service launching works in nowadays’ macs…

  26. I’ve followed all the instructions, including replacing httpd.conf and php.ini.default with the previous versions – nothing doing, still getting “Oops! Google Chrome could not connect to localhost”.
    What could the cause be? What do you need to know from me? Any help would be appreciated.

  27. I have tried to configure, PHP and Apache according to given above., but if I try to open phpinfo.php file says unable to open.

  28. Do yourself a favour and get VirtualHostX app (free 1 host, paid multiple). It does everything for you through a gui.

  29. Hey there,
    Just reinstalling my iMac and stubbled across a little notice for the tutorial.

    in mavericks the line 429
    On line 429, uncomment the Include of the httpd-vhosts.conf file:
    Include /private/etc/apache2/extra/httpd-vhosts.conf

    this has been changed to 478.

  30. Hi guys, I recently switch to Mac and after 10 days of agony I finally managed to setup everything. I just had to tell you one thing, it’s 3 times easier to setup CF 9 or 10 under JBoss 7 than to setup all these little thingies for JRun. Performance boost is side effect in this case :)

  31. Does anyone know what permissions should be on the /www and /www/local.example.com directories? I had to “sudo mkdir” as “mkdir” did not have permission to create the directory, but now my text editor cannot write to that location.

  32. Your step involving adding the PHP handler appears to not be necessary, at least in my version of Mavericks. At the end of the httpd.conf file, there’s a line:

    Include /private/etc/apache2/other/*.conf

    And if you look in the `other/` directory, there’s a php5.conf already there and configured. It just checks if the php5 module’s been turned on (vis-a-vis uncommenting the module line). As it turns out, moving the php5 handler code out into another config file is probably a better approach, anyway, from an organizational standpoint.

  33. I had the same problem – eventually solved it by changing the owner of the /www folder from root to me:

    sudo chown $USER /www

    I always feel a bit out of my comfort zone mucking about with this stuff though – if this is a bad idea someone please tell me!

  34. The only modifications I made to your instructions were to substitute your instructions of making a “www” directory in root and the subdirectory of “local.example.com” in that www directory. I have a Sites directory at /Users/dave/Sites, which I believe carried over from previous installations of Mac OS X. I used that Sites directory and substituted all of the conf instructions accordingly.

    When I go into the Sites directory, I can double-click an html file and it will load in my browser. However, it will not run a php script. The result from a called php script is to display the raw php code. However, when I load the URL “localhost” or “local.dave.com” the browser displays “Index of /“, and all of the files and directories of my “Sites” directory, which is located at /Users/dave/Sites. If I click on any html or php file listed on the localhost browser page, it executes the html and php script correctly. So, is this a correct installation of Apache and php? For the purposes of simply creating a local development environment, it appears to be doing everything I need it to do.

    Now I need to install MySql. I have checked my /usr/local directory and there is no mysql directory. I also need to install phpMyAdmin.

    Can you point me to a link (preferably one that you wrote) that provides instructions on installing MySql and PhpMyAdmin so it will all work together with my current Apache and PHP configurations? Or, if I download MySql and phpMyAdmin, will they install correctly and automagically work with the configuration I have?

    Thanks very much Brian.


  35. I linked my ip to a host name, but I’m still required to append the port number in order to load the site. Anything that I can do to just type the host name sans port number?

  36. Hi! Would you mind if I share your blog with my
    facebook group? There’s a lot of folks that I think would really enjoy your content.
    Please let me know. Cheers

  37. Thanks for this. Apparently, on my install (I have a sites-enabled folder set up on my mac instead of one single vhost file for ease of scalability) I needed to copy over httpd.conf~previous rather than httpd.conf.pre-update, and everything went back to normal.

    Thanks to you and all the other commenters here who saved me a hell of a lot of trouble :)

Comments are closed.