Installing Traccar v3.9 on Ubuntu 16.10 Server x84_x64 on Remote VPS via SSH

Amr Elsharqawi7 years ago

Installing Latest Traccar on Ubuntu 16.10 Server x84_x64 on Remote VPS via SSH

Login to your server using putty http://www.putty.org/

If it's the first time you login to your server change root password by:

# passwd

Then create a non root user and give him sudo permission.

# adduser user
# usermod -aG sudo user

Then switch to the new user.

# su - user

From here we will use sudo command.

If your server version is Ubuntu 16.04 let's upgrade it first by the following commands:

$ sudo apt update
$ sudo apt dist-upgrade

Next, you need to install update-manager-core package on your system, if it’s not installed.

$ sudo apt install update-manager-core

Next, edit /etc/update-manager/release-upgrades file

$ sudo nano /etc/update-manager/release-upgrades

And set the variable prompt as below:

Prompt=normal

Then

$ sudo do-release-upgrade -d

Then you can go by the on-screen directives to complete the upgrade process.

Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-34-generic x86_64)

Now let's install Java

$ sudo apt install default-jdk

Now let's install Apache

$ sudo apt install apache2

Set your vhosts in /etc/apache2/sites-available/ in my case and according my DNS configuration I will set 2 hosts wich is domain.com & www.domain.com

  1. configuration for vhost www.domain.com
    $ sudo nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>

    ServerName www.domain.com
    ServerAdmin admin@domain.com
    DocumentRoot /var/www/html


    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # below lines added by certbot when you choose force https option
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.domain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

</VirtualHost>

2. configuration for vhost domain.com

$ sudo nano /etc/apache2/sites-available/domain.conf

<VirtualHost *:80>
        ServerName domain.com
        ServerAdmin admin@domain.com
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    # below lines added by certbot when you choose force https option & I made little modification for my needs by adding www.
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =domain.com
        RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

Next, check for syntax errors by typing:

$ sudo apache2ctl configtest

All you should see is:

Syntax OK

You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser

You should see "It works!"

Now lets use Let’s Encrypt to enable HTTPS on your website.

$ sudo apt install python-certbot-apache

$ certbot --apache -d www.domain.com -d domain.com

Then you can go by the on-screen directives

Now let's install traccar

$ sudo apt install zip
$ wget https://github.com/tananaev/traccar/releases/download/v3.9/traccar-linux-3.9.zip
$ unzip traccar-linux-3.9.zip
$ sudo ./traccar.run
$ sudo /opt/traccar/bin/startDaemon.sh

Lest's test it by visiting domain.com:8082

Now lets redirect traccar port 8082 to http port 80

$ sudo a2enmod ssl
$ sudo a2enmod proxy_http
$ sudo a2enmod proxy_wstunnel
$ sudo service apache2 restart

Add the following lines to /etc/apache2/sites-available/domain-le-ssl.conf

    ProxyPass /api/socket ws://localhost:8082/api/socket
        ProxyPassReverse /api/socket ws://localhost:8082/api/socket
        ProxyPass / http://localhost:8082/
        ProxyPassReverse / http://localhost:8082/

It should look like this

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName domain.com
        ServerAdmin admin@domain.com
        DocumentRoot /var/www/html

        ProxyPass /api/socket ws://localhost:8082/api/socket
        ProxyPassReverse /api/socket ws://localhost:8082/api/socket
        ProxyPass / http://localhost:8082/
        ProxyPassReverse / http://localhost:8082/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/www.domain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/www.domain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Now test it by visiting domain.com
Traccar server should work

Now edit /etc/apache2/sites-available/000-default-le-ssl.conf

It should look like this

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName www.domain.com
        ServerAdmin admin@domain.com
        DocumentRoot /var/www/html

        ProxyPass /api/socket ws://localhost:8082/api/socket
        ProxyPassReverse /api/socket ws://localhost:8082/api/socket
        ProxyPass / http://localhost:8082/
        ProxyPassReverse / http://localhost:8082/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/www.domain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/www.domain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
</IfModule>

Now let's set up our firewall

$ sudo ufw status verbose

You should see

Status: inactive

$ sudo ufw allow ssh
$ sudo ufw allow http
$ sudo ufw allow https
$ sudo ufw enable

$ sudo ufw status verbose

Now you should see

Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22                         ALLOW IN    Anywhere
80                         ALLOW IN    Anywhere
443                        ALLOW IN    Anywhere
22 (v6)                    ALLOW IN    Anywhere (v6)
80 (v6)                    ALLOW IN    Anywhere (v6)
443 (v6)                   ALLOW IN    Anywhere (v6)

Now your server is up and running and secure too.

Good luck!!!

I found a bug in the traccar-web regarding the registration button in the login page, so I will try to build latest traccar from the source after success I will post it.

Amr Elsharqawi7 years ago

I will go for Command Line method, so we need Java and Maven

$ sudo apt install default-jdk
$ sudo apt install maven

$ git clone https://github.com/tananaev/traccar.git
$ cd traccar
$ git clone https://github.com/tananaev/traccar-web.git

$ mvn package


$ cd ..
$ wget http://cdn.sencha.com/ext/gpl/ext-6.2.0-gpl.zip

$ unzip ext-6.2.0-gpl.zip

$ wget http://cdn.sencha.com/cmd/6.2.1/no-jre/SenchaCmd-6.2.1-linux-amd64.sh.zip

$ unzip SenchaCmd-6.2.1-linux-amd64.sh.zip

$ sudo ./SenchaCmd-6.2.1.29-linux-amd64.sh -q -dir /bin


$ cd PATH to /traccar/traccar-web/tools

$ ./minify.sh

$ cd ../../setup

$ wget https://excellmedia.dl.sourceforge.net/project/yajsw/yajsw/yajsw-stable-12.08/yajsw-stable-12.08.zip
$ wget https://mlaan2.home.xs4all.nl/ispack/innosetup-5.5.9.exe
$ sudo apt install wine-stable
$ sudo apt install innoextract
$ sudo apt install makeself
$ sudo apt install dos2unix

$ ./package.sh v3.9-latest

Now you've got the packages

copy traccar-linux-v3.9-latest.zip to your convenient directory and unzip it, then upgrade the current v3.9 to v3.9-latest.

Upgrade process is very simple:

  1. Make backup of the database
  2. Save any changes in the config file (if applicable)
  3. Remove old version of Traccar
  4. Install new version of Traccar
  5. Update config file (if applicable)
  6. Start Traccar service

Since we didn't change configurations & we didn't add data to current version "Simply"

$ unzip traccar-linux-v3.9-latest.zip
$ sudo ./traccar.run
$ sudo /opt/traccar/bin/startDaemon.sh
Anton Tananaev7 years ago

Very detailed documentation, thanks. Added some formatting as well.

SpiderMax7 years ago

When i do the below stage

Add the following lines to /etc/apache2/sites-available/domain-le-ssl.conf
ProxyPass /api/socket ws://localhost:8082/api/socket
    ProxyPassReverse /api/socket ws://localhost:8082/api/socket
    ProxyPass / http://localhost:8082/
    ProxyPassReverse / http://localhost:8082/

i have a blank file and nothing to add it to, if i copy the part you have and change the domain to mine I still cant access the site via port 80, any advice

SpiderMax7 years ago

I have found that there seems to be a default file in /var/www/html called index.html the file says i should replace it but i dont know what with so for now i have put a http redirect to point my page at port 8082 but i dont like having that in the top address and still want to change it.

kyle7 years ago

Hi Amr

Thank you for the detailed installation guide, I have ran into a problem and hope maybe able to help me.
When I first installed traccar, I was able to view the site, however after make the said changes when I try to view the traccar webpage I get the apache2 Ubuntu default page. Please can you help me in resolving this error.

Many Thanks
Kyle

W Kruger6 years ago

Hi Everyone,

I have the same issue, I can view traccar with localhost:8082 but after doing the above detailed proxy or redirection, I only see the Apache home page and it doesn't seem to actually direct it to http://localhost:8082. I will have to do the html redirection same as SpiderMax, but is there any other way of making sure it bypasses the index.html file in the html folder?

SpiderMax6 years ago

You need to edit the config file and change the web.port setting to which ever port you want.

W Kruger6 years ago

Thanks SpiderMax, are you referring to the traccar.conf file? the config file is currently : (except obviously "mydomain.com" replaced with the actual url)

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName www.mydomain.com
        ServerAdmin admin@mydomain.com
        DocumentRoot /var/www/html

        ProxyPass /api/socket ws://localhost:8082/api/socket
        ProxyPassReverse /api/socket ws://localhost:8082/api/socket
        ProxyPass / http://localhost:8082/
        ProxyPassReverse / http://localhost:8082/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        SSLCertificateFile /etc/letsencrypt/live/www.domain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/www.domain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
rijotech6 years ago

Yep I'm kind of confused too, all I'm getting is the apache page.

rijotech6 years ago

Just edit the /etc/apache2/sites-available/000-default.conf with the ssl config.

Amr Elsharqawi5 years ago

I am sorry for late reply

You have to configure your vhosts properly and http proxy

After that use let's encrypt to use ssl

If you need it in detailed I can write it up

GaryLog5 years ago

hi, great guide! im also getting just the apache page, is there a way to use ip instead of domain in vhosts?

Macan5 years ago

Very good tutorial,but you didnt explain what about mysql database ?