OCS is an Open Computers and Software Inventory Next Generation Inventory. It helps system administrators to manage IT assets in a simpler and more organized manner. With OCS, you can collect hardware and software inventory from all active devices on the network including, routers, switches, computers, printers, and many more from the central location. It can be installed on many operating systems such as Sun Solaris, IBM AIX, HP-UX, Windows, Linux, macOS, and many more.

In this tutorial, we will explain how to install the OCS Inventory server on Ubuntu 22.04.

Prerequisites

  • A server running Ubuntu 22.04.
  • A root password is configured on the server.

Getting Started

First, it is a good idea to update all the system packages to the latest version. You can update all of them with the following command:

apt-get update -y
apt-get upgrade -y

Once your server is up-to-date, you will need to install other required dependencies in your server. You can install all of them with the following command:

apt-get install make cmake gcc make git curl unzip -y

Once all the packages are installed, you can proceed to the next step.

Install LAMP Server

Next, you will need to install the Apache web server, MariaDB server, PHP, and other required PHP extensions on your server. You can install all of them by running the following command:

apt-get install apache2 mariadb-server libapache2-mod-perl2 libapache-dbi-perl libapache-db-perl php libapache2-mod-php php-common php-sqlite3 php-mysql php-gmp php-curl php-mbstring php-gd php-cli php-xml php-zip php-soap php-json php-pclzip composer

Once all the packages are installed, edit the php.ini file and change the default settings:

nano /etc/php/8.1/apache2/php.ini

Change the following settings:

memory_limit = 256M
post_max_size = 100M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Save and close the file when you are finished.

Install Perl and Required Modules

You will also need to install Perl and some Perl modules on your server. You can install all of them with the following command:

apt-get install perl libxml-simple-perl libcompress-zlib-perl libdbi-perl libdbd-mysql-perl libnet-ip-perl libsoap-lite-perl libio-compress-perl libapache-dbi-perl libapache2-mod-perl2 libapache2-mod-perl2-dev -y

After installing all modules, enable them with the following command:

perl -MCPAN -e 'install Apache2::SOAP'
perl -MCPAN -e 'install XML::Entities'
perl -MCPAN -e 'install Net::IP'
perl -MCPAN -e 'install Apache::DBI'
perl -MCPAN -e 'install Mojolicious'
perl -MCPAN -e 'install Switch'
perl -MCPAN -e 'install Plack::Handler'

Once you are finished, you can proceed to the next step.

Create a Database for OCS

Next, you will need to create a database and user for OCS inventory. First, log in to the MariaDB shell with the following command:

mysql

Once login, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE ocsdb;
MariaDB [(none)]> CREATE USER 'ocsuser'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the ocsdb with the following command:

MariaDB [(none)]> GRANT ALL ON ocsdb.* TO 'ocsuser'@'localhost' WITH GRANT OPTION;

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Download and Install OCS Inventory

Next, you will need to download the latest version of OCS from the Git repository. You can download it with the following command:

git clone https://github.com/OCSInventory-NG/OCSInventory-Server.git

You should see the following output:

Cloning into 'OCSInventory-Server'...
remote: Enumerating objects: 8628, done.
remote: Counting objects: 100% (755/755), done.
remote: Compressing objects: 100% (307/307), done.
remote: Total 8628 (delta 442), reused 647 (delta 377), pack-reused 7873
Receiving objects: 100% (8628/8628), 52.87 MiB | 31.04 MiB/s, done.
Resolving deltas: 100% (6004/6004), done.

Once downloaded, change the directory to OCSInventory-Server and download the ocsreport project with the following command:

cd OCSInventory-Server
git clone https://github.com/OCSInventory-NG/OCSInventory-ocsreports.git ocsreports

Next, change the directory to ocsreports and install the Composer with the following command:

cd ocsreports
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Once the Composer is installed, you should get the following output:

All settings correct for using Composer
Downloading...

Composer (version 2.4.4) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Next, go back to the OCSInventory-Server directory and edit the setup.sh file:

cd ..
nano setup.sh

Define your database settings as shown below:

# Which host run database server
DB_SERVER_HOST="localhost"
# On which port run database server
DB_SERVER_PORT="3306"
# Database server credentials
DB_SERVER_USER="ocsuser"
DB_SERVER_PWD="password"

Save and close the file when you are finished.

Next, start the OCS inventory installation by running the following command:

./setup.sh

During the installation, you will be asked several questions. Answer all questions as shown below:

 ---------------------------------------------------------- 
|                                                          |
|  Welcome to OCS Inventory NG Management server setup !   |
|                                                          |
 ---------------------------------------------------------- 

Trying to determine which OS or Linux distribution you use
 ---------------------------------------------------------- 
| Checking for Apache web server binaries !				|
 ---------------------------------------------------------- 

CAUTION: If upgrading Communication server from OCS Inventory NG 1.0 RC2 and
previous, please remove any Apache configuration for Communication Server!

Do you wish to continue ([y]/n)?y
Assuming Communication server 1.0 RC2 or previous is not installed
on this computer.

Starting OCS Inventory NG Management server setup from folder /root/OCSInventory-Server
Storing log in file /root/OCSInventory-Server/ocs_server_setup.log

 ---------------------------------------------------------- 
| Checking for database server properties...			  |
 ---------------------------------------------------------- 

Your MySQL client seems to be part of MySQL version 10.3.
Your computer seems to be running MySQL 4.1 or higher, good ;-)

Which host is running database server [localhost] ?
OK, database server is running on host localhost ;-)

On which port is running database server [3306] ?
OK, database server is running on port 3306 ;-)


 ---------------------------------------------------------- 
| Checking for Apache web server daemon...				|
 ---------------------------------------------------------- 

Where is Apache daemon binary [/usr/sbin/apache2ctl] ?
OK, using Apache daemon /usr/sbin/apache2ctl ;-)


 ---------------------------------------------------------- 
| Checking for Apache main configuration file...		  |
 ---------------------------------------------------------- 

Where is Apache main configuration file [/etc/apache2/apache2.conf] ?
OK, using Apache main configuration file /etc/apache2/apache2.conf ;-)


 ---------------------------------------------------------- 
| Checking for Apache user account...					 |
 ---------------------------------------------------------- 

Which user account is running Apache web server [www-data] ?
OK, Apache is running under user account www-data ;-)


 ---------------------------------------------------------- 
| Checking for Apache group...							|
 ---------------------------------------------------------- 

Which user group is running Apache web server [www-data] ?
OK, Apache is running under users group www-data ;-)


 ---------------------------------------------------------- 
| Checking for Apache Include configuration directory...   |
 ---------------------------------------------------------- 

Setup found Apache Include configuration directory in
/etc/apache2/conf-available.
Setup will put OCS Inventory NG Apache configuration in this directory.
Where is Apache Include configuration directory [/etc/apache2/conf-available] ?
OK, Apache Include configuration directory /etc/apache2/conf-available found ;-)


 ---------------------------------------------------------- 
| Checking for PERL Interpreter...						|
 ---------------------------------------------------------- 

Found PERL interpreter at  ;-)
Where is PERL interpreter binary [/usr/bin/perl] ?
OK, using PERL interpreter /usr/bin/perl ;-)


Do you wish to setup Communication server on this computer ([y]/n)?y

 ---------------------------------------------------------------------- 
|        OK, Administration server installation finished ;-)           |
|                                                                      |
| Please, review /etc/apache2/conf-available/ocsinventory-reports.conf
|          to ensure all is good and restart Apache daemon.            |
|                                                                      |
| Then, point your browser to http://server//ocsreports
|        to configure database server and create/update schema.        |
 ---------------------------------------------------------------------- 


Setup has created a log file /root/OCSInventory-Server/ocs_server_setup.log. Please, save this file.
If you encounter error while running OCS Inventory NG Management server,
we can ask you to show us its content !

DON'T FORGET TO RESTART APACHE DAEMON !

Enjoy OCS Inventory NG ;-)

Enable OCS Inventory for Apache

Next, you will also need to enable the OCS Inventory Apache virtual host configuration file. You can enable them with the following command:

ln -s /etc/apache2/conf-available/ocsinventory-reports.conf /etc/apache2/conf-enabled/ocsinventory-reports.conf
ln -s /etc/apache2/conf-available/z-ocsinventory-server.conf /etc/apache2/conf-enabled/z-ocsinventory-server.conf
ln -s /etc/apache2/conf-available/zz-ocsinventory-restapi.conf /etc/apache2/conf-enabled/zz-ocsinventory-restapi.conf

Next, change the ownership of the OCS inventory-reports directory to www-data with the following command:

chown -R www-data:www-data /var/lib/ocsinventory-reports

Next, restart the Apache service to apply the changes:

systemctl restart apache2

You can also check the Apache status using the following command:

systemctl status apache2

You should see the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-04 14:52:58 UTC; 6s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 86019 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 86023 (/usr/sbin/apach)
      Tasks: 6 (limit: 4579)
     Memory: 38.9M
        CPU: 815ms
     CGroup: /system.slice/apache2.service
             ??86023 /usr/sbin/apache2 -k start
             ??86024 /usr/sbin/apache2 -k start
             ??86025 /usr/sbin/apache2 -k start
             ??86026 /usr/sbin/apache2 -k start
             ??86027 /usr/sbin/apache2 -k start
             ??86028 /usr/sbin/apache2 -k start

Nov 04 14:52:58 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

Access OCS Inventory

Now, open your web browser and type the URL http://your-server-ip/ocsreports/install.php. You should see the OCS Inventory installation screen:

How To Install OCS Inventory Asset Management Software on Ubuntu 22.04 linux ubuntu

Provide your OCS database, database username, password, and click on the Send button. Once the installation has been completed successfully, you should see the following screen:

How To Install OCS Inventory Asset Management Software on Ubuntu 22.04 linux ubuntu

Click on the click here to enter OCS-NG GUI. You should see the OCS Inventory login screen as shown below:

How To Install OCS Inventory Asset Management Software on Ubuntu 22.04 linux ubuntu

Provide the default username and password as admin / admin and click on the Send button. You should see the OCS Inventory dashboard on the following screen:

How To Install OCS Inventory Asset Management Software on Ubuntu 22.04 linux ubuntu

Take care to change the default login password of the admin user to a secure password. Finally, remove the install.php file to get rid of the alert message on the dashboard.

rm -f /usr/share/ocsinventory-reports/ocsreports/install.php

Conclusion

Congratulations! You have successfully installed OCS Inventory on your Ubuntu 22.04 server. You can now use OCS in your organization and start managing your IT assets easily from the web browser. Feel free to ask me if you have any questions.