/ HowTos

Installing Piwik on CentOS 7 (Apache, MariaDB, PHP 5.4)

[![Piwik](/content/images/2014/11/logo.svg)](http://piwik.org/)

Got bored today and decided to spin up a Piwik server. This is a rundown of the steps I took to install Piwik on a CentOS 7 server with SeLinux enabled.

Initial Steps

From Piwik Website

To run Piwik your host needs a couple of things:

  • Webserver such as Apache, Nginx, IIS, etc.
  • PHP version 5.3.3 or greater
  • MySQL version 4.1 or greater
  • (enabled by default) PHP extension pdo and pdo_mysql, or the mysqli extension.

Installing the needed packages.

yum install httpd php-pdo php-gd php-xml php-mysql php-mbstring php mariadb mariadb-server

Start and enable the services.

systemctl start mariadb httpd
systemctl enable mariadb httpd

Initialize MariaDB and set your MariaDB root user password. (I accepted the defaults all the way through)

mysql_secure_installation

Now we can create the Piwik related items in MariaDB.

mysql -u adminusername -p
MariaDB [(none)]> CREATE DATABASE piwik_db_name_here;

MariaDB [(none)]> CREATE USER 'piwik'@'localhost' IDENTIFIED BY 'password';

MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON piwik_db_name_here.* TO 'piwik'@'localhost';

MariaDB [(none)]> quit;

Getting Piwik

I chose to install this on a dedicated VM, so I'm going to throw it in the default httpd document root, as I don't plan to add any other web sites or services to this server.

cd /var/www/html
wget http://builds.piwik.org/piwik.zip
unzip piwik.zip
chown apache. *

(Optional Steps)

cd /var/www/html
mv piwik/* .
mv piwik/.bowerrc .
mv piwik/.coveralls.yml .

rmdir /var/www/html/piwik

Firewall

You will need to open ports 80 at the least and also port 443 if you plan to enable SSL.

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Piwik First time Setup

Head to the IP or DNS of your server in a browser and follow the steps from there. Should be self explanatory. You will probably hit some snags with write permissions and connecting to the database during these steps, which my next section will cover.

SeLinux Issues

SeLinux will probably step on you at some point in this process. It caused issues on my setup with write permissions for the apache user and allowing a connection to the database.

Here are the steps I took to let Piwik through SeLinux.

setsebool -P httpd_unified on
setsebool -P httpd_can_network_connect_db on

Profit

Hope this helps someone out there in this vast series of tubes will call the Interweb!!