Install DSpace 7.6 on Ubuntu 22.04

By

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 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 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

systemctl restart postgresql

SOLR SETUP

Download solr-8

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

Extract the file

tar xvf solr-8.11.4.tgz

Install solr

sudo bash solr-8.11.4/bin/install_solr_service.sh solr-8.11.4.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).

apt install tomcat9

Define JAVA_HOME for tomcat inside

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.

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

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

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

Change ownership of the deployment directory to dspace system user.

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-HOST/server

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

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

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

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
ln -s /opt/dspace-7/server/webapps/server server

Copy over solr cores

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

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

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

Restart solr

systemctl restart solr

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

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

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

apt install npm

Install yarn

npm install --global yarn

Install node 16 or 18 LTS (or stable).

npm install -g n
n 18

Install pm2 (node.js process manager)

npm install -g pm2

Install required angular dependencies

yarn install

Build angular for production

yarn build:prod

Create the deployment dir

mkdir /opt/dspace-7/client

Give its ownership to dspace user

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

pm2 start dspace-ui.json

SETUP NGINX AS REVERSE PROXY

Install nginx

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 $server_name;
    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

service nginx restart

SETUP SSL USING LETSENCRYPT’S CERTBOT PACKAGE

Install certbot

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.

About The Author

10 responses to “Install DSpace 7.6 on Ubuntu 22.04”

  1. dwalakira Avatar

    hey what is the postgres password?

    1. Systems Librarian Avatar

      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.

  2. LibAuto Avatar

    i require you services

    1. Systems Librarian Avatar

      Please use this link to start a chat with me on whatsapp https://wa.me/message/BYBD3DXARCHJD1

      Message Hyperlink on WhatsApp.

  3. Tim Avatar
    Tim

    Thanks for the instructions. They were quite helpful.
    We did find something that was a little problematic. In the section: INSTALL DSPACE 7 BACKEND, when editing the local config, your example reads:
    dspace.server.url = http://YOUR-SERVER-IP:8080/server
    This does not match the settings for the server itself. If following your instructions, that URL gets defined with the nginx reverse proxy, which you defined later as not having the 8080. Since we were doing a fair bit of copy/paste, it took us a bit to track that down.
    For what it is worth, with the 8080 in the local conf but with the nginx proxy not using the 8080, the Angular backend hangs, giving an out-of-memory error if you run it in dev mode. And, the UI gives you a “gateway timeout” error.

    1. Systems Librarian Avatar

      Thanks Tim for pointing that out. I have updated it accordingly.

  4. ahmed Avatar
    ahmed

    How can you add the Arabic language to the dspace 7.6

    1. Systems Librarian Avatar

      You can add Arabic language by creating (if it doesn’t exist already) a file called ar.json5 to the assets/i18n folder of your theme.

  5. Gabriel Avatar

    hi, thanks for the guide, when i finish the installing i see the angular dspace web, but redirects to

    https://myhost/500

    Can you help me?

    1. Systems Librarian Avatar

      Replace any occurrence of “myhost” in local.cfg, nginx and config.prod.yml with the actual hostname of your server. If you are using an IP address, then use the IP address. If you need more help please contact me on whatsapp using this link https://wa.me/message/BYBD3DXARCHJD1

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.

×

Hello!

Select one of our contacts below to chat on WhatsApp

× How can I help you?