How to Install CKAN on Vagrant - ckan/ckan GitHub Wiki

Intro

Here's how to adapt the Installing CKAN from source instructions for when you want to run and develop CKAN using Vagrant.

This is the setup that I use, as a long-time core contributor to CKAN, running macOS. (D Read)

This config provides 'synced folders' so that you can edit the source code of CKAN (and any extensions) using your host machine's normal text editor, rather than the extra trouble of editing via ssh.

Distribution: these instructions are for Ubuntu Bionic 18.04, but you can easily adapt it for other base boxes. I've also tested it on Trusty 14.04 and Xenial 16.04 and for these you can follow the normal ckan SOLR install instructions using solr-jetty package.

CKAN version: these instructions are for CKAN master (i.e. latest bleeding edge), but you can easily use 'git checkout' after the clone to use another branch. I've tested this on CKAN 2.8.2, 2.7.2 and 2.6.2.

Instructions

First you need to install Vagrant and Virtualbox.

Now set-up Vagrant and the files for CKAN on your host machine:

mkdir ckan-vagrant
cd ckan-vagrant
mkdir etc src
cd src
git clone https://github.com/ckan/ckan.git  # or [email protected]:ckan/ckan.git if you have ckan write permission
cd ..
vagrant init ubuntu/bionic64    # or choose another distro e.g. ubuntu/xenial64
vim Vagrantfile  # and insert these lines after "Vagrant.configure("2") do |config|"
  config.vm.network "forwarded_port", guest: 80, host: 6080
  config.vm.network "forwarded_port", guest: 5000, host: 6050
  config.vm.network "private_network", ip: "192.168.33.60"
  config.vm.synced_folder "etc/", "/etc/ckan/default"
  config.vm.synced_folder "src/", "/usr/lib/ckan/default/src"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
  end

vagrant up

Now the guest box is running. Let's ssh into it and set it up:

vagrant ssh
sudo apt-get update
# Follow http://docs.ckan.org/en/latest/maintaining/installing/install-from-source.html
# BUT there are changes to steps 1, 2c and 5 - see below
#   Step 1 - don't install solr-jetty. If necessary, uninstall like this:
sudo apt-get remove solr-jetty jetty9
#   Step 2c - don't do: pip install -e 'git+https://github.com/ckan/ckan.git#egg=ckan'
#             because you already have CKAN source. Instead do this:
cd /usr/lib/ckan/default/src/ckan
pip install -e .
python setup.py develop
# And in ckan.ini set:
ckan.site_url = http://192.168.33.60:5000
#   Step 5 - Instead of this step, install SOLR 6 (without jetty) using these instructions:
https://github.com/ckan/ckan/wiki/Install-and-use-Solr-6.5-with-CKAN
# Test SOLR from your VM:
curl http://localhost:8983/solr/ckan
# Now complete the rest of the CKAN 'install from source' instructions

When you run the development server, flask/werkzeug doesn't serve to requests over the Vagrant network from your host box, so you need an extra -H 0.0.0.0:

ckan -c /etc/ckan/default/ckan.ini run -H 0.0.0.0

(For CKAN 2.8 and earlier, just use 'paster serve' as normal)

Now try it in your host browser: http://192.168.33.60:5000/

# Convenience to activate the virtualenv by default
echo . /usr/lib/ckan/default/bin/activate >> ~/.bashrc
# Convenience to start in the source directory by default
echo cd /usr/lib/ckan/default/src/ckan >> ~/.bashrc
# Convenience to default --config value for paster commands
echo export CKAN_INI=/etc/ckan/default/ckan.ini >> ~/.bashrc
# Convenience to stop nosetests outputting reams of unnecessary logging
echo export NOSE_NOLOGCAPTURE=1 >> ~/.bashrc

Note about SOLR

I don't know why, but SOLR doesn't start-up properly, so when running tests I see:

  File "/vagrant/src/ckan/ckan/lib/search/index.py", line 300, in index_package
    raise SearchIndexError(msg)
SearchIndexError: Solr returned an error: (u'Solr responded with an error (HTTP 500): [Reason: None]\n<html><head><m

This is solved by restarting it:

sudo service solr restart

or if you are using jetty:

sudo service jetty9 restart

Tips

The CKAN source is accessed from your host machine in the 'src' directory you created at the start, so you can edit it using your normal editor and use git etc. You can also easily access ckan.ini in 'etc'.

When you run ckan run -H 0.0.0.0 / paster serve --reload it serves it on port 5000 in the VM, which is forwarded to 6050 on your host machine, so use your normal browser on: http://localhost:6050/ . Alternatively you can use the private IP address: http://192.168.33.60:5000/ however I find that it stops working occasionally. And likewise if you deploy apache & nginx you can access it on http://localhost:6080/ or http://192.168.33.60/

⚠️ **GitHub.com Fallback** ⚠️