Skip to content

How to setup CKAN on Dev server

Shashank Sharma edited this page Mar 11, 2021 · 1 revision

Configuration

  • Ubuntu 18.04
  • Python 2.7

Setup Process

screen -S ckan
sudo su ubuntu
sudo apt-get update
  • Install the required packages

      sudo apt-get install python-dev postgresql libpq-dev python-pip python-virtualenv git-core openjdk-8-jdk redis-server
    
  • Install CKAN into a Python virtual environment

      mkdir -p ~/ckan/lib
      sudo ln -s ~/ckan/lib /usr/lib/ckan
      mkdir -p ~/ckan/etc
      sudo ln -s ~/ckan/etc /etc/ckan
    
      sudo mkdir -p /usr/lib/ckan/ckan-env
      sudo chown `whoami` /usr/lib/ckan/ckan-env
      virtualenv --no-site-packages /usr/lib/ckan/ckan-env
      . /usr/lib/ckan/ckan-env/bin/activate
      pip install setuptools==36.1
      pip install -e 'git+https://github.com/ckan/[email protected]#egg=ckan'
      pip install -r /usr/lib/ckan/ckan-env/src/ckan/requirements.txt
      deactivate
      . /usr/lib/ckan/ckan-env/bin/activate
    
  • Setup a PostgreSQL database

      sudo -u postgres createuser -S -D -R -P <db_owner_name>
      sudo -u postgres createdb -O <db_owner_name> db_name> -E utf-8
    
  • Create a CKAN config file

      sudo mkdir -p /etc/ckan/default
      sudo chown -R `whoami` /etc/ckan/
      sudo chown -R `whoami` ~/ckan/etc
      paster make-config ckan /etc/ckan/default/development.ini
    
    • Edit the development.ini file in a text editor, changing the following options:

        sqlalchemy.url = postgresql://<db_owner_name>:<owner_password>@localhost/<db_name>
        ckan.site_id = default
        ckan.site_url = http://<server_ip | domain_name>:5000
      
  • Setup Solr

    • Docs: https://github.com/ckan/ckan/wiki/Install-and-use-Solr-6.5-with-CKAN

    • Download the source and extract:

        wget https://archive.apache.org/dist/lucene/solr/8.3.1/solr-8.3.1.zip
        unzip solr-8.3.1.zip
      
    • Install using the shell script

        cd solr-8.3.1/bin/
        sudo ./install_solr_service.sh ../../solr-8.3.1.zip
      
    • Create the ckan core

        sudo su solr
        cd /opt/solr/bin
        ./solr create -c ckan
      
    • Proceed to edit the configuration files.

        cd /var/solr/data/ckan/conf
      
    • Open solrconfig.xml and insert following line into the root <config> element:

        <schemaFactory class="ClassicIndexSchemaFactory"/>
      
    • Comment the element add-schema-fields from <updateRequestProcessorChain's processor attribute.

    • Next, remove the managed-schema file

    • Edit the /usr/lib/ckan/ckan-env/src/ckan/ckan/config/solr/schema.xml file

      • Comment the lines containing defaultSearchField and solrQueryParser.

      • Change the following as below:

          textgen > text_general
          tdate > pdate
          tdates > pdates
          tlong > plong
          tlongs > plongs
          tdouble > pdouble
          tdoubles > pdoubles
        
    • and copy the schema.xml to solr:

        cp /usr/lib/ckan/ckan-env/src/ckan/ckan/config/solr/schema.xml schema.xml
      
    • Restart solr:

        sudo service solr restart
      
    • Finally, change the solr_url setting in your CKAN configuration file (/etc/ckan/default/development.ini) to point to your Solr server, for example:

        solr_url=http://<server_ip>:8983/solr/ckan
      
  • Link to who.ini

      ln -s /usr/lib/ckan/ckan-env/src/ckan/who.ini /etc/ckan/default/who.ini
    
  • Create database tables

      cd /usr/lib/ckan/ckan-env/src/ckan
      paster db init -c /etc/ckan/default/development.ini
    
  • Creating a sysadmin user

      paster sysadmin add <admin_username> email=<admin_email> name=<admin_name> -c /etc/ckan/default/development.ini
    
  • You’re done!

      cd /usr/lib/ckan/ckan-env/src/ckan
      paster serve /etc/ckan/default/development.ini
    

Configure Storage

  • Set up storage

    • Create the directory for uploads

        sudo mkdir -p /var/lib/ckan/justice-hub-uploads
      
    • Add the following line to your CKAN config file (/etc/ckan/default/production.ini), after the [app:main] line:

        ckan.storage_path = /var/lib/ckan/justice-hub-uploads
      
    • Set the permission of your storage_path directory. For example if you’re running CKAN with Apache, then Apache’s user (www-data on Ubuntu) must have read, write and execute permissions for the storage_path

        sudo chown www-data:www-data /var/lib/ckan/justice-hub-uploads
        sudo chmod u+rwx /var/lib/ckan/justice-hub-uploads
      
  • Set up the DataStore

    • Enable the plugin

        ckan.plugins = datastore
      
    • setup the database

        sudo -u postgres createuser -S -D -R -P -l <datastore_owner_name>
        sudo -u postgres createdb -O <db_owner_name> <datastore_db_name> -E utf-8
      
    • set URLs

        ckan.datastore.write_url = postgresql://<db_owner_name>:<db_owner_password>@localhost/<datastore_db_name>
        ckan.datastore.read_url = postgresql://<datastore_owner_name>:<datastore_owner_password>@localhost/<datastore_db_name>
      
    • set permissions

        paster --plugin=ckan datastore set-permissions -c /etc/ckan/default/development.ini | sudo -u postgres psql --set ON_ERROR_STOP=1
      
        NOTE: We have not yet set DataPusher
      

Deploy

Reference Documentation

Ref Threads on SO