Blog | Manage Apache on OSX (Updated or Yosemite)

28

Jun
2015
Comments Off

Manage Apache on OSX (Updated or Yosemite)

Here is a little tip for customizing apache on OSX.

The first thing you have to do is turn on Web Sharing in your System Preferences. This will start the local Apache server and you can access it by going to http://localhost. From here, you can start modifying it to your will. Apache customization is a big topic and you can find all you need on the Apache website.

Here are a few tips:

  • Apache is installed at: /etc/apache2
  • Apache config is at: /etc/apach2/httpd.conf
  • Apache user config is at: /etc/apach2/users/<username>.conf
  • Apache extra config is at: /etc/apach2/extra/*.conf
  • You can customize your own virtual server by modifying: /etc/apach2/users/<username>.conf
  • You can start/stop Apache by:
    • Enabling/disabling Web Sharing in System Preferences
    • running the following in terminal:
      sudo apachectl <start|stop|restart>

In order for you to get going and have a user directory, you will need to make sure the following is done.

  • Create folder to host your files (e.g. /Users/<my_username>/Sites/)
  • Create an index file in the above folder with a message so you know when it is working.
  • In /etc/apach2/httpd.conf, make sure:
    • userdir_module is loaded (i.e. not commented out).

      LoadModule userdir_module libexec/apache2/mod_userdir.so
    • httpd-userdir.conf is included.

      Include /etc/apache2/extra/httpd-userdir.conf
  • In /etc/apache2/extra/httpd-userdir.conf, make sure that user configuration files are included.

    Include /private/etc/apache2/users/*.conf
  • In /etc/apache2/users, make sure to create a user file for yourself (note: you will have to use sudo to make sure permissions on the file are set to 644 and owned by root:wheel).

    /etc/apache2/users/<my_username>.conf

    Contents:

    <Directory "/Users/<my_username>/Sites/">
      Options Indexes MultiViews
      AllowOverride All
      Require all granted
      DirectoryIndex index.html
    </Directory>

At this point you can should be able to start (or restart) Apache and test your setup.

http://localhost/~<my_username>


Comments are closed.