In this tutorial, you will learn how to install OCS Inventory Server on Ubuntu 22.04/Ubuntu 20.04. OCS (Open Computers and Software Inventory Next Generation) is an opensource assets inventory management solution. It is used to inventory hardware and software details of IT assets either using the OCS Inventory Agent or SNMP polling for assets that the agent cannot be deployed (e.g routers, switches, printers. Inventoried results can be visualized through a web interface.
Table of Contents
Installing OCS Inventory Server on Ubuntu 22.04|20.04
Install MariaDB Database
A database is required by OCS to store inventory information.
Check the link below to install MariaDB database on Ubuntu;
How to install and setup MariaDB database on Ubuntu
Assuming you have already installed MariaDB, let’s create the database and database users for OCS inventory server.
Be sure to replace the name of the database and database user, and the user password.
mysql -u root -p -e "create database ocsng_db;"
mysql -u root -p -e "create user ocsadmin@localhost identified by 'ChangeME'; \
grant all on ocsng_db.* to ocsadmin@localhost; flush privileges;"
Install PHP and Required Modules
Ubuntu 20.04
Note that PHP 7.4 is the default available version on Ubuntu 20.04 repositories by default, as of this writing.
apt info php
Package: php
Version: 2:7.4+75
Priority: optional
Section: php
Source: php-defaults (75)
Origin: Ubuntu
Maintainer: Ubuntu Developers
Original-Maintainer: Debian PHP Maintainers
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13.3 kB
Depends: php7.4
Download-Size: 2,712 B
APT-Sources: http://de.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Ubuntu 22.04
Similarly, on Ubuntu 22.04, PHP 8.1 is the default available on the default repos, as of this writing.
apt info php
Package: php
Version: 2:8.1+92ubuntu1
Priority: optional
Section: php
Source: php-defaults (92ubuntu1)
Origin: Ubuntu
Maintainer: Ubuntu Developers
Original-Maintainer: Debian PHP Maintainers
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 14.3 kB
Depends: php8.1
Download-Size: 2,756 B
APT-Sources: http://de.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
Thus, execute the command below to install PHP 8.2 and required modules on Ubuntu 20.04 and Ubuntu 22.04
apt -y install apt-transport-https lsb-release ca-certificates curl \
wget gnupg2 software-properties-common
add-apt-repository ppa:ondrej/php --yes
apt install php8.2 php-pclzip php8.2-mbstring php8.2-soap php8.2-mysql \
php8.2-curl php8.2-xml php8.2-zip php8.2-gd
Confirm PHP version;
php -v
PHP 8.2.8 (cli) (built: Jul 8 2023 07:10:21) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
Install OCS NG Inventory APT Repository
In order to be able to install the latest and stable release version of OCS Inventory server on Ubuntu, you need to install their APT repository.
NOTE: As much there is no support for Ubuntu 22.04 on the APT repository, the repos for Ubuntu 20.04 should still be able to work.
Thus, to install the OCS APT repository on Ubuntu 22.04/Ubuntu 20.04;
Install the Repository signing key;
apt install gnupg2 curl wget -y
curl -sS http://deb.ocsinventory-ng.org/pubkey.gpg | \
gpg --dearmor -o /etc/apt/trusted.gpg.d/ocs.gpg
Next, install the repo itself;
echo "deb http://deb.ocsinventory-ng.org/ubuntu/ `lsb_release -sc` main" | \
tee /etc/apt/sources.list.d/ocsinventory.list
Installing OCS Inventory Server on Ubuntu
The use of the APT repository installed above ensures that some of the package dependencies required to setup OCS inventory server on Ubuntu installed.
Run system package cache update;
apt update
Before you can proceed, install some other required Perl module;
apt install make
perl -MCPAN -e 'install XML::Entities'
When prompted, enter yes and press ENTER to proceed.
Next, install OCS Inventory server and web console; on Ubuntu;
apt install ocsinventory
Update OCS Inventory DB Connection Settings
Open the Communication Server Apache configuration file and update the database connection details
vim /etc/apache2/conf-available/z-ocsinventory-server.conf
...
<IfModule mod_perl.c>
# Which version of mod_perl we are using
# For mod_perl <= 1.999_21, replace 2 by 1
# For mod_perl > 1.999_21, replace 2 by 2
PerlSetEnv OCS_MODPERL_VERSION 2
# Master Database settings
# Replace localhost by hostname or ip of MySQL server for WRITE
PerlSetEnv OCS_DB_HOST localhost
# Replace 3306 by port where running MySQL server, generally 3306
PerlSetEnv OCS_DB_PORT 3306
# Name of database
PerlSetEnv OCS_DB_NAME ocsng_db
PerlSetEnv OCS_DB_LOCAL ocsng_db
# User allowed to connect to database
PerlSetEnv OCS_DB_USER ocsadmin
# Password for user
PerlSetVar OCS_DB_PWD ChangeME
# SSL Configuration
...
Save and exit the configuration file when done.
Next, update the database connection details on the API config;
vim /etc/apache2/conf-available/zz-ocsinventory-restapi.conf
...
<Perl>
$ENV{PLACK_ENV} = 'production';
$ENV{MOJO_HOME} = '/usr/share/perl5';
$ENV{MOJO_MODE} = 'deployment';
$ENV{OCS_DB_HOST} = 'localhost';
$ENV{OCS_DB_PORT} = '3306';
$ENV{OCS_DB_LOCAL} = 'ocsng_db';
$ENV{OCS_DB_NAME} = 'ocsng_db';
$ENV{OCS_DB_USER} = 'ocsadmin';
$ENV{OCS_DB_PWD} = 'ChangeME';
$ENV{OCS_DB_SSL_ENABLED} = 0;
...
Save and exit the file.
Similarly, update the web console database connection settings;
vim /etc/ocsinventory-reports/dbconfig.inc.php
<?php
define("DB_NAME", "ocsng_db");
define("SERVER_READ","localhost");
define("SERVER_WRITE","localhost");
define("SERVER_PORT","3306");
define("COMPTE_BASE","ocsadmin");
define("PSWD_BASE","ChangeMe");
define("ENABLE_SSL","");
define("SSL_MODE","");
define("SSL_KEY","");
define("SSL_CERT","");
define("CA_CERT","");
?>
Save the changes and exit the file
Update PHP Settings
Edit the PHP php.ini
to optimize certain settings for OSC best suited for your env.
vim /etc/php/8.2/apache2/php.ini
OCS recommends disabling max_execution_time
and max_input_time
by setting the following value:
max_execution_time = -1
max_input_time = -1
These settings define the maximum life time of the script and the time that the script should spend in accepting input.
Adjust file upload limit size:
upload_max_filesize = 50M
post_max_size = 50M
Additionally you can adjust size of memory for php engine.
memory_limit = 256M
Save and exit the file.
Update OCS Configs Owership and Permissions
Set the proper permissions and ownership of OCS configuration files.
chmod -R 766 /usr/share/ocsinventory-reports
chown -R www-data:www-data /usr/share/ocsinventory-reports \
/var/lib/ocsinventory-reports
Disable default Apache site;
a2dissite 000-default.conf
Restart Apache and MariaDB.
systemctl restart apache2 mariadb
Finalize OCS-NG Configuration via Web Interface
If there is a firewall in place, open web ports to allow external access to OCS inventory web console.
Navigate to http://server-hostname-or-IP/ocsreports
on your browser to access OCS.
Configure OCS Inventory database connection details and click Send.
Installation complete;
Next, click Click here to enter OCS-NG GUI to proceed.
If prompted to perform database update, please do so and proceed to login page when update is done.
Next, click Click here to enter OCS-NG GUI to login to OCS web interface.
OCS Inventory Server Web Dashboard
Use the default credentials:
- login: admin
- password: admin
OCS Inventory server dashboard;
Reset the password: Settings gear > My account > Password.
Remove the installation script.
mv /usr/share/ocsinventory-reports/ocsreports/install.php{,.old}
That marks the end of our guide on how to install OCS NG Inventory server on Ubuntu 22.04/Ubuntu 20.04.
Reference: OCS Inventory Documentation.