Skip to content

Instantly share code, notes, and snippets.

@fak
Last active August 29, 2015 13:57
Show Gist options
  • Save fak/9911600 to your computer and use it in GitHub Desktop.
Save fak/9911600 to your computer and use it in GitHub Desktop.
Deploy the ppdms resource on an Apache web server (myChEMBL image)

Setting the scene

First we need to add a few modifications to te existing environment. In order to communicate with the github servers, we will generate ssh keys using ssh-keygen -t rsa -C "[email protected] and then add them to the list of ssh keys in the github profile.

For a working bash and vim environment, we can clone the dotfiles repo with git clone [email protected]:fak/dotfiles.git and from within that repo cp bashrc ~/.bashrc and cp vimrc ~/.vimrc.

To activate a few nice features of vim we will also git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle and then open vim and use :BundleInstall to get our favourite colour-scheme, status bar and so on.

We also want to set up a virtualenv as described here.

Installing and configuring Apache2

Apache2 requires the mod_wsgi module to communicate with Python processes. We install this module with sudo apt-get install libapache2-mod-wsgi.

To get the configuration right, we can copy all files in /etc/apache2 using sudo scp -r user@server:/etc/apache2 /etc/. In principle, what we need to do in conf.d is to define a VirtualHost, identified by a ServerName. It should also ontain a WSGIScriptAlias pointing to the wsgi.py script of the django project and the WSGIPythonPath to the python packages directory in our virtualenv (eg ~/.virtualenvs/django/lib/python2.7/site-packages). This is important because otherwise we can't use the modules we installed in the virtualenv. We should also set an alias for static files, which will be served through Apache separately from wsgi.py virtual host:

NameVirtualHost *:80
Listen 80
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName chempfam.ebi.ac.uk
</VirtualHost>
WSGIScriptAlias / /path/to/wsgi.py/script/
WSGIPythonPath  /path/to/python/site-packages/in/virtualenv/
Alias /static/ /home/chembl/script/ppdms/static/
<Directory /home/chembl/script/ppdms/static>
    Order deny,allow
    Allow from all
</Directory>

In the sites-enabled folder, we should have a file named after the ServerName defined in ports.conf, containing directives for a VirtualHost. In it, the ServerRoot should be set to the directory containing the wsgi.py script, the DocumentRoot to the index.html template and directives for directories, eg blocking access to all directories, and enabling access to files in the templates directory of the application.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName chempfam.ebi.ac.uk
     ServerRoot /path/to/wsgi.py/script/
    DocumentRoot /path/to/template/dir/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from All
    </Directory>
    # Setting alias for serving a static files directory
    <Directory /path/to/template/dir/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Creating the django project and application

First, we create a virtualenv with all required modules. So once we have switched to our virtualenv (let's call it 'django') with workon django we can start installing them:

pip install django
pip install numpy
pip install pyyaml
pip install psycopg2

We also need two modules that are provided through an EBI repo. To access it, we create a pip config file at ~/.pip/pi.conf and we instert the following lines:

[global]
index-url = http://howe.ebi.ac.uk:8080/repo/index
extra-index-url = https://pypi.python.org/simple/

Then, we install the two modules using pip install chembl_core_model and pip install chembl_migration_model.

Now, it is time to generate the django project: django-admin.py startproject ppdms. We need to adjust the settings.py file and the urls.py file in the ppdms folder. The easiest way to do this is to scp user@server:script/django_project/django_project/settings.py ~/script/ppdms/ppdms/ - if we are planning to host the project on a server with a different name we need to adjust the allowed hosts setting manually. The urls.py file should include:

urlpatterns = patterns('',
  url(r'^pfam_maps/', include('pfam_maps.urls')),
  # Uncomment the admin/doc line below to enable admin documentation:
  url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  # Uncomment the next line to enable the admin:
  url(r'^admin/', include(admin.site.urls)),
)

Into the top-level folder of our django application, we clone the pfam_maps app using git clone [email protected]:fak/pfam_maps.git.

Adding the pfam_maps and other tables to the db

Since we are using the myChEMBL virtual machine, there is already a postgres instance of the ChEMBL database running on the machine. So we only need to project the catalogue of domains onto the activities in that database and override mappings for activities where we already have manual mappings. This is achieved with the pfam_map_loader module. We can clone it into any directory using git clone [email protected]:fak/pfam_map_loader.git. We should move the example.yaml file to local.yaml and edit passwords and username accordingly. scp user@server:script/pfam_map_loader/local.yaml ./ should do the trick, but we still need to change the host to our current IP. Then we simply call python loader.py.

Activating the Apache server

A simple sudo /etc/init.d/apache2 start should be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment