How To: Install OCS on Ubuntu 21.04

What is OCS or OCSng?:

In short, OCS (Open Computers and Software Inventory Next Generation) is an assets management and deployment solution.

OCS can be directly integrated with GLPI for seamless asset tracking automation. Check out my other blog post on how to install GLPI

Read more about OCS on their website: OCS

Overview:

In this article, we will go step-by-step on how to install OCS on Ubuntu 21.04. There are a few installation gotchas that I have overcome that are not mentioned in the OCS documentation and I wanted to share this information so that anyone just getting into OCS or wanting to know more about OCS doesn’t have to go through the same pain I had to.

Just give me the commands

Prerequisites:

  • Note: All commands are done via an SSH connection in this guide.

To start you will need to open an SSH session to your Ubuntu machine, if you are on windows you can use putty or even PowerShell to achieve this.

Install the various array of applications and extensions needed to properly run OCS.

apt-get install -y apache2 build-essential libapache2-mod-php libapache-dbi-perl libarchive-zip-perl libdbd-mysql-perl libdbi-perl libmojolicious-perl libswitch-perl libnet-ip-perl libplack-handler-anyevent-fcgi-perl libsoap-lite-perl libxml-simple-perl make mariadb-client mariadb-server php php-apcu php-bz2 php-cas php-curl php-curl php-gd php-iconv php-imagick php-imap php-intl php-json php-ldap php-mbstring php-memcache php-mysql php-pclzip php-pear php-pspell php-soap php-tidy php-xml php-xmlrpc php-xsl php-zip
cpan install XML::Entities
apt-get update && apt-get upgrade

Prerequisite: Command Details

Install OCS Inventory:

Next, install OCS so that certain OCS configuration files will be created and staged. We will configure OCS at a later point in the walkthrough.

wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/download/2.9/OCSNG_UNIX_SERVER-2.9.tar.gz
tar -xvf OCSNG_UNIX_SERVER-2.9.tar.gz
cd OCSNG_UNIX_SERVER-2.9/
sh setup.sh

OCS setup.sh output

Configure the MariaDB database:

After installing OCS, we will work on configuring the MariaDB database.

systemctl enable mariadb && systemctl start mariadb
mysql_secure_installation

Create a password for the MariaDB root account as the default is nothing, then for the remaining initial setup wizard accept the defaults using “Y“.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

After running through the MariaDB setup wizard, log into the MariaDB management interface.

mysql -u root -p

Prestage a database for OCS as well as assign it a dedicated service account with full permissions. This database & service account will be used later on when it comes to the OCS setup wizard.

The user account and password below are examples and should be adjusted to fit your needs accordingly.

create database ocsweb;
CREATE USER 'ocssa'@'localhost' IDENTIFIED BY 'Password12345';
GRANT ALL PRIVILEGES ON ocsweb. * TO 'ocssa'@'localhost' IDENTIFIED BY 'Password12345';
flush privileges;
exit;

Configure the MariaDB database: Command Details

Configure Apache Web Server:

After installing the prerequisites we will now work on configuring the HTTPd\Apache webserver.

Edit the PHP “php.ini” to better optimize certain settings for OCS.

# To edit in vim use: i
# To save and quit vim use: Esc + :wq!

vim /etc/php/7.4/apache2/php.ini

Look for the following lines and adjust the settings to better fit your needs. The values below are what I have found to be a good balance when running OCS for small to medium businesses.

post_max_size = 50M
upload_max_filesize = 50M
max_execution_time = 300
max_input_time = 300
memory_limit = 256M

Since we changed the default username and password for OCS we need to update OCS’s configuration files with the database’s service account username and password. (This is also where you would change the database name if you didn’t want to use OCSng’s default “ocsweb” database name.)

# To edit in vim use: i
# To save and quit vim use: Esc + :wq!  

vim /etc/apache2/conf-available/z-ocsinventory-server.conf
  # Name of database
  PerlSetEnv OCS_DB_NAME ocsweb
  PerlSetEnv OCS_DB_LOCAL ocsweb
  # User allowed to connect to database
  PerlSetEnv OCS_DB_USER ocssa
  # Password for user
  PerlSetVar OCS_DB_PWD Password12345

To have computers be able to communicate with the OCsng server, we will also need to adjust OCS’s API configuration file as well.

# To edit in vim use: i
# To save and quit vim use: Esc + :wq!  

vim /etc/apache2/conf-available/zz-ocsinventory-restapi.conf
  # Name of database
       $ENV{OCS_DB_LOCAL} = 'ocsweb';
  # User allowed to connect to database
       $ENV{OCS_DB_USER} = 'ocssa';
  # Password for user
       $ENV{OCS_DB_PWD} = 'Password12345';

Once OCS is installed, it generates Apache configuration files that will need to be enabled by creating alias.

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
chown -R www-data:www-data /var/lib/ocsinventory-reports
systemctl restart apache2 && systemctl enable apache2

Configure Apache Web Server: Command Details

Configure OCS:

After installing OCS, prestaging HTTPdApache, and MariaDB, we will now run through the setup wizard to finish setting up the OCS instance.

Browse out to the following: “http://IP-OF-SERVER/ocsreports“, and follow along with the setup wizard to complete the installation and setup of OCS.

Default OCS Login = admin,admin

Clean up:

Rename the “install.php” file in the “OCSReports” directory after the setup wizard is complete or OCS will warn you when you log in.

mv /usr/share/ocsinventory-reports/ocsreports/install.php /usr/share/ocsinventory-reports/ocsreports/install.php.bck

Thoughts?

Thank you for taking the time to read this article, I hope that it was helpful in some way to you. If you noticed anything wrong or have a better way of doing this please don’t hesitate to comment below or send me an email.

Thank you!

    Jim Gallott
    25 Jun 2021
    12:29pm

    Worked great, there was one typo in the mysql database creation: should be CREATE USER ‘ocssa’, not ‘oscsa’

    create database ocsweb;
    CREATE USER ‘oscsa’@’localhost’ IDENTIFIED BY ‘Password12345’;
    GRANT ALL PRIVILEGES ON ocsweb. * TO ‘ocssa’@’localhost’ IDENTIFIED BY ‘Password12345’;

      Celerium
      3 Jul 2021
      7:02am

      Hi Jim, thank you for pointing out this typo and the missing API config. I have updated the post with these changes.

        andy
        16 Feb 2022
        9:48am

        Hi Jim, whilst you change some reference to oscsa, you didn’t change them all (maybe do a find on this page)
        Tripped me up!

          Celerium
          16 Feb 2022
          10:04am

          Hi Andy, thanks for the feed back, sounds like I need to proofread some items across these articles. I’ll see about updating them this weekend.

        andy
        16 Feb 2022
        9:50am

        ok, so I’m one of those who was following the ‘Just Give me the Commands’ link. It’s in there!

      Celerium
      19 Feb 2022
      9:11am

      Hello everyone,

      I have updated the documented and corrected the mistakes. Thank you all for letting me know 🙂

    Jim Gallott
    28 Jun 2021
    8:51am

    To get computers to successfully connect to the server, I had to also modify database/user/password for mysql in /etc/apache2/conf-available/zz-ocsinventory-restapi.conf

    fernando liriano
    26 Aug 2021
    1:10pm

    felicidades muy buena guia de ocs . que Dios te Dendiga y te de mas inteligencia y salud.

    Ramy Asha
    19 Oct 2022
    12:33pm

    If anyone can help me out, no matter what I do, I keep getting the problem listed here below when installing the Windows Agent:

    XX.XXX.XXX:80 X.X.X.X – – [19/Oct/2022:21:32:12 +0300] “GET /ocsinventory/deploy/label HTTP/1.1” 404 4031 “-” “OCS-NG_WINDOWS_AGENT_v2.9.2.0”
    XX.XXX.XXX:80 X.X.X.X – – [19/Oct/2022:21:32:13 +0300] “POST /ocsinventory HTTP/1.1” 404 4031 “-” “OCS-NG_WINDOWS_AGENT_v2.9.2.0”

    And I can’t figure out why. I’ve gone through at least a dozen different articles on installing OCS inventory and I just don’t get it. Any help would be greatly appreciated.

    Srivathsa
    29 Jan 2023
    10:32pm

    Thank you very much for the instructions, was very helpful

Leave A Comment