3

I have a simple, Django application which I would like to push to production on a Google Compute Engine (GCE) server. The GCE server is running Debian-Wheezy. I have installed Apache 2, Django 1.6.2 and mod-wsgi on the server and set up a firewall rule which opens port tcp:80.

I am attempting to follow the instructions at https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi/. However, I have been unable to find the httpd.conf file to modify.

Questions:

  1. Where can I find this httpd.conf file to modify?
  2. Once found, do I just edit it as shown at the webpage and then any visits to the GCE instance's external IP address will be directed to my Django application?

Edit 1:

In my root I have the following folders:

bin  boot  build  dev  etc  home  initrd.img  lib  lib64  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var  vmlinuz

Follwing advice from: http://commanigy.com/blog/2011/06/08/finding-apache-configuration-file-httpd-conf-location I have run the following:

$ ps -ef | grep apache

which returns

jason@instance-1:/$ ps -ef | grep apache
root     10492     1  0 13:33 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10495 10492  0 13:33 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10496 10492  0 13:33 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10497 10492  0 13:33 ?        00:00:00 /usr/sbin/apache2 -k start
jason    11669 11529  0 16:54 pts/1    00:00:00 grep apache

and then

$ /usr/sbin/apache2 -V

which returns

Server version: Apache/2.2.22 (Debian)
Server built:   Feb  1 2014 21:26:17
Server's Module Magic Number: 20---edited-just-in-case
Server loaded:  APR 1.4.6, APR-Util 1.4.1
Compiled using: APR 1.4.6, APR-Util 1.4.1
Architecture:   64-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....

 -D APACHE_MPM_DIR="server/mpm/worker"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

According to that website the file I'm actually looking for is apache2.conf not httpd.conf - though this contradicts the Django documentation...

Edit 2

To answer @ls97 question, at /usr/sbin/apache2 is a symbolic link which points to

apache2 -> ../lib/apache2/mpm-worker/apache2

If I navigate to this location and run $ ls -al I get

  total 496
  drwxr-xr-x 2 root root   4096 Apr 18 13:27 .
  drwxr-xr-x 7 root root   4096 Apr 18 13:27 ..
  -rwxr-xr-x 1 root root 497808 Feb  1 21:27 apache2

And the apache2 item at this location is not a directory.

3

apache2.conf is usually under /etc/apache2/ and is the apache main configuration file. It loads httpd.conf which is where you should place your configurations (and not in the main file).

update:

So, in /etc/apache2/apache2.conf file, you certainly have lines like these 2 somewhere:

# Include all the user configurations:
Include httpd.conf

The last one will include /etc/apache2/httpd.conf file which is probably an empty file (or almost) on a fresh install. If it doesn't exist, you can create a new one and add:

NameVirtualHost *:80
Listen 80

You can add your global configurations and virtualhosts configurations there as stated in the django tutorial. As I know the virtualhost part is not in django tutorial (because it is not django related but apache), here is a starting example from a working django site:

<VirtualHost *:80>  # will listen on port 80 - as defined above

    ServerAdmin your@email.com
    ServerName your.site.com     # will serve requests on this url

    DocumentRoot /path/to/your/djangoproject  # like /home/username/projects/myproject


# complete with the rest of the django tutorial configuration under "Serving Files" 
# to serve static files using the same server as I think you have only 1 server available

# close the virtualhost after django tutorial configurations
</VirtualHost>

You need to install and enable wsgi module on apache of course. Usually it is already there and you only need to enable it with: sudo a2enmod wsgi. Not sure about that but I suppose it's enabled for you by GCE based on your configuration for python/django.

Also beware if you are using apache before 2.4, there is a note in django tutorial to change Require all granted with Allow from all and select permission order.

I think this is the simplest way to do it. Another method I prefer for multiple virtualhosts, is to use a directory called sites-available to store 1 file per vhost and enable them selectively linking to sites-enabled. You can find examples of how to do it in apache documentation but working in httpd.conf is fine too for a small number of sites.

  • thank you for your contribution - your clearly know what you're talking about, however I'm looking for a bit more of a step by step eli5 – user714852 Apr 18 '14 at 19:35
  • added a virtualhost configuration example to start your configuration file and complete with the django tutorial. – laurent Apr 18 '14 at 21:45
1

httpd.conf is the main configuration file for Apache. It's under apache/conf and you can edit the file as shown (I'm no expert but it looks like their edits should work).

I remember reading that you run the risk of losing changes to httpd.conf when apache is updated if you edit the file directly but that may have been only for XAMPP users. I can't seem to find this source again. In any case, make a backup of the config file before and after you edit it.

  • @user714852 Following up on your edit, is there anything at /usr/sbin/apache2/conf? – LS97 Apr 18 '14 at 17:04
  • updated question. Basically there is a file called apache2 though it's not a directory so I cannot cd into it. – user714852 Apr 18 '14 at 18:27
  • OK, I'm sorry I can't help any further, but I'm in unfamiliar territory. – LS97 Apr 18 '14 at 20:35

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.