Piwik on AWS EC2

1. Make a SSH connection

2. Setup a mySql 

mysql -u root -p
CREATE USER 'piwik-user'@'localhost' IDENTIFIED BY 'your_strong_password';
CREATE DATABASE `piwik-db`;
GRANT ALL PRIVILEGES ON `piwik-db`.* TO "piwik-user"@"localhost";
FLUSH PRIVILEGES;
exit

3. Prepare piwik

wget https://builds.piwik.org/piwik.zip
unzip piwik.zip
rm piwik.zip
rm How\ to\ install\ Piwik.html

cd piwik

4. Make a piwik folder

sudo mkdir /var/www/piwik
sudo mv * /var/www/piwik
cd ..
rm -r piwik

5. Fix file permissions

sudo chown -R apache:apache /var/www/piwik

6. Make the stat.w--w--w.com vhost

sudo vim /etc/httpd/conf.d/vhosts.conf

<VirtualHost *:80>
ServerName stat.w--w--w.com
Redirect permanent / https://stat.w--w--w.com
</VirtualHost>
<VirtualHost *:443>
ServerName stat.w--w--w.com
DocumentRoot /var/www/piwik
<IfModule security2_module>
SecRuleEngine Off
</IfModule>
<Directory /var/www/piwik>
AllowOverride All
</Directory>
</VirtualHost>

7. Restart httpd

sudo service httpd restart

8. Setup cron

sudo crontab -u apache -e

5 * * * * php -f /var/www/piwik/console core:archive --url=https://stat.w--w--w.com/

9. Exit ssh

exit