---
# System prepended metadata

title: CKAN installation

---

# CKAN installation


sudo apt update

sudo apt install -y libpq5 redis-server nginx supervisor

wget https://packaging.ckan.org/python-ckan_2.10-jammy_amd64.deb

sudo dpkg -i python-ckan_2.10-jammy_amd64.deb

sudo apt install -y postgresql

sudo -u postgres psql -l

sudo -u postgres createuser -S -D -R -P ckan_default
password: FFB@q3Op64
sudo -u postgres createdb -O ckan_default ckan_default -E utf-8

sudo snap install docker

docker run --name ckan-solr -p 8983:8983 -d ckan/ckan-solr:2.10


sudo apt install x11-apps

sudo mkdir -p /var/lib/ckan/default

sudo chown www-data /var/lib/ckan/default
sudo chmod u+rwx /var/lib/ckan/default


Set the IP address in /etc/ckan/default/ckan.ini

ckan.site_url = http://158.39.201.32

sqlalchemy.url = postgresql://ckan_default:FFB@q3Op64@localhost/ckan_default


sudo ckan db init

sudo supervisorctl reload

sudo supervisorctl status

sudo service nginx restart

Installation if successful is available at http://158.39.201.32

https://docs.ckan.org/en/2.10/maintaining/getting-started.html

. /usr/lib/ckan/default/bin/activate
cd /usr/lib/ckan/default/src/ckan

Create sysadmin annefou

ckan -c /etc/ckan/default/ckan.ini sysadmin add annefou email=annefou@localhost name=annefou

T..af

ckan -c /etc/ckan/default/ckan.ini sysadmin --help

### Creating test data

pip install -r dev-requirements.txt

 sudo ckan -c /etc/ckan/default/ckan.ini generate fake-data organization
2023-09-28 19:09:23,103 INFO  [ckan.cli] Using configuration file /etc/ckan/default/ckan.ini
2023-09-28 19:09:23,103 INFO  [ckan.config.environment] Loading static files from public
2023-09-28 19:09:23,316 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2023-09-28 19:09:23,748 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2023-09-28 19:09:23,970 WARNI [ckan.config.middleware.flask_app] Extensions are excluded from CSRF protection! We allow extensions to run without CSRF protection but it will be forced future releases. Read the documentation for more information on how to add CSRF protection to your extension.
2023-09-28 19:09:24,300 DEBUG [ckanext.activity.logic.action] Created 'new organization' activity
{"approval_status": "approved", "created": "2023-09-28T19:09:24.221954", "description": "Usually provide style feeling after respond.", "display_name": "Gonzales, Rodriguez and Nelson", "id": "c46daccf-a93b-4162-9847-eb601cbdb8bf", "image_display_url": "https://placekitten.com/259/49", "image_url": "https://placekitten.com/259/49", "is_organization": true, "name": "organization-vkmz-7266-qtfe", "num_followers": 0, "package_count": 0, "state": "active", "title": "Gonzales, Rodriguez and Nelson", "type": "organization", "users": [{"about": null, "activity_streams_email_notifications": false, "capacity": "admin", "created": "2023-09-28T18:49:23.181812", "display_name": "default", "email_hash": "d41d8cd98f00b204e9800998ecf8427e", "fullname": null, "id": "2fdd938d-d313-44e2-9da3-cbe87ad8c3f2", "image_display_url": null, "image_url": null, "last_active": null, "name": "default", "number_created_packages": 0, "state": "active", "sysadmin": true}], "extras": [], "tags": [], "groups": []}


sudo ckan -c /etc/ckan/default/ckan.ini generate fake-data dataset --owner_org=c46daccf-a93b-4162-9847-eb601cbdb8bf

sudo vi /etc/ckan/default/ckan.ini

change for instance title and then restart to take changes into account:

sudo supervisorctl restart ckan-uwsgi:*



### Install extension

Need sources:

sudo /usr/lib/ckan/default/bin/pip install -r https://raw.githubusercontent.com/ckan/ckan/ckan-2.10.1/requirements.txt

sudo /usr/lib/ckan/default/bin/pip install -r https://raw.githubusercontent.com/ckan/ckan/ckan-2.10.1/dev-requirements.txt

In the oracle folder:

```
ssh -X -i ssh-key-2023-09-28.key ubuntu@158.39.201.32
```

We need to be `root` to define our extension and put it in the right folder:

sudo bash -i

Then activate ckan environment:

```
 . /usr/lib/ckan/default/bin/activate
```

We tried to use `cookiecutter` to generate the extension (as mentioned in the [documentation](https://docs.ckan.org/en/2.10/extensions/tutorial.html)) but it failed:

```
project [Project's name (must begin with 'ckanext-')]: ckanext-iauthfunctions
keywords [A space separated list of keywords]: tutorial
description []: 
author []: 
author_email []: 
github_user_name [Github user or organization name]: annefou
project_shortname [iauthfunctions]: 
plugin_class_name [IauthfunctionsPlugin]: 
include_examples [0]: 
Traceback (most recent call last):
  File "/tmp/tmp438bc8g_.py", line 99, in <module>
    recut()
  File "/tmp/tmp438bc8g_.py", line 75, in recut
    gen.generate_file(project_dir=destination,
  File "/usr/lib/ckan/default/lib/python3.10/site-packages/cookiecutter/generate.py", line 173, in generate_file
    tmpl = env.get_template(infile_fwd_slashes)
  File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/environment.py", line 1010, in get_template
    return self._load_template(name, globals)
  File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/environment.py", line 969, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
  File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/usr/lib/ckan/default/lib/python3.10/site-packages/jinja2/loaders.py", line 218, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: setup.py
ERROR: Stopping generation because post_gen_project hook script didn't exit successfully
Hook script failed (exit status: 1)
```

We tried a few things but it did not work. However, it works using `ckan generate extension`:

```
cd /usr/lib/ckan/default/src

ckan generate extension
```

Below is the output we got:

```
Extension's name [must begin 'ckanext-']: ckanext-iauthfunctions
Author's name []: 
Author's email []: 
Your Github user or organization name []: 
Brief description of the project []: 
List of keywords (separated by spaces) [CKAN]: 
Do you want to include code examples? [y/N]: 

Written: /usr/lib/ckan/default/src/ckanext-iauthfunctions
```


Below is what we have in plugin.py:

```
cat ckanext-iauthfunctions/ckanext/iauthfunctions/plugin.py
```

It returns:

```
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit


class IauthfunctionsPlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)
    

    # IConfigurer

    def update_config(self, config_):
        toolkit.add_template_directory(config_, "templates")
        toolkit.add_public_directory(config_, "public")
        toolkit.add_resource("assets", "iauthfunctions")

    
```

Then we need to add in the setup and entry point:

```
vi ckanext-iauthfunctions/setup.py 
```

Below is what we have in the file:

```
# -*- coding: utf-8 -*-
from setuptools import setup

setup(
   entry_points='''
    [ckan.plugins]
    example_iauthfunctions=ckanext.iauthfunctions.plugin:IAuthFunctionsPlugin
    ''',
    # If you are changing from the default layout of your extension, you may
    # have to change the message extractors, you can read more about babel
    # message extraction at
    # http://babel.pocoo.org/docs/messages/#extraction-method-mapping-and-configuration
    message_extractors={
        'ckanext': [
            ('**.py', 'python', None),
            ('**.js', 'javascript', None),
            ('**/templates/**.html', 'ckan', None),
        ],
    }
)
```

Then we need to install the extension:

```
. /usr/lib/ckan/default/bin/activate
cd /usr/lib/ckan/default/src/ckanext-iauthfunctions
python setup.py develop
```

Finally we need to enable the plugin:

```
vi /etc/ckan/default/ckan.ini
```

And add the name of the function (what is on the left handside in plugin.py)

Then we have in ckan.ini:

```
## Plugins Settings ############################################################
ckan.plugins = activity example_iauthfunctions
ckan.resource_proxy.timeout = 5
```

Then we need to restart:

```
 supervisorctl restart ckan-uwsgi:*

```


## Documentation

There are two cool inline blogs that detail how to implement a CKAN plugin.

- https://medium.com/@pooya.oladazimi/how-to-develop-a-plugin-for-ckan-part-one-45e7ca1f2270
- https://medium.com/@pooya.oladazimi/how-to-develop-a-ckan-plugin-part-2-templates-f798aeeaa7f8


## Adding signposting to CKAN


```
 ckan generate extension
```

We then need answer a few questions:

```
Extension's name [must begin 'ckanext-']: ckanext-signposting
Author's name []: Anne Fouilloux
Author's email []: annef@simula.no
Your Github user or organization name []: annefou
Brief description of the project []: CKAN extension for signposting
List of keywords (separated by spaces) [CKAN]: 
Do you want to include code examples? [y/N]: 

Written: /usr/lib/ckan/default/src/ckanext-signposting
```
