13 December 2014

Apache Web Server on Mac Yosemite

Instead of using the in-built Apache you can use a solution like MAMP to run the server independently of the OS.
  1. Create a suitable landing page:
    mkdir ~/Sites
    echo "<html>Hello World!</html>" > ~/Sites/index.html.en
  2. Alter the Apache configuration to enable user sites:
    1. sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bak
    2. sudo vi /etc/apache2/httpd.conf
    3. Search for userdir: /userdir[Enter]
    4. Enter insert mode: i
    5. uncomment (remove the hash) on these lines:
      #LoadModule userdir_module libexec/apache2/mod_userdir.so
      #Include /private/etc/apache2/extra/httpd-userdir.conf
    6. Save and Exit: Esc, :wq[Enter]
  3. Include the user configuration files:
    cp /etc/apache2/extra/httpd-userdir.conf /etc/apache2/extra/httpd-userdir.conf.bak
    sudo vi /etc/apache2/extra/httpd-userdir.conf
    uncomment: Include /private/etc/apache2/users/*.conf
  4. Create/edit a user configuration file:
    1. vi /etc/apache2/users/[short username].conf (maybe new file)
    2. Insert:
      <Directory "/Users/[short username]/Sites/">
      AddLanguage en .en
      LanguagePriority en fr de
      ForceLanguagePriority Fallback
      Options Indexes MultiViews
      AllowOverride None
      Order allow,deny
      Allow from localhost
      Require all granted
  5. Restart Apache:
    sudo /usr/sbin/apachectl stop
    sudo /usr/sbin/apachectl start
  6. Start automatically on boot:
    sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
    to stop it from starting automatically:
    sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

No comments:

Post a Comment