Setting up Local Webserver on OS X 10.10 Yosemite

This post is specific to OS X 10.10 “Yosemite”.

  1. Edit the Apache configuration file as root:  
    sudo vi /etc/apache2/httpd .conf
  2. Enable PHP by un-commenting line 169 changing : 
    #LoadModule php5_module libexec/apache2/libphp5.so 
    To
    LoadModule php5_module libexec/apache2/libphp5.so
  3. Enable Personal Websites by un-commenting the following at line 166:
    #LoadModule userdir_module libexec/apache2/mod_userdir.so
    To
    LoadModule userdir_module libexec/apache2/mod_userdir.so
  4. And do the same at line 493:
    #Include /private/etc/apache2/extra/httpd-userdir .conf
    To
    Include /private/etc/apache2/extra/httpd-userdir .conf
    Now save and quit httpd.conf file.
  5. Open the file You just enabled above with:
    sudo vi /etc/apache2/extra/httpd-userdir.conf
    and uncomment the following at line 16:
    #Include /private/etc/apache2/users/* .conf
    To
    Include /private/etc/apache2/users/* .conf
    Save and exit.
  6. Lion and later versions no longer create personal web sites by default.
    If you already had a Sites folder in Snow Leopard, it should still be there. 
    To create one manually, enter the following:
    mkdir ~/Sites
    echo "<html><body><h1>My site works</h1></body></html>" > ~/Sites/index.html.en
  7. While you are in /etc/apache2, double-check to make sure you have a user config file.
    It should exist at the path: /etc/apache2/users/<your short user name> .conf
    That file may not exist and if you upgrade from an older version, you may still not have it.
    It does appear to be created when you create a new user. If that file doesn't exist,you will need to create it with:
    sudo vi /etc/apache2/users/ .conf
    Use the following as the content:
    <Directory "/Users/<your short user name>/Sites/">
         AddLanguage en .en
         Options Indexes MultiViews FollowSymLinks
         AllowOverride None
         Require host localhost
    </Directory>
  8. Now you are ready to turn on Apache itself. But first, do a sanity check. Sometimes copying and pasting from an internet forum can insert invisible,
    invalid characters into config files. Check your configuration by running the following command in the Terminal:
         apachectl configtest
  9. If this command returns "Syntax OK" then you are ready to go. It may also print a warning saying
    "httpd: Could not reliably determine the server’s fully qualified domain name".
    You could fix this by setting the ServerName directive in / etc / apache2 / httpd .conf and adding a matching entry into / etc / hosts.
    But for a development server, you don't need to do anything. You can just ignore that warning.
  10. Turn on the Apache httpd service by running the following command in the
    Terminal:
         sudo launchctl load -w / System/ Library/ LaunchDaemons/ org .apache .httpd .plist
    In Safari, navigate to your web site with the following address:
         http://localhost /
    It should say:
         It works!
  11. Now try your user home directory:
         http://localhost/ ~<your short user name>
    It should say:
         My site works
  12. Now try PHP. Create a PHP info file with:
         echo "<?php echo phpinfo(); ?>" > ~/ Sites/ info .php
    And test it by entering the following into Safari's address bar:
         http://localhost/ ~<your short user name>/ info .php
    e.g. 
    http:// localhost/ ~sandipv.tekale/ phpinfo .php
    You should see your PHP configuration information.
  13. You will need to restart the Apache server with:
         sudo apachectl graceful

Add new comment