Friday, April 24, 2015

Apache Configuration


Writing Apache config file is required and basic for setting up a new website using Apache. It's easy for basic types of websites since you can find template files online, and only a little modification is needed. However, this turned out that I still don't really know much about how to write the config file even I have set up tons of websites already.

Setting up simple static websites with virtual host, or setting up Wordpress websites is easy. But, if we want to fully and nicely control the permission or setup a Django app would be complex. So, I am writing this article as a note about Apache config files.


I am using Ubuntu 14.04, so I installed those tools by having following commands:

Then, instead of modifying existing config files, I think it's a better idea to add new files under /etc/apache2/sites-available to extends the setting. For my case, I add "bugkiller.conf" for my new website called Bug Killer.

Also, since in most of the time, I build more than one website on a machine, so "virtual host" became essential setting in my case. This is the way to make Apache gave different outputs based on its domain name.

Case 1. Setup Static Websites (using Virtual Host)

  • ServerAdmin is the email address where receives error logs (or any other logs based on your setting),
  • ServerName and ServerAlias are the domain name for your new website,
  • DocumentRoot is the root directory path of your static website folder
  • For logging, it means that logs at LogLevel "warn", and will be saved in ErrorLog and CustomLog.
And, in order to let the web server process to access the folder correctly, we give the folder all the permission by saying "AllowOverride All".

Case 2. Setup Wordpress Websites (using Virtual Host)

Same as "Case 1".

Case 3. Setup Django Applications (using Virtual Host)

  • WSGIPythonPath: The path for Django project root folder. By setting up this correctly, the server process will know where are those python files locate.
  • WSGIScriptAlias: The path to Django wsgi file, which is a gateway that wires external sockets to our Django project. So, Django should start to work after setting up this path correctly.
  • Directory tag: This part is pretty alike static files, one should give out the permission to read file in order to access the gateway.
  • For static files, Apache server has to handle the since it is not supported when DEBUG=FALSE in Django setting. What we have to do is route the "/static/" requests to our static folder and give out permission for that folder.
  • LogLevel debug: This helped me a lot for debugging, which allowed me to read the setting errors in the default log file (/var/log/apache2/error.log or /var/log/apache2/access.log)

No comments:

Post a Comment