You are on page 1of 33

REX – RTM
Installation Guide

Proposed by
PRXSION Technologies Pvt. Ltd.
Installation Guide

Contents
1. Introduction ...............................................................................................3
Hardware Prerequisites .............................................................................................................3
Software Prerequisites ..............................................................................................................3
2. Installing Python ..........................................................................................4
Step 1: Install Python Dependencies .........................................................................................4
Step 2: Download Python 3.8 Archive .......................................................................................4
Step 3: Install Python3.8 ............................................................................................................5
Step 4: Verify Installation ...........................................................................................................6
3. Installing Apache Web Server ...........................................................................7
Step 1: Install Apache ................................................................................................................7
Step 2: Activate Apache .............................................................................................................7
Step 3: Verify Apache Service ................................................................................................... 7
Step 4: Checking your Web Server ...........................................................................................7
Step 5: Managing the Apache Process .....................................................................................9
4. Installing mod_wsgi .....................................................................................11
5. Installing PostgreSQL....................................................................................11
Step 1: Install PostgreSQL .......................................................................................................11
Step 2: Configure PostgreSQL ................................................................................................ 13
Step 3: Access the PostgreSQL Shell .....................................................................................13
Step 4: Create a Database ......................................................................................................14
Step 5: Connect to a Database ............................................................................................... 14
Step 6: Secure PostgreSQL ....................................................................................................14
6. Installing PHP ............................................................................................16
Step 1: Enable EPEL repository .............................................................................................. 16
Step 2: Install PHP .................................................................................................................. 17
Step 3: Verify Installation .........................................................................................................17
7. Installing Redis ...........................................................................................19
Step 1: Install Redis................................................................................................................. 19
Step 2: Securing Redis ............................................................................................................20
8. Setup REX-RTM ...........................................................................................21
Step 1: Setup Model Server ....................................................................................................21
Step 1.1: Installing Celery ........................................................................................................26
Step 1.2 Installing Flower ........................................................................................................26
Step 1.3: Setup Supervisor ......................................................................................................26

1
Installation Guide

Step 2: Setup Application Server .............................................................................................28


Step 3: Validating REX-RTM Setup .........................................................................................31
Contact Us ...................................................................................................32

2
Installation Guide

1. Introduction

Hardware Prerequisites

Software Prerequisites

Before we begin with the installation, let’s make sure to update the default system
applications to have the latest versions available.
Let’s first make sure that yum is up to date by running this command:

sudo yum -y update

The -y flag is used to alert the system that we are aware that we are making changes,
preventing the terminal from prompting us to confirm.

Next, we will install yum-utils, a collection of utilities and plugins that extend and
supplement yum:

sudo yum -y install yum-utils

Finally, we’ll install the CentOS Development Tools, which are used to allow you
to build and compile software from source code:

sudo yum -y groupinstall development

Install additional tools to proceed installation:

sudo yum -y install wget nano zip unzip firewalld

To start firewalld, run the following command as root:

systemctl start firewalld

To check the status of firewalld, run the following command as root:

systemctl status firewalld

3
Installation Guide

If your Firewall is active you should execute the following commands in order to allow
HTTP and HTTPS ports:
sudo firewall-cmd --zone=public —add-port=80/tcp
sudo firewall-cmd --zone=public —add-port=22/tcp
sudo firewall-cmd --zone=public —-add-port=443/tcp
sudo firewall-cmd --zone=public —-add-port=8080/tcp
sudo firewall-cmd --zone=public —-add-port=8181/tcp
sudo firewall-cmd --zone=public —-add-port=5432/tcp
sudo firewall-cmd --zone=public —-add-port=6379/tcp
sudo firewall-cmd --zone=public —-add-port=5555/tcp

We can verify that this was successful using the --list-ports operation:

sudo firewall-cmd --zone=public --list-ports

Expected output should be:

80/tcp 22/tcp 443/tcp 8080/tcp 8181/tcp 5432/tcp 6379/tcp

Create download folders to download and build:

mkdir /root/downloads

Once everything is installed, our setup is in place and we can go on to install


requirements.
2. Installing Python

Step 1: Install Python Dependencies


As we’ll install Python from source, let’s install the packages required for Python
installation:

sudo yum -y install openssl-devel bzip2-devel libffi-devel

Step 2: Download Python 3.8 Archive

4
Installation Guide

cd /root/downloads
wget https://www.python.org/ftp/python/3.8.3/
Python-3.8.3.tgz

Extract the package:

tar xvf Python-3.8.3.tgz

Change the directory:

cd Python-3.8*/

Step 3: Install Python3.8

Setup installation by running the configure script:


./configure —prefix=/usr/local —enable-optimizations —
enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

Add LD_LIBRARY_PATH to environment variable. This is important for successfully


compiling Python3.8:
#add following line to ~/.bashrc and save
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib

Enter following command to reload environment variables

source ~/.bashrc

Initiate compilation of Python 3.8:

sudo make altinstall

If this was successful, you should see a message like below:

5
Installation Guide

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0
[root@rex-uat-1 Python-3.8.3]#

Step 4: Verify Installation

In order to ensure that Python 3.8 is in fact installed and useable, we can check by
running the following command:

python3.8 —version

You should see “Python 3.8.3”

Pip is also installed. Check by running the following command:

pip3.8 —version

You should see “pip 19.2.3 from /usr/local/lib/python3.8/site-packages/pip (python


3.8)”

You may want to upgrade Pip to ensure you have the latest version:

pip3.8 install --upgrade pip

Upon successful upgrade you should see version >= 20.1.1

6
Installation Guide

3. Installing Apache Web Server

Step 1: Install Apache

To install Apache on your CentOS server, use the following command:

sudo yum install httpd httpd-devel

The system should download and install the Apache software packages.

Step 2: Activate Apache

To activate Apache, start its service first.


1. Enter the following command in a terminal window:

sudo systemctl start httpd

This will start the Apache service.

2. Next, set the Apache service to start when the system boots:

sudo systemctl enable httpd

Step 3: Verify Apache Service

Display information about Apache, and verify it’s currently running with:

sudo systemctl status httpd

Step 4: Checking your Web Server


Apache does not automatically start on CentOS once the installation completes. You will
need to start the Apache process manually:

7
Installation Guide

sudo systemctl start httpd

Verify that the service is running with the following command:

sudo systemctl status httpd

You will see an active status when the service is running:


httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service;
enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-07 16:32:48
IST; 4 days ago
As you can see from this output, the service appears to have started successfully.
However, the best way to test this is to request a page from Apache.

You can access the default Apache landing page to confirm that the software is running
properly through your IP address. If you do not know your server’s IP address, you can
get it a few different ways from the command line.
Type this at your server’s command prompt:

hostname -I

This command will display all of the host’s network addresses, so you will get back a
few IP addresses separated by spaces. You can try each in your web browser to see if
they work.

Type following IP command in terminal windows to view current IP addresses


configured on your system:

ip addr show

When you have your server’s IP address, enter it into your browser’s address bar:

8
Installation Guide

http://your_server_ip

You’ll see the default CentOS 7 Apache web page:

Step 5: Managing the Apache Process


Now that you have your web server up and running, let’s go over some basic
management commands.

To stop your web server, type:

sudo systemctl stop httpd

To start the web server when it is stopped, type:

sudo systemctl start httpd

To stop and then start the service again, type:

9
Installation Guide

sudo systemctl restart httpd

If you are simply making configuration changes, Apache can often reload without
dropping connections. To do this, use this command:

sudo systemctl reload httpd

By default, Apache is configured to start automatically when the server boots. If this is
not what you want, disable this behaviour by typing:

sudo systemctl disable httpd

To re-enable the service to start up at boot, type:

sudo systemctl enable httpd

Apache will now start automatically when the server boots again.
The default configuration for Apache will allow your server to host a single website. If
you plan on hosting multiple domains on your server, you will need to configure virtual
hosts on your Apache web server.

10
Installation Guide

4. Installing mod_wsgi

The following commands can be used to install the prerequisites:

pip3.8 install mod_wsgi

You can verify the installation by running the mod_wsgi-express command:

mod_wsgi-express module-config

You can use the output of this command to configure httpd.conf to load mod_wsgi
module

Add following line at the end of /etc/httpd/conf/httpd.conf:


LoadModule wsgi_module /usr/local/lib/python3.8/site-
packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-
linux-gnu.so

WSGISocketPrefix /var/run/wsgi
Save and exit the httpd.conf file

5. Installing PostgreSQL

Step 1: Install PostgreSQL

11
Installation Guide

Install the repository RPM:



rpm -Uvh https://yum.postgresql.org/11/redhat/rhel-7-
x86_64/pgdg-redhat-repo-latest.noarch.rpm

Install PostgreSQL:
yum install postgresql11-server postgresql11 -y
# instell
yum install postgresql11-contrib

Initialise your Postgres database and start PostgreSQL:


sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl start postgresql-11

Configure PostgreSQL to start on boot:

sudo systemctl enable postgresql-11

49 sudo dnf -y install https://download.postgresql.org/pub/


repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-
latest.noarch.rpm
50 rpm -qi pgdg-redhat-repo
51 sudo dnf module disable postgresql
52 sudo dnf clean all
53 sudo dnf -y install postgresql11-server postgresql11
54 dnf info postgresql11-server postgresql11
55 sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
56 sudo systemctl enable --now postgresql-11
57 sudo systemctl status postgresql-11
58 sudo su - postgres
59 clear
60 sudo passwd postgres

12
Installation Guide

Step 2: Configure PostgreSQL

By default, PostgreSQL will create a Linux user named postgres to access the
database software.

Change the postgres user’s Linux password:

sudo passwd postgres

Issue the following commands to set a password for the postgres database user. Be
sure to replace newpassword with a strong password and keep it in a secure place:

su - postgres


Note that this user is distinct from the postgres Linux user. The Linux user is used to
access the database, and the PostgreSQL user is used to perform administrative tasks
on the databases.

The password set in this step will be used to connect to the database via the network.
Peer authentication will be used by default for local connections.

Step 3: Access the PostgreSQL Shell


The PostgreSQL client shell allows you to issue SQL commands to administer your
databases. As the postgres Linux user, log in by running:

psql postgres

This will log you in as the postgres database user. You’ll see a prompt similar to this:
psql (11.8)
Type "help" for help.

postgres=#

13
Installation Guide

In the last line, postgres=# indicates the name of the current database. To see a list of
available commands, type \h. You may find more information on a specific command by
adding it after \h. Once you’ve finished using the shell, you can exit with \q.

Step 4: Create a Database


You can create databases with the createdb command. Create a sample database
called rex and by running this command as the postgres Linux user:

createdb rex -O postgres

Step 5: Connect to a Database


You can use the psql command to connect to a specific database.

Connect to the test database:


psql rex


You will see the following output:

psql (11.8)
Type "help" for help.

rex=#

Install uuid extension


create extension if not exists "uuid-ossp";

Type \q to exist postgres shell and then exit to exit su bash shell.

Step 6: Secure PostgreSQL

While PostgreSQL’s default peer authentication is useful in cases where a particular


system user will be running a local program (e.g., scripts, CGI/FastCGI processes
owned by separate users, etc.), you may wish to require passwords for greater security.
Commands in this section should be run as the postgres Linux user unless otherwise
specified.

14
Installation Guide

Edit the /var/lib/pgsql/11/data/pg_hba.conf file, under the # "local" is for Unix domain
socket connections only header:
# "local" is for Unix domain socket connections only
local all all peer
Replace peer with md5 on this line to activate password authentication using an MD5
hash.

To enable these changes, you need to restart PostgreSQL.

sudo systemctl restart postgresql-11

As postgres, connect to the rex database as the postgres PostgreSQL user:

psql rexapi -U postgres

You will be prompted to enter the password for the postgres user and then given psql
shell access to the database.

Type \q to exit psql shell

15
Installation Guide

6. Installing PHP

PHP 7.1 is not provided by the official RHEL repository so you have to add “Webtatic”
repo in order to install it easily.

Step 1: Enable EPEL repository


First, install EPEL repository with the following command:

yum install epel-release

Now you can add the Webtatic repo:


rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-
release.rpm

Update your repository list with the command below:

16
Installation Guide

yum repolist

Step 2: Install PHP


Proceed and install PHP 7.1 and associated PHP modules:
sudo yum install -y mod_php71w php71w-cli php71w-common
php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd
php71w-xml php71w-devel php71w-intl php71w-ldap php71w-
pear php71w-pecl-apcu php71w-pecl-igbinary php71w-pecl-
redis php71w-php-process php71w-xmlrpc
If you see error “Nothing to d”, clean yum cache by
yum clean all & yum clean metadata

Step 3: Verify Installation


To verify the installation, run the command:

php -v

Apache web Server is installed on your system as a dependency for PHP, start its
service using below systemctl command:

sudo systemctl start httpd

Now create a info.php file under /var/www/html, run the following command to create
the file’s contents:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Use the path noted above to load the module into Apache by adding the following
snippet to the bottom of the /etc/httpd/conf/httpd.conf:

LoadModule php7_module modules/libphp7.so

17
Installation Guide

Now test the syntax and restart Apache service:


httpd -t
sudo systemctl restart httpd

If libphp7.so is installed successfully, no error or warning should prompt. Any error


related to Apache or mod_wsgi can be checked in log /var/log/httpd/error_log.

Now you can open your browser and type in http://public_ip/info.php.


You should see a page like below:

18
Installation Guide

PHP 7.3.25
104 sudo dnf install dnf-utils http://rpms.remirepo.net/
enterprise/remi-release-8.rpm
105 sudo dnf module list php
106 sudo dnf module reset php
107 sudo dnf module enable php:remi-7.3
108 sudo dnf install php php-opcache php-gd php-curl php-
mysqlnd
109 sudo systemctl enable --now php-fpm
110 php -v

7. Installing Redis
Step 1: Install Redis
Install Redis using yum:

sudo yum install redis -y

This may take a few minutes to complete.

After the installation finishes, start the Redis service:

sudo systemctl start redis.service

19
Installation Guide

If you’d like Redis to start on boot, you can enable it with the enable command:

sudo systemctl enable redis

You can check Redis’s status by running the following:

sudo systemctl status redis.service

Once you’ve confirmed that Redis is indeed running, test the setup with this command:

redis-cli ping

This should print PONG as the response. If this is the case, it means you now have
Redis running on your server and we can begin configuring it to enhance its security.

Step 2: Securing Redis


An effective way to safeguard Redis is to secure the server it’s running on. You can do
this by ensuring that Redis is bound only to either localhost or to a private IP address
and that the server has a firewall up and running.

To remedy this, open the Redis configuration file for editing:

sudo nano /etc/redis.conf

Locate the line beginning with bind and make sure it’s uncommented:
# /etc/redis.conf
bind 127.0.0.1

If you need to bind Redis to another IP address (as in cases where you will be
accessing Redis from a separate host) we strongly encourage you to bind it to a
private IP address. Binding to a public IP address increases the exposure of your Redis
interface to outside parties.

Since a default standalone installation of Redis server is listening only on the loopback
interface (127.0.0.1 or localhost), there should be no concern for incoming traffic on its
default port.

20
Installation Guide

8. Setup REX-RTM

Step 1: Setup Model Server


(rexrtmapi)

Create a new directory under /var/www/


cd /var/www
mkdir rexrtmapi
cd rexrtmapi

Once you are in the directory where you would like the environments to live, you can
create an environment by running the following command:

python3.8 -m venv venv

Essentially, this command creates a new directory (in this case called venv)

21
Installation Guide

To use this environment, you need to activate it, which you can do by typing the
following command that calls the activate script in the bin directory:

source venv/bin/activate

Your prompt will now be prefixed with the name of your environment, in this case it is
called venv.

Look for activate_this.py in venv/bin/ folder. activate_this.py will be used in wsgi file
to activate the virtual environment. If you don’t find the file in the location, we need to
create one by copy-paste below content in a file called /venv/bin/activate_this.py:

22
Installation Guide

import os
import site
import sys

try:
abs_file = os.path.abspath(__file__)
except NameError:
raise AssertionError("You must use
exec(open(this_file).read(), {'__file__': this_file}))")

bin_dir = os.path.dirname(abs_file)
base = bin_dir[: -len("bin") - 1] # strip away the bin part
from the __file__, plus the path separator

# prepend bin to PATH (this file is inside the bin directory)


os.environ["PATH"] = os.pathsep.join([bin_dir] +
os.environ.get("PATH", "").split(os.pathsep))
os.environ["VIRTUAL_ENV"] = base # virtual env is right above
bin directory

# add the virtual environments libraries to the host python


import mechanism
prev_length = len(sys.path)
for lib in "../lib64/python3.8/site-packages:../lib/python3.8/
site-packages".split(os.pathsep):
path = os.path.realpath(os.path.join(bin_dir, lib))
site.addsitedir(path.decode("utf-8") if "" else path)
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]

sys.real_prefix = sys.prefix
sys.prefix = base

You might want to update pip3 utility to its latest version. Use below command to
upgrade pip3:

pip3 install --upgrade pip

Your virtual environment is now ready to use.

23
Installation Guide

To leave the environment, simply type the command deactivate and you’ll return to your
original directory.

Configure mod_wsgi

Now that mod_wsgi has been installed, let’s take a look at the configuration. We will be-
gin by creating a basic Python web application to detail the steps to configure mod_ws-
gi.

Next, enter this directory and activate the venv:


cd rexrtmapi
source venv/bin/activate
pip3 install flask
nano app.py

Place the following configuration inside of the rexrtmapi.wsgi file:


import os
import sys

activate_this ='/var/www/rexrtmapi/venv/bin/
activate_this.py'
exec(open(activate_this).read())

sys.stdout = sys.stderr

sys.path.insert(0, '/var/www/rexrtmapi/venv/lib/python3.8/
site-packages')
sys.path.insert(0, ‘/var/www/rexrtmapi/venv/lib64/
python3.8/site-packages')

sys.path.append('/var/www/rexrtmapi')
from rexrtmapi import create_app
application, socketio = create_app()

Setup rexrtmapi from Github:


Navigate to folder /var/www/rexrtmapi folder:

24
Installation Guide

cd /var/www/rexrtmapi
git clone https://github.com/sarabjeethanspal/rexrtmapi.git

chown -R root:apache rexrtmapi


chmod -R 770 rexrtmapi

Execute the following command one by one to set the proper permissions:
sudo chown -R apache:apache /var/www/rexrtmapi
sudo chmod -R 755 /var/www/rexrtmapi

Check if SELIinux is enabled. Use below command to disable it:

setenforce 0

Now that the example application has been created, let’s configure Apache.


We will begin by creating a virtual host for this application. This file will be placed inside

/etc/httpd/conf.d/

Write the file to the following path replacing domain.com with your domain:

/etc/httpd/conf.d/rexrtmapi.conf

The contents of the file will be as follows, replacing domain.com with your domain:
<VirtualHost *:8080>
ServerName 46.101.210.238:8080
WSGIDaemonProcess rexrtmapi user=apache group=apache
threads=5
WSGIScriptAlias / /var/www/rexrtmapi/rexrtmapi.wsgi
process-group=rexrtmapi application-group=%{GLOBAL}
WSGIPassAuthorization on
<Directory /var/www/rexrtmapi>
Require all granted
</Directory>
</VirtualHost>

25
Installation Guide

Now test and restart Apache:


httpd -t
service httpd restart

Step 1.1: Installing Celery


Celery is an asynchronous task queue/job queue based on distributed message
passing. It is focused on the real-time operation but supports scheduling as well.

On your Virtualenv, use pip3 command to install celery:

pip3 install celery

Step 1.2 Installing Flower

Step 1.3: Setup Supervisor

To install supervisor on CentOS 7, you need epel repository which can be added using
the commands. If you have already installed epel-release in previous section, please
ignore:

sudo yum -y install epel-release

Then do the installation of a supervisor from epel:

sudo yum -y install supervisor

The service can be managed using systemctl, the name is supervisord

Create Directory to store celery logs


/var/log/celery

Supervisor is configured to read all configuration files under /etc/supervisord.d 


directory. We will place our celery configuration file in
/etc/supervisord.d/celery.ini file. Content of the file should look like below:

26
Installation Guide

# cat /etc/supervisord.d/celery.ini
[program:celery]
command=/var/www/rexapi/venv/bin/celery -A
celery_worker.celery worker —loglevel=info
directory=/var/www/rexrtmapi
user=root
numprocs=1
stdout_logfile=/var/log/celery/celery.log
stderr_logfile=/var/log/celery/celery.log
autostart=true
autorestart=true
priority=999

Once all the changes have been made, start the supervisord daemon:

sudo systemctl start supervisord

If you check on its status, you should see the commands specified on our configuration
files executed:

sudo systemctl status supervisord

Supervisor also provides a command line tool called supervisorctl which allows you to
control the processes that are currently managed by supervisord:

supervisorctl status celery

To stop the process with supervisorctl, use:

supervisorctl stop celery

To restart, use:

supervisorctl restart celery

27
Installation Guide

To check if celery working is running:

ps axjf | grep celery

Step 2: Setup Application Server


(rexrtmapp)

For installing the latest version of Laravel we need to get the Composer dependency
manager:
cd /root/downloads
curl -sS https://getcomposer.org/installer | php

Execute the following command to move your Composer binary file to the executable
path:
mv /root/downloads/composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
Now you can run the command below to download and install Laravel directly into your
Apache document root:

composer create-project laravel/laravel /var/www/rexrtmapp

composer create-project --prefer-dist laravel/laravel rexsmsapp

To create a virtual host for rexrtmapp, create rexrtmapp.conf file in /etc/httpd/conf.d


folder:

sudo nano /etc/httpd/conf.d/rexrtmapp.conf

Add in the following configuration block:

28
Installation Guide

<VirtualHost *:8080>
ServerName rexrtmapp
DocumentRoot /var/www/rexrtmapp/public

<Directory /var/www/rexrtmapp/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /var/log/httpd/rexrtmapp-error_log
CustomLog /var/log/httpd/rexrtmapp-access_log combined
</VirtualHost>
Save and exit.

Open port 8080. Find “Listen 80” in /etc/httpd/conf/httpd.conf. Add following line
below “Listen 80”:

Listen 8080

Save and exit

Test the configuration file syntax with:

sudo apachectl configtest

If there are no errors you will see the following output:

Syntax OK

Execute the following command one by one to set the proper permissions:
sudo chown -R apache:apache /var/www/rexrtmapp
sudo chmod -R 755 /var/www/rexrtmapp/storage

Check if SELIinux is enabled. Use below command to disable it:

setenforce 0

29
Installation Guide

REX Config Details

1. config >> app.php


1. 'sitename' => env('SITE_NAME', 'REX'), change site title


2. 'rexurl' => env('SITE_URL', 'http://165.227.223.92/public/'), change url


2. app >> helpers.php


1. Change api url http://165.227.223.92:8080/api/


3.  app/Http/Controllers >> AdminController.php


1. $_SESSION["siteURLPath"] = "http://165.227.223.92/public/"; change url


2. $_SESSION["siteURL"] = "http://165.227.223.92/"; change url


4.  For change logo resources/libraries/rtx-logo.png


5.  For change Feature sample download csv file resources/views/feature-


creation/sample_file.csv 


6.  For change Action sample download csv file resources/views/actions/


sample_file.csv 


Restart Apache to take effect:

sudo systemctl restart httpd

30
Installation Guide

Step 3: Validating REX-RTM Setup

31
Installation Guide

Contact Us

info@prxsion.com
+91 99303 17670

Request more information or for any other reason we look forward to hearing from you
soon.

PRXSION Technologies Pvt. Ltd


www.prxsion.com

32

You might also like