Install DSpace 7.6 on Ubuntu 22.04

Last updated on: Published by: Systems Librarian 2

PREREQUISITES

Update and upgrade packages

sudo apt update && sudo apt upgrade -y

Create dspace system user

sudo adduser dspace

Add dspace user to sudoers group

usermod -aG sudo dspace

Install openjdk-11

sudo apt install openjdk-11-jdk -y

Install git, ant and maven

sudo apt-get install git ant ant-optional maven -y

POSTGRES DATABASE SETUP

Install postgres-14. DSpace supports postgres 11, 12, 13, 14 and 15. This command should install postgres-14 on Ubuntu 22.04

sudo apt-get install postgresql postgresql-contrib libpostgresql-jdbc-java -y

Set up host based access on PostgreSQL with the following command

echo “host dspace dspace 127.0.0.1/32 md5” | sudo tee -a /etc/postgresql/14/main/pg_hba.conf

Change database user permissions to “trust” only

sudo sed -i ‘s/ident/trust/’ /etc/postgresql/14/main/pg_hba.conf

sudo sed -i ‘s/md5/trust/’ /etc/postgresql/14/main/pg_hba.conf

sudo sed -i ‘s/peer/trust/’ /etc/postgresql/14/main/pg_hba.conf

Restart postgres

sudo systemctl restart postgresql

Switch to postgres user

sudo su postgres

Create dspace db user

createuser dspace

Create the dspace db with unicode encoding

createdb dspace -E UNICODE

Access the db shell

psql -d dspace

Create the pgcrypto extension to the dspace database

CREATE EXTENSION pgcrypto;

Create the dspace user password

ALTER ROLE dspace WITH PASSWORD ‘your-db-password’;

Give the dspace db user ownership of the dspace db.

ALTER DATABASE dspace OWNER TO dspace;

Give necessary privileges to dspace db user on the dspace db

GRANT ALL PRIVILEGES ON DATABASE dspace TO dspace;

Exit the db shell

\q

Exit postgres user session

exit

Restart postgres

sudo systemctl restart postgresql

SOLR SETUP

Download solr-8

wget -c https://dlcdn.apache.org/lucene/solr/8.11.2/solr-8.11.2.tgz

Extract the file

tar xvf solr-8.11.2.tgz

Install solr

sudo bash solr-8.11.2/bin/install_solr_service.sh solr-8.11.2.tgz

The script will install solr in /opt/solr with a symbolic link to /opt/solr-[version] The solr data dir will be in /var/solr directory.

SETUP TOMCAT9

Only tomcat9 is supported for now (at the time of writing).

sudo apt install tomcat9

Define JAVA_HOME for tomcat inside

sudo nano /etc/default/tomcat9

as shown below

JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64

Configure tomcat’s memory utilization according to your available resources.

JAVA_OPTS=”-Djava.awt.headless=true -Xmx2048m -Xms1024m -XX:MaxPermSize=1024m”

Alter Tomcat’s default configuration to support searching and browsing of multi-byte UTF-8 correctly. Edit the file server.xml by editing as shown.

sudo nano /etc/tomcat9/server.xml

You can comment out the existing element and paste in the one below

<Connector port="8080" 
minSpareThreads="25"
              enableLookups="false"
              address="127.0.0.1"
              redirectPort="8443"
              connectionTimeout="20000"
              disableUploadTimeout="true"
              URIEncoding="UTF-8"/>    

Restart tomcat

sudo service tomcat9 restart

INSTALL DSPACE 7 BACKEND

Download dspace-7.6 backend code

wget -c https://github.com/DSpace/DSpace/archive/refs/tags/dspace-7.6.tar.gz

Extract the downloaded file

tar -zxvf dspace-7.6.tar.gz

Rename the folder (only to make the name simpler)

mv DSpace-dspace-7.6 dspace-server-src

cd to the directory

cd dspace-server-src

Create the deployment directory

sudo mkdir /opt/dspace-7 && sudo mkdir /opt/dspace-7/server

Change ownership of the deployment directory to dspace system user.

sudo chown dspace:dspace -R /opt/dspace-7/server

Create a configuration local.cfg file by copying the existing example file.

cp dspace/config/local.cfg.EXAMPLE dspace/config/local.cfg

Edit the file nano dspace/config/local.cfg

nano dspace/config/local.cfg

Edit the following configs

dspace.dir=/opt/dspace-7/server

dspace.server.url = http://YOUR-SERVER-IP:8080/server

dspace.ui.url = http://YOUR-SERVER-IP

solr.server = http://localhost:8983/solr

db.url = jdbc:postgresql://localhost:5432/dspace

db.driver = org.postgresql.Driver

db.username = dspace

db.password = dspace

BUILD DSPACE

mvn package

cd to the build directory dspace/target/dspace-installer

cd dspace/target/dspace-installer

Deploy the code

ant fresh_install

Configure tomcat9 to serve the deployed code

cd /var/lib/tomcat9/webapps

sudo ln -s /opt/dspace-7/server/webapps/server server

Copy over solr cores

sudo cp -r /opt/dspace-7/server/solr/* /var/solr/data/

Set ownership to solr user for the folders and files you just copied

sudo chown solr:solr -R /var/solr/data

Restart solr

sudo systemctl restart solr

Allow tomcat9 to ReadWrite /opt/dspace-7/server folder

sudo nano /etc/systemd/system/multi-user.target.wants/tomcat9.service

Under # Security section, add.

ReadWritePaths=/opt/dspace-7/server/

Save and close the file

Restart systemd and tomcat

sudo systemctl daemon-reload && sudo service tomcat9 restart

Initialize to create tables on the db

cd /opt/dspace-7/server

./bin/dspace database migrate

INSTALL DSPACE 7.6 ANGULAR FRONT-END

Download the source code

wget -c https://github.com/DSpace/dspace-angular/archive/refs/tags/dspace-7.6.tar.gz

Extract the files

tar -zxvf dspace-7.6.1tar.gz

Rename the directory (only to simplify the name)

mv dspace-angular-dspace-7.6 dspace-7-angular

cd to the directory

cd dspace-7-angular

Install node version manager

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash

Load NVM to the terminal session

source ~/.nvm/nvm.sh

Install npm

sudo apt install npm

Install yarn

sudo npm install –global yarn

Install node 16 or 18 LTS (or stable).

sudo npm install -g n

sudo n 18

Install pm2 (node.js process manager)

sudo npm install -g pm2

Install required angular dependencies

yarn install

Build angular for production

yarn build:prod

Create the deployment dir

sudo mkdir /opt/dspace-7/client

Give its ownership to dspace user

sudo chown dspace:dspace -R /opt/dspace-7/client/

Copy the dist dir to the deployment dir

cp -r dist /opt/dspace-7/client/

Create config dir

mkdir /opt/dspace-7/client/config

Create production config file

cp config/config.example.yml /opt/dspace-7/client/config/config.prod.yml

Configure angular to connect to the backend API

cd /opt/dspace-7/client/

RUN ANGULAR VIA PM2

Create the file dspace-ui.json

nano dspace-ui.json

Add

{
    "apps": [
        {
           "name": "dspace-ui",
           "cwd": "/opt/dspace-7/client",
           "script": "dist/server/main.js",
           "instances": 4,
           "exec_mode": "cluster",
           "env": {
              "NODE_ENV": "production"
           }
        }
    ]
}

Start the application

sudo pm2 start dspace-ui.json

SETUP NGINX AS REVERSE PROXY

Install nginx

sudo apt install nginx -y

Configure one server block inside /etc/nginx/sites-enabled/default as follows

server {
  listen 80;

  server_name    repository.hyperlink.co.ke;
  access_log /var/log/nginx/dspace-access.log;
  error_log /var/log/nginx/dspace-error.log;

  location /server {
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass http://localhost:8080/server;
  }

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:4000/;
  }
}

Restart nginx

sudo service nginx restart

SETUP SSL USING LETSENCRYPT’S CERTBOT PACKAGE

Install certbot

sudo snap install --classic certbot

Ensure the certbot command can be run

sudo ln -s /snap/bin/certbot /usr/bin/certbot

Fetch and configure ssl cert for nginx

sudo certbot --nginx

Create a dspace administrator account

cd /opt/dspace-7/server
sudo bin/dspace create-administrator

Your system should now be ready for use.

Refer to the official documentation for dspace 7 installation if you encounter any challenges. It is more detailed and explains each of these steps.

Related posts

2 Replies to “Install DSpace 7.6 on Ubuntu 22.04”

    1. Systems Librarian Post author

      In this guide, we created a database user “dspace” with the password “dspace”. But by default, database user called postgres is created and you can use sudo su postgres to switch to the user’s shell session.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.