Wednesday, 14 December 2016

Install LAMP Server (Apache, MariaDB, PHP) On CentOS/RHEL/Scientific Linux 7

LAMP is a combination of operating system and open-source software stack. The acronym of LAMP is derived from first letters of Linux, Apache HTTP Server, MySQL/MariaDB database, and PHP/Perl/Python.
In this tutorial, let us see how to setup LAMP server on RHEL/CentOS/Scientific Linux 7.
My testbox hostname and IP address are server.unixmen.local and 192.168.1.101/24 respectively.

Install Apache

Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI, SSL and virtual domains.
The following commands should be run with root user privileges.
To install Apache, enter the following command in your terminal:
yum install httpd -y
Start the Apache service and make it to start automatically on every reboot:
systemctl start httpd
systemctl enable httpd
If you’re behind firewall or router, allow Apache server through your firewall/router in case you want to access it from the remote systems. To do that, enter the following commands from your Terminal:
firewall-cmd --permanent --add-service=http
systemctl restart firewalld

Test Apache

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.
Apache HTTP Server Test Page powered by CentOS - Mozilla Firefox_001

Install MariaDB

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.
Now, start installing MariaDB as shown below:
yum install mariadb-server mariadb -y
Start MariaDB service and let it to start automatically on every reboot:
systemctl start mariadb
systemctl enable mariadb

Set MySQL root password

By default, MySQL root password is empty. So, to prevent unauthorized access to MySQL, let us set root user password. Enter the following command to setup mysql root user password:
mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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 ## Enter Y and press Enter
New password:   ## Enter new password
Re-enter new password:  ## Enter password again
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  ## Enter Y and press Enter
 ... 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  ## Enter Y and press Enter
 ... 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  ## Enter Y and press Enter
 - 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  ## Enter Y and press Enter
 ... 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!

Install PHP

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.
Install PHP with following command:
yum install php php-mysql php-gd php-pear -y

Test PHP:

Create a sample “testphp.php” file in Apache document root folder and append the lines as shown below:
vi /var/www/html/testphp.php
Add the following lines.
<?php 
phpinfo(); 
?>
Restart httpd service:
systemctl restart httpd
Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.
phpinfo() - Mozilla Firefox_002
If you want to install all php modules, enter the command yum install php* -y and restart the httpd service. To verify for the modules, open web browser and navigate to http://server-ip-address/testphp.php. You will then see all php modules.

Install phpMyAdmin (Optional)

phpMyAdmin is a free open-source web interface tool used to manage your MySQL databases. By default phpMyAdmin will not be not found in CentOS/RHEL/Scientific Linux official repositories. So let us install it from EPEL repository.
To add EPEL repository, just follow the link.
Now, install phpMyAdmin:
yum install phpmyadmin -y

Configure phpMyAdmin

By default, phpMyAdmin can only be accessed from the localhost itself. To make it to accessible globally, do the following steps.
Edit the phpmyadmin.conf file:
vi /etc/httpd/conf.d/phpMyAdmin.conf
Find and comment the whole /<Directory> section and add the lines as shown below:
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

## Comment the following Section ##

#<Directory /usr/share/phpMyAdmin/>
#   <IfModule mod_authz_core.c>
#     # Apache 2.4
#     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
#     </RequireAny>
#   </IfModule>
#   <IfModule !mod_authz_core.c>
#     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from 127.0.0.1
#     Allow from ::1
#   </IfModule>
#</Directory>

## Add the following lines:

<Directory /usr/share/phpMyAdmin/>
        Options none
        AllowOverride Limit
        Require all granted
</Directory>
[...]
Edit “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:
vi /etc/phpMyAdmin/config.inc.php 
Change ‘cookie’ to ‘http’.
[...] 
/* Authentication type */
$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?
[...]
Restart the Apache service:
systemctl restart httpd
Now you can access the phpmyadmin console by navigating to the URL http://server-ip-address/phpmyadmin/ from your browser.
Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “centos”.
New Tab - Mozilla Firefox_003
You will be redirected to PhpMyAdmin main web interface.
192.168.1.101 - localhost | phpMyAdmin 4.2.7 - Mozilla Firefox_004
Now you will able to manage your MariaDB databases from phpMyAdmin web interface.
That’s it. Your LAMP server is up and ready to use.

Monday, 28 November 2016

How to Setup OpenGTS GPS Tracking System on Ubuntu / CentOS

 

Hello everybody, today we are going to show you the installation and configuration steps to use OpenGTS that is well known as Open GPS Tracking System. OpenGTS is the only open source and web based GPS tracking system which is being widely used in different countries for tracking their different devices. OpenGTS can be operated in any specific GPS tracking device or the protocol that supports it like OpenDMTP (Open Source Device Monitoring and Tracking Protocol). It has a number of features like the customization of its web pages, reports and mapping services.
OpenGTS is fully written in Java and should run fine on any system that fully supports private JVM environment and an SQL database server (like MySQL).

Prerequisites

In this article we will be installing the Open GPS Tracking System on Ubuntu / CentOS. we are using the Ubuntu server 14.04 in our test environment. There are number of its prerequisites that we will have to setup first before the OpenGTS installation.

1) System Update

Login to your ubuntu / centos server using the root or sudo credentials to update your system using the below commands receptively.

# apt-get update
# yum update

2) LAMP Setup

As we mentioned earlier that OpenGTS is a web based application, that's why we will setup the LAMP stack as a prerequisite of OpenGTS. We will be using the Apache Web server and MySQL data base in our LAMP stack. Let's run the below commands to install the required packages.

For Ubuntu:
# sudo apt-get install apache2 php5 mysql-server libmysql-java wget curl unzip ant
For CentOS:
# yum install httpd php5 mysql-server libmysql-java wget curl unzip ant
In Ubuntu you will be asked to configure the root password on MySQL data base, choose your appropriate password and press OK to proceed.
While in CentOS you can run the below command to setup the root password.

# mysql_secure_installation
To start mysql and apache services on your ubuntu or centos server you can use the below commands.
For Ubuntu
# /etc/init.d/mysql start
# /etc/init.d/apache2 start
For CentOS
# /etc/init.d/mysqld start
# /etc/init.d/httpd start

3) JAVA Setup

To setup the JAVA environment we will be using the JAVA OpenJDK version 7 and then configure its environment using the below commands.
For Ubuntu / centOS:
# apt-get install openjdk-7-jdk
When the installation is complete setup the JAVA_HOME environment variables using the below commands.
# export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
# echo "export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64" >> ~/.bashrc

4) Tomcat Setup (This won't work with tomcat 8)

To install and configure the Tomcat setup follow the link to Download Tomcat, then copy the linked URL and download it using the wget command on the server.
# wget -c http://apache.mirror.uber.com.au/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.65.zip
Tomcat download
Run the command below to extract the above downloaded zipped package.
# unzip apache-tomcat-7.0.65.zip

Now copy the package into the '/usr/local/' directory from teh current directory.
root@open-gts:~# cp -a apache-tomcat-7.0.65 /usr/local/
By using the below commands we will setup the CATALINA_HOME environment for the tomcat.
# export CATALINA_HOME=/usr/local/apache-tomcat-7.0.65/
# cd /usr/local

# ln -s $CATALINA_HOME tomcat
# cd $CATALINA_HOME/bin
# chmod a+x *.sh
Catalina Env
When the Catalina Home environment has been setup, run the command as shown below to start tomcat.
# $CATALINA_HOME/bin/startup.sh

# echo "export CATALINA_HOME=/usr/local/apache-tomcat-7.0.65" >> ~/.bashrc
Stating Tomcat

5) Setup JAVA Connector

To setup the JAVA connector, there's as mysql java connector package is available that we we download from the this LINK
Download the connector package using the below wget command.
# wget -c http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.37.zip

Then extract the zipped package and copy its files into the 'ext' directory of the JAVA_HOME by using below commands.
# unzip mysql-connector-java-5.1.37.zip
# cd mysql-connector-java-5.1.37/
# cp mysql-connector-java-5.1.37-bin.jar $JAVA_HOME/jre/lib/ext

JAVA Mail Setup

To install the Java mail setup, we can download the latest Jar repository from this LINK
Copy the link address and download it using the below wget command in the command line interface.
# wget -c https://maven.java.net/content/repositories/releases/com/sun/mail/javax.mail/1.5.2/javax.mail-1.5.2.jar

Java Mail
Copy this Jar repository in to the '/ext/' directoy and then change its name using the commands as shown below.
# cp javax.mail-1.5.2.jar $JAVA_HOME/jre/lib/ext/
# mv $JAVA_HOME/jre/lib/ext/javax.mail-1.5.2.jar $JAVA_HOME/jre/lib/ext/javax.mail.jar

Installing OpenGTS

We are ready to go with installation of OpenGTS Tracking System. We will be using the curl command to get the latest available package of OpenGTS from this LINK by using the below command.
# curl -L http://sourceforge.net/projects/opengts/files/server-base/2.6.0/OpenGTS_2.6.0.zip > OpenGTS_2.6.0.zip
download OpenGTS
Then extract the OpenGTS package into the '/usr/local/' directory using below command.
# unzip OpenGTS_2.6.0.zip -d /usr/local

Its recommended to run the OpenGTS with a general user, for this purpose we will run the below command to change the ownership.
# chown -R gts:sudo /usr/local/OpenGTS_2.6.0/
Then export the environment variables to set the OpenGTS home environment.
# export GTS_HOME=/usr/local/OpenGTS_2.6.0/
# echo "export GTS_HOME=/usr/local/OpenGTS_2.6.0" >> ~/.bashrc

1) Setup Environment

To setup the environment variables with ANT and creating the symbolinks, run the following commands.
# echo "export ANT_HOME=/usr/share/ant" >> ~/.bashrc
# source ~/.bashrc
# ln -s $JAVA_HOME /usr/local/java
# ln -s $CATALINA_HOME /usr/local/tomcat
# ln -s $GTS_HOME /usr/local/gts

2) OpenGTS Configurations

Open the default configuration file of OpenGTS to configure some of its basic parameters. To so do use the following command and uncomment the below mentioned line in the configuration file.
# vim $GTS_HOME/config.conf

OpenGTS Conf
Save the configuration file changes, and then list the CATALINA_HOME folder to check if it linked to its folder or not.
# ls -l $CATALINA_HOME

Catalina Home Link
In case if its pointing to itself then you can run the command below unlink it.
# unlink /usr/local/apache-tomcat-7.0.65/apache-tomcat-7.0.65

3) OpenGTS Compilation

Finally we are ready to compile the OpenGTS, to do first change you directory to the GTS-HOME and the run the command to compile it with 'ant all' command as shown.
# cd $GTS_HOME
root@open-gts:/usr/local/OpenGTS_2.6.0# ant all
The compilation process will takes a while to compile all the required data.




OpenGTS Compilation


4) OpenGTS Initialization

To initialize the OpenGTS database , we will be using the below command to by providing the root credetials of our database.
root@open-gts:/usr/local/OpenGTS_2.6.0# bin/initdb.sh -rootUser=root -rootPass=******

This be creating the new database with name and user 'gts' and grant him the privileges as shown below.
Version: 2.6.0
Database created: gts
Privileges granted to user: gts
Validating table columns ...
---------------------------------------------------------------------------
Table 'Account' --- Creating table ...
Table 'AccountString' --- Creating table ...
Table 'User' --- Creating table ...
Table 'UserAcl' --- Creating table ...
Table 'GroupList' --- Creating table ...
Table 'Device' --- Creating table ...
Table 'Transport' --- Creating table ...
Table 'UniqueXID' --- Creating table ...
Table 'DeviceGroup' --- Creating table ...
Table 'DeviceList' --- Creating table ...
Table 'Driver' --- Creating table ...
Table 'EventData' --- Creating table ...
Table 'Geozone' --- Creating table ...
Table 'Resource' --- Creating table ...
Table 'Role' --- Creating table ...
Table 'RoleAcl' --- Creating table ...

Table 'StatusCode' --- Creating table ...
Table 'SystemProps' --- Creating table ...
Table 'EventTemplate' --- Creating table ...
Table 'PendingPacket' --- Creating table ...
Table 'Property' --- Creating table ...
Table 'Diagnostic' --- Creating table ...
---------------------------------------------------------------------------
Column validation completed successfully.
---------------------------------------------------------------------------
Updating GTS Version: 2.6.0
Updating DMTP Version: 1.3.6

5) Testing Installation

To test the installation of OpenGTS run the below command with the home directory of GTS_HOME as shown below.
root@open-gts:/usr/local/OpenGTS_2.6.0# bin/checkInstall.sh

after executing the above command you might see some errors, warnings and recommendation taht you you can figure them out.

6) Creating New Account

To create the new admin account run the below command by mentioning your account name and password.
root@open-gts:/usr/local/OpenGTS_2.6.0# bin/admin.sh Account -account=sysadmin -pass=****** -create
Entry Point: org.opengts.db.tables.Account
Created Account-ID: sysadmin

7) Install Track Java Servlet

To install the Track Java Servelet followed by copying its webapp, use the below commands.
root@open-gts:/usr/local/OpenGTS_2.6.0# ant track

root@open-gts:/usr/local/OpenGTS_2.6.0# cp build/track.war $CATALINA_HOME/webapps/


Track Java servlet



Open OpenGTS Web Interface

Open your web browser and give the below URL to access the web interface on OpenGTS GPS Tracking system to start tracking your devices.
http://your_servers_ip:8080/track/Track
OpenGTS Web



In case if you unable to login using your credentials, then stop the Tomcat services and then restart it again using below commands.
#$CATALINA_HOME/bin/shutdown.sh
#rm -rf $CATALINA_HOME/webapps/track*
#cp $GTS_HOME/build/track.war $CATALINA_HOME/webapps/
#$CATALINA_HOME/bin/startup.sh

Welcome to OpenGTS GPS Tracking

We have successfully setup OpenGTS, by using its web console now you can easily manage and track vehicles.





OpenGTS Server Admin

Conclusion

In this article you have learned the installation and configuration of OpenGTS Open GPS Tricking system including all of its required dependencies on Ubuntu. Hope you under each and every stept that we performed in the article. This was only the server side setup, in our next article we will show you its client side setup for OpenGTS Testing. Leave your valuable comments or suggestions if you face any issue or your recommendations.