Install Open Web Analytics on CentOS 7 Server with Nginx, MariaDB, PHP
Open Web Analytics, aka OWA, is a free and open source alternative to Google Analytics. It’s written in PHP and uses MySQL/MariaDB database. In this tutorial, I’m going to show you how to install OWA web analytics tool on a CentOS 7 server with Nginx, MariaDB and PHP.
This tutorial assumes that you have already configured a LEMP stack on CentOS 7. If you haven’t already done so, please check out the below easy to follow guide.
When you are finished setting up LEMP stack, come back here and read on.
Benefits of Open Web Analytics over Google Analytics
- OWA is free and open source.
- You own your site’s data and no third-party can take a peek on your visitors. This also increase visitor trust if you tell them about this.
- OWA heat map can track where and what elements your visitors click on your site.
Step 1: Install Open Web Analytics on CentOS 7 Server
First log into your server via SSH and update your system.
sudo yum update
Then download the Open Web Analytics zip archive onto your server with the following command. The latest version is 1.6.0 at the time of writing. You may need to change the version number. Go to Github OWA project page to check out the latest version.
wget https://github.com/padams/Open-Web-Analytics/archive/1.6.0.zip
Extract it.
sudo yum install unzip unzip 1.6.0.zip
A new directory named Open-Web-Analytics-1.6.0 will be created in the current working directory. Move this directory and all of its content to the web root of Nginx.
sudo mv Open-Web-Analytics-1.6.0/ /usr/share/nginx/html/owa/
Then you also need to make nginx
as the owner of this directory so later on Open Web Analytics can write to this directory.
sudo chown nginx:nginx /usr/share/nginx/html/owa/ -R
Step 2: Create a Database and User in MariaDB
Log into MariaDB database server with the following command:
mysql -u root -p
Then create a database for Open Web Analytics. This tutorial name the database owa
. You can use whatever name you like.
create database owa;
Create the database user. Again, you can use your preferred username. Replace your-password with your preferred password.
create user owauser@localhost identified by 'your-password';
Grant all privileges on the owa database to the user.
grant all privileges on owa.* to owauser@localhost identified by 'your-password';
Flush privileges table and exit.
flush privileges; exit;
Step 3: Create a Nginx Server Configuration File for OWA
We will create a owa.conf
file in /etc/nginx/conf.d/
directory.
sudo nano /etc/nginx/conf.d/owa.conf
Copy and paste the following lines in the file. Replace the red text with your actual domain name. You also need to point your domain name to the IP address of your CentOS server in DNS.
server {
listen 80;
server_name analytics.your-domain.com;
root /usr/share/nginx/html/owa;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ /.well-known {
allow all;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save and close the file. Then test Nginx configuration.
sudo nginx -t
If the test if successful, reload Nginx.
sudo systemctl reload nginx
Step 4: Finish the Installation in your Web Browser
Now in your web browser, type your domain name. For instance
analytics.your-domain.com
or
analytics.your-domain.com/install.php
Click Let’s get started button.
If you see access denied error, that’s because PHP-FPM process has been denied access to web files by SELinux. To fix this problem, run the following 3 commands:
sudo setsebool -P httpd_can_network_connect_db 1 sudo setsebool -P httpd_can_network_connect 1 sudo restorecon -R -v /usr/share/nginx/html/owa
In the next window, enter you URL. Select MySQL as the database type, enter localhost
in the Database Host filed. Then enter your database name, user and password and click Continue.
If this step failed, we can manually created the configuration file by running the below command:
cd /usr/share/nginx/html/owa/ sudo cp owa-config-dist.php owa-config.php
Then open the config file and edit it.
sudo nano owa-config.php
Enter database info and URL. Note that if later on you install a TLS/SSL certificate for your OWA installation, you need to change URL scheme from http
to https
.
define('OWA_DB_TYPE', 'mysql'); // options: mysql define('OWA_DB_NAME', 'owa'); // name of the database define('OWA_DB_HOST', 'localhost'); // host name of the server housing the database define('OWA_DB_USER', 'owauser'); // database user define('OWA_DB_PASSWORD', 'your-password'); // database user's password define('OWA_PUBLIC_URL', 'http://analytics.your-domain.com/');
Save and close the file. Back in your browser, refresh your page and your will be taken to a page which ask you to enter the site you want to track and set up an admin password.
Now you can login. The user name is admin
.
You might see a blank page after you hit the Login button. In this case, just type your domain name for OWA in the address bar to access it.
Once you are logged in, you can copy the tracking code to your site and start tracking how many people visited your site, where they come from and how they use your website and other useful site statistics.
I hope this article helped you install Open Web Analytics on CentOS Server or VPS. As always, if you found this post useful, subscribe to our free newsletter or follow us on Google+, Twitteror like our Facebook page.