Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Running the Application on Apache

Jeremy Neal edited this page May 13, 2014 · 1 revision

Apache Web Server is an open-source and extremely popular web server by the Apache Software Foundation. While there are other web servers we could use, this one is the standard, and there is a plethora of documentation available for it. This page will serve as a brief guide on deploying our application. Note that these rules may not work universally. I'm only documenting what I know to work within the conditions described here.

You're gonna need a few things.

For most development, I like to use Vagrant and VirtualBox to keep my work contained. There's another wiki page that goes more in depth on using it. For deployment, you're going to need the following.

It really shouldn't matter what your host OS is. I use Ubuntu, so these directions should work for most *nix systems.

Once you have those two applications downloaded, you're going to need to do a little configuration. Create a new directory (preferably in user space), and call it whatever you want. I recommend something topical, like application. Next, cd into that directory. Create two files, one called Vagrantfile and one called bootstrap.sh.

Open up Vagrantfile in your favorite text editor (vim, cough, cough...) and add the following.

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 4567, guest: 80
  config.vm.network :forwarded_port, host: 4568, guest: 5000
end

Save that, then open up bootstrap.sh and add the following.

apt-get update

apt-get install -y python-dev python-pip libapache2-mod-wsgi git
pip install virtualenv

rm -rf /var/www

Now that you have those finished, launch the vagrant box with the command vagrant up. This part may take a minute. Once it's done, connect to the box with vagrant ssh.

Git and you.

This part is tricky. Well, not really, just requires a bit of finagling. First, you're going to need to add ssh keys to the vagrant box in order to pull the repo. Follow the guide on Github on how to generate and store keys. A bit of advice: I recommend moving the id_rsa.pub file to the /vagrant directory. This will let you access it from outside the vm. Once you have ssh keys set up, clone the repository to the vm. Once it's downloaded, you'll need to run a few more commands.

First, we need to create a virtualenv for the application. In the project directory, run the following.

virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt

Second, we need to link the project repository to the /var/www directory. To do this, enter ln -fs /home/vagrant/Section-2-Team-6 /var/www. This will link the project directory to a location where Apache ca n find and render the HTML files.

Getting that API running.

The last thing we need to do is configure the web server to run the application for us. In your root directory, create a file called deku.wsgi. Add the following inside.

activate_this = '/home/vagrant/Section-2-Team-6/.venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import sys
sys.path.insert(0, '/home/vagrant/Section-2-Team-6')
from app import app as application

Next, create a logs directory in your root directory.

Next, create the file /etc/apache2/sites-available/deku and enter the following within (Note: you need to run sudo with this):

<VirtualHost *:5000>
    WSGIDaemonProcess deku user=vagrant group=vagrant threads=5
    WSGIScriptAlias / /home/vagrant/deku.wsgi

    <Directory /home/vagrant>
        WSGIProcessGroup deku
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

    ErrorLog /home/vagrant/logs/error.log
    LogLevel warn
    CustomLog /home/vagrant/logs/access.log combined

</VirtualHost>

Finally, add the following to /etc/apache2/ports.conf:

NameVirtualHost *:5000
Listen 5000

Once you have all of that done, run sudo a2ensite deku and then restart the Apache server with sudo service apache2 reload.

From your host os, you should now be able to go to http://localhost:4567 in a browser and see the interface. You will not be able to access the API this way, but you can test it using cURL from the guest machine.