DSpace

Install DSpace 7 on Ubuntu 22.04 LTS
Open terminal

Refreshes your system's local "catalog" of available software
sudo apt update && sudo apt upgrade -y

To open an interactive root shell session
sudo su
Provide password

OR

If you want to create new DSpace user;
sudo useradd -m dspace
sudo passwd dspace

enter a password for dspace

Add dspace user to sudoers group
sudo usermod -aG sudo dspace 

Install Mousepad text editor 
sudo apt -y install mousepad

Create the directory for the DSpace installation.
sudo mkdir /dspace

Change the dspace folder permission to the dspace user.

sudo chown dspace /dspace

Install packages to support the Dspace installation.

sudo apt install wget curl git build-essential mousepad zip unzip -y

Install Open JDK

sudo apt install openjdk-11-jdk -y

Set the JAVA_HOME Environment Variable: Java installation location
sudo mousepad /etc/environment

Add the following two lines to the file,
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
JAVA_OPTS="-Xmx512M -Xms64M -Dfile.encoding=UTF-8"
Save and close the file.

Check the Java Home is successfully saved
source /etc/environment
echo $JAVA_HOME
echo $JAVA_OPTS

Install Maven and Ant
sudo apt install maven ant -y

Install PostgreSQL
sudo apt-get install postgresql postgresql-client postgresql-contrib libpostgresql-jdbc-java -y

Apply the following command to check the PostgreSQL version number. 
psql -V psql

PostgreSQL varies 14 is available
sudo pg_ctlcluster 14 main start
sudo systemctl status postgresql

Apply the key, CTRL + C, to exit from the screen.

Create a password for PostgreSQL.
sudo passwd postgres

Try to login into PostgreSQL using the password created.
su postgres

Now the command prompt looks like postgres@user: 
exit

Open the following file,
sudo mousepad /etc/postgresql/14/main/postgresql.conf

Uncomment the line (remove #) listen_addresses = 'localhost' under the connection settings option.
Save and exit

The security of PostgreSQL
sudo mousepad /etc/postgresql/14/main/pg_hba.conf

Find the line, # Database administrative login.
Add the following lines below it,

#DSpace configuration
host dspace dspace 127.0.0.1 255.255.255.255 md5

Restart Postresql
sudo systemctl restart postgresql

Solr Installation
Save solr-8.11.4.zip to the opt folder in the operating system

Apply the following command,
cd

Download the Solr (version 8) package using the following command line,
sudo wget https://downloads.apache.org/lucene/solr/8.11.4/solr-8.11.4.zip

Unzip the package,
sudo unzip solr-8.11.4.zip

Apply the following command to install Solr,
sudo bash solr-8.11.4/bin/install_solr_service.sh solr-8.11.4.zip


After successful installation, exit from the process. Apply the key combination,
Ctl + C

Apply the following commands for restart automatically
sudo systemctl enable solr
sudo systemctl start solr
sudo systemctl status solr

To exit apply CTRL + C

Add the URL on a browser to open the Solr interface,
http://localhost:8983/solr

Download the DSpace package
Create a build temporary folder in the root (/)
sudo mkdir /build

cd /build
sudo wget https://github.com/DSpace/DSpace/archive/refs/tags/dspace-7.6.1.zip

Extract the package,
sudo unzip dspace-7.6.1.zip

Change the permission of the /build folder.
sudo chmod 777 -R /build

HTTP web server environment where Java code can run

Install Tomcat
sudo apt install tomcat9 -y

Open the following file for DSpace installation path to Tomcat
sudo mousepad /lib/systemd/system/tomcat9.service

Find the category, #Security,
Add the following line at the last portion,
ReadWritePaths=/dspace
Save and close the file.

The default configuration to support searching and browsing of multi-byte UTF-8.

Open the following file,
sudo mousepad /etc/tomcat9/server.xml

Find the below-mentioned lines in the file, and comment out. Add  <!-- in the first line and --> in the last line,

<Connector port="8080" protocol="HTTP/1.1"
           	connectionTimeout="20000"
           	redirectPort="8443" />
It will look like this after commented out,

<!-- <Connector port="8080" protocol="HTTP/1.1"
           	connectionTimeout="20000"
           	redirectPort="8443" /> -->
Add the following lines below the commented-out lines,

<Connector port="8080" protocol="HTTP/1.1"
			minSpareThreads="25"
			enableLookups="false"
			redirectPort="8443"
			connectionTimeout="20000"
			disableUploadTimeout="true"
			URIEncoding="UTF-8"/>
Save and close the file.

Restart Tomcat,
sudo systemctl restart tomcat9.service

If it shows the following error message,

Warning: The unit file, source configuration file or drop-ins of tomcat9.service changed on disk. Run 'systemctl daemon-reload to reload units.

Apply the following command,
sudo systemctl daemon-reload

Try to restart the Tomcat,
sudo systemctl restart tomcat9.service

DSpace Database setup

Login into the Postgres terminal
sudo su postgres

If there are any changes in the version, please check it
cd /etc/postgresql/14/main

Create the user named dspace and password for the dspace 
createuser --username=postgres --no-superuser --pwprompt dspace

Create the database with the name dspace, the database owner is dspace
createdb --username=postgres --owner=dspace --encoding=UNICODE dspace

Enable pgcrypto extension. 
psql --username=postgres dspace -c "CREATE EXTENSION pgcrypto;"

Exit from the Postgres terminal,
exit

Create a new DSpace configuration fil.
cd /build/DSpace-dspace-7.6.1/dspace/config
 
Make a copy of the local.cfg file,
sudo cp local.cfg.EXAMPLE local.cfg
 
Open the local.cfg file,
sudo mousepad local.cfg

Please identify the essential lines in the file and their purpose. Provide IP address or DNS instead of localhost.

DSpace server URL
dspace.server.url = http://localhost:8080/server

DSpace frontend URL
dspace.ui.url = http://localhost:4000

# Name of the site
dspace.name = DSpace at My University
If any changes in the DSpace database username/password, mention them here.

# Database username and password
db.username = dspace
db.password = dspace
Uncomment the following line in the local.cfg file,

solr.server = http://localhost:8983/solr
Save and close the file.

Installation of DSpace backend
Login as the Root user,
sudo su
 
Enter into the DSpace package downloaded folder
cd /build/DSpace-dspace-7.6.1
 
Download and install the dependencies and the required packages
mvn package

Depends on the Internet speed and server responses it may take 15 to 30 minutes to finish. 

Install DSpace Backend
Enter into the DSpace installer located and install
cd dspace/target/dspace-installer
 
Install the DSpace package,
ant fresh_install

After successful install, exit from sudo user
exit

Copy the DSpace web apps folder to the Tomcat server folder
sudo cp -R /dspace/webapps/* /var/lib/tomcat9/webapps
 
Copy DSpace Solr folders into the default home of Solr (/var/solr/data),
sudo cp -R /dspace/solr/* /var/solr/data

Change the permission of the folder 
sudo chown -R solr:solr /var/solr/data

Restart Solr
sudo systemctl restart solr

Open the Solr on the browser using the URL
http://localhost:8983
Please check the Core Selector is available on the left side of the page

Initialize the Database. 

Enter into the dspace/bin folder and apply the migration command
cd /dspace/bin/
sudo ./dspace database migrate

Create a DSpace Administrator Account
sudo /dspace/bin/dspace create-administrator

The following questions will arise
Creating an initial administrator account
E-mail address: dspace@localhost
First name: dspace
Last name: dspace
Is the above data correct? (y or n): y
Password: Enter the password to login dspace.
Again to confirm: Confirm the password again.
Administrator account created

The permission of DSpace to Tomcat user
sudo chown -R tomcat:tomcat /dspace/
sudo systemctl restart tomcat9.service

Open a Browser and test the changes of tomcat
http://localhost:8080/server

Open OAI-PMH Interface,
http://localhost:8080/server/oai/request?verb=Identify 

Install the Front End: Install Node.js, Yarn, and DSpace-Angular packages.

Install Node.js
sudo apt install nodejs -y

Install NVM
sudo su
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Close the current terminal and open a new one and the following commands to install the Node.js.

sudo su
nvm install 16.18.1
Install Yarn

Yarn is a software packaging system.
npm install --global yarn
npm install --global pm2
 
Front end installation
DSpace user interfaces build on Angular
cd /home/dspace

Download the dspace-angular package,
sudo wget https://github.com/DSpace/dspace-angular/archive/refs/tags/dspace-7.6.1.zip

Extract the package,
unzip dspace-7.6.1.zip
 
Remove the dspace zip package,
rm dspace-7.6.1.zip

Enter into the dspace-angular folder, 	
cd /home/dspace/dspace-angular-dspace-7.6.1

Install all dependencies,
yarn install

Enter into the /dspace-angular/config folder,
cd config

Copy and rename the following file,
cp config.example.yml config.prod.yml

Open the config file
mousepad config.prod.yml

Find the block of information and find the lines.  Make changes like this,
ssl: true -> false
host:  api7.dspace.org -> localhost
Port: Change to 8080

# The REST API server settings
# NOTE: these must be 'synced' with the 'dspace.server.url' setting in your backend's local.cfg.
rest:
ssl: false
host: localhost
port: 8080
Save and close the file.

Run the command,

yarn run build:prod
exit

Startup the User Interface
Create a PM2 JSON configuration file. 
Create the file,
sudo mousepad /home/dspace/dspace-angular-dspace-7.6.1/dspace-ui.json

Copy the following content into the dspace-ui.jason file,

{
    "apps": [
        {
           "name": "dspace-ui",
           "cwd": "/home/dspace/dspace-angular-dspace-7.6.1/",
           "script": "dist/server/main.js",
           "instances": 4,
           "exec_mode": "cluster",
           "env": {
              "NODE_ENV": "production"
           }
        }
    ]
}
Start the application using PM2. Apply the following command to start the service,
sudo su
pm2 start /home/dspace/dspace-angular-dspace-7.6.1/dspace-ui.json
Create a cronjob entry at the ROOT user to autostart dspace-ui.json. Login as a ROOT user. Apply the following commands,

crontab -e
Add the following line

#Auto start dspace-angular
@reboot bash -ci 'pm2 start /home/dspace/dspace-angular-dspace-7.6.1/dspace-ui.json'

To save the file, apply CTRL + O key combination. Exit from the editor and apply CTRL + X.
Enter the below URL on the browser to start the DSpace front end,
http://localhost:4000

Install/configure pm2-logrotate to ensure that PM2's log folder doesn't fill up over time.

pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 1000K
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:rotateInterval 0 0 19 1 1 7
Build directory no longer required after the installation of DSpace; remove it. Apply the following command;

sudo rm -rf /build
Check the Solr, Tomcat, and DSpace