How to Install OCS Inventory Server on Ubuntu Linux

This brief tutorial shows students and new users how to install OCS-NG (Open Computers and Software Inventory Next Generation) on Ubuntu 18.04 | 16.04 with Apache2 HTTP server.

For the uninitiated, OCS-NG is a free asset management platform that is easy to install, setup and manage and can run in almost any network environment.

With SNMP protocol scans, you’ll be able to gather information about your network hardware: printers, switches, computer, etc.

These devices don’t need to have OCS client installed to be discovered. Simply install OCS Inventory server and begin scanning your network. In no time, you should begin to see devices appearing in your dashboard.

For some devices, OCS Inventory includes the package deployment feature that can be installed to on supported devices to gather even more information about device name, address, location and more.

If you’re looking for a IT hardware inventory system for your business, then OCS Inventory is a great place to start.

For more about OCS Inventory, please check their Homepage

To get started with installing OCS CMS, follow the steps below:

Install Required Packages

Before setting up OCS server on Ubuntu, you must first install required packages to enable the server to function. To do that, run the commands below to install the below packages.

sudo apt update
sudo apt install make cmake gcc make

Install Apache2 HTTP Server

OCS works great with Apache2 HTTP server. To install Apache2 web server and other modules, run the commands below.

sudo apt install apache2 libapache2-mod-perl2 libapache-dbi-perl libapache-db-perl libapache2-mod-php

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Now that Apache2 is installed. to test whether the web server is working, open your browser and browse to the URL below.


Apache2 Test Page

If you see the page above, then Apache2 is successfully installed.

Install MariaDB Database Server

OCS also requires a database server to store its content. If you’re looking for a truly open source database server, then MariaDB is a great place to start.

To install MariaDB run the commands below:

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 18.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Now that MariaDB is installed, to test whether the database server was successfully installed, run the commands below.

sudo mysql -u root -p

type the root password when prompted.

mariadb welcome

If you see a similar screen as shown above, then the server was successfully installed.

Install PHP 7.2 and Related Modules

OCS-NG is a PHP and Perl based platform. However, PHP 7.2 may not be available in Ubuntu default repositories. To run PHP 7.2 on Ubuntu 16.04 and previous, you may need to run the commands below:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 7.2

sudo apt update

Next, run the commands below to install PHP 7.2 and related modules.

sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-sqlite3 php7.2-mysql php7.2-gmp php7.2-curl php7.2-mbstring php7.2-gd php7.2-cli php7.2-xml php7.2-zip php7.2-soap php7.2-json php-pclzip

After installing PHP 7.2, run the commands below to open PHP default configuration file for Apache2.

sudo nano /etc/php/7.2/apache2/php.ini

The lines below is a good settings for most PHP based apps. Update the configuration file with these and save.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Everytime you make changes to PHP configuration file, you should also restart Apache2 web server. To do so, run the commands below:

sudo systemctl restart apache2.service

Now that PHP is installed, to test whether it’s functioning, create a test file called phpinfo.php in Apache2 default root directory. ( /var/www/html/)

sudo nano /var/www/html/phpinfo.php

Then type the content below and save the file.

<?php phpinfo( ); ?>

Next, open your browser and browse to the server’s hostname or IP address followed by phpinfo.php

/phpinfo.php

You should see PHP default test page.

PHP Test Page

Create OCS-NG Database

Now that you’ve installed all the packages that are required for OCS-NG to function, continue below to start configuring the servers. First run the commands below to create a blank OCS database.

To logon to MariaDB database server, run the commands below.

sudo mysql -u root -p

Then create a database called ocs

CREATE DATABASE ocs;

Create a database user called ocsuser with a new password

CREATE USER 'ocsuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON ocs.* TO 'ocsuser'@'localhost' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Install Perl and Modules

Perl is required for OCS_NG. To install Perl and required modules, run the commands below:

sudo apt -y 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

After installing above, run the commands below to enable Perl modules.

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

Download OCS-NG Latest Release

When you’re all done with installing the packages above, continue below to clone OCS-NG package from Github and installed.

sudo apt install git curl
cd /tmp
git clone 

Then change into OCSInventory-Server folder, clone the ocsreport project, edit its setup.sh script and begin the installation.

cd OCSInventory-Server
git clone  ocsreports

After cloning the ocsreports project, change into it, then install Composer and update the ocsreports packages

cd /tmp/OCSInventory-Server/ocsreports
curl -sS  | sudo php -- --install-dir=/usr/local/bin --filename=composer
sudo composer install

After that go back to the OCSInventory-Server folder, then edit the setup.sh file and type in the database username and password. then save and exit.

cd . 
nano setup.sh

Edit the highlighted lines and save the file.

 This code is open source and may be copied and modified as long as the source
# code is always made freely available.
# Please refer to the General Public Licence  or Licence.txt
################################################################################
#
# 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="ocsuser_password_here"
# Where is Apache daemon binary (if empty, will try to find it)
APACHE_BIN=""
# Where is Apache configuration file (if empty, will try to find it)

When you’re done, run the commands below to begin the installation.

sudo ./setup.sh

During the installation, you’ll get numeral prompts. Choose the default settings and select y for all. When you’re done, you should see similar lines as below:

+----------------------------------------------------------------------+
|        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 
|        to configure database server and create/update schema.        |
+----------------------------------------------------------------------+

Setup has created a log file /tmp/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 the OCS Portal

To enable OCS Portal, run the commands below each line at a time.

sudo ln -s /etc/apache2/conf-available/ocsinventory-reports.conf /etc/apache2/conf-enabled/ocsinventory-reports.conf
sudo ln -s /etc/apache2/conf-available/z-ocsinventory-server.conf /etc/apache2/conf-enabled/z-ocsinventory-server.conf
sudo ln -s /etc/apache2/conf-available/zz-ocsinventory-restapi.conf /etc/apache2/conf-enabled/zz-ocsinventory-restapi.conf
sudo chown -R www-data:www-data /var/lib/ocsinventory-reports
sudo systemctl restart apache2.service

After running the commands above, open your browser and browse to the server domain name or IP address.


Next type in the database username and password created above, then click Send

OCS Inventory Ubuntu Setup

Next, click the OCS-NG GUI link.

OCS Inventory Ubuntu Setup

Then click the link to Perform the update.

OCS Inventory Ubuntu Setup

After that the installation should be done.

OCS Inventory Ubuntu Setup

Login with the username admin and password admin

OCS Inventory Ubuntu Setup

Rename the install folder for security reasons.

sudo mv /usr/share/ocsinventory-reports/ocsreports/install.php /usr/share/ocsinventory-reports/ocsreports/install.php.bak

Enjoy~

Congratulation! You have successfully installed OCS Inventory Sever on Ubuntu 16.04 | 18.04.

You may also like the post below: