Changes between Initial Version and Version 1 of PiwikServerInstall


Ignore:
Timestamp:
02/27/13 11:08:43 (4 years ago)
Author:
chris
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PiwikServerInstall

    v1 v1  
     1[[PageOutline(2-5, Table of Contents, floated)]] 
     2 
     3Notes moved from the PiwikServer page. 
     4 
     5== Archive == 
     6 
     7The following documentation is outdated. 
     8 
     9=== Quince Server === 
     10 
     11The live install at https://stats.transitionnetwork.org/ on the NewLiveServer, the install was done on ticket:160. 
     12 
     13==== Install ==== 
     14 
     15{{{ 
     16cd /web 
     17cd stats.transitionnetwork.org/ 
     18wget http://piwik.org/latest.zip 
     19unzip latest.zip 
     20cd piwik 
     21chown -R www-data:www-data tmp/ 
     22chown -R www-data:www-data config/ 
     23chown -R www-data:www-data themes/ 
     24}}} 
     25 
     26===== Apache ===== 
     27 
     28Create {{{stats.transitionnetwork.org.conf}}} in {{{cd /etc/apache2/sites-available/}}}: 
     29 
     30{{{ 
     31<VirtualHost *:80> 
     32  ServerName stats.transitionnetwork.org 
     33  ServerAlias stats.transitionnetwork.org.webarch.net 
     34  ServerSignature Off 
     35  UseCanonicalName On 
     36 
     37  ErrorLog /var/log/apache2/stats.transitionnetwork.org_error.log 
     38  ErrorLog /var/log/apache2/error.log 
     39  SetEnvIf Remote_Addr "127\.0\.0\.1" loopback 
     40  SetEnvIf Remote_Addr "kiwi\.transitionnetwork\.org" loopback 
     41  CustomLog /var/log/apache2/stats.transitionnetwork.org_access.log combined env=!loopback 
     42  CustomLog /var/log/apache2/access.log combined env=!loopback 
     43 
     44  Redirect / https://stats.transitionnetwork.org/ 
     45</VirtualHost> 
     46 
     47<VirtualHost *:443> 
     48  ServerName stats.transitionnetwork.org 
     49  ServerAlias stats.transitionnetwork.org.webarch.net 
     50  ServerSignature Off 
     51  UseCanonicalName On 
     52 
     53  LogLevel warn 
     54  ErrorLog /var/log/apache2/stats.transitionnetwork.org_ssl_error.log 
     55  ErrorLog /var/log/apache2/error.log 
     56  SetEnvIf Remote_Addr "127\.0\.0\.1" loopback 
     57  SetEnvIf Remote_Addr "kiwi\.transitionnetwork\.org" loopback 
     58  CustomLog /var/log/apache2/stats.transitionnetwork.org_ssl_access.log combined env=!loopback 
     59  CustomLog /var/log/apache2/access.log combined env=!loopback 
     60 
     61  SSLEngine on 
     62  SSLCipherSuite HIGH 
     63  SSLProtocol all -SSLv2 
     64  SSLCertificateFile      /etc/ssl/transitionnetwork.org/transitionnetwork.org.pem 
     65  SSLCertificateChainFile /etc/ssl/transitionnetwork.org/gandi.pem 
     66 
     67  DocumentRoot "/web/stats.transitionnetwork.org/piwik" 
     68  <Directory "/web/stats.transitionnetwork.org/piwik"> 
     69    DirectoryIndex index.php 
     70    Options -Indexes 
     71    AddType 'image/x-icon' .ico 
     72    AddHandler php5-script .php 
     73    AddType text/html .php 
     74    SSLOptions +StdEnvVars 
     75    AllowOverride None 
     76    order allow,deny 
     77    allow from all 
     78  </Directory> 
     79  <Directory "/web/stats.transitionnetwork.org/piwik/tmp"> 
     80    Options Indexes 
     81    RemoveHandler .php 
     82    AllowOverride None 
     83    order allow,deny 
     84    allow from all 
     85  </Directory> 
     86  <Location /config> 
     87    Order deny,allow 
     88    Deny from all 
     89    Allow from 127.0.0.1 
     90  </Location> 
     91 
     92  <FilesMatch "\.(cgi|shtml|phtml|php)$"> 
     93    SSLOptions +StdEnvVars 
     94  </FilesMatch> 
     95  <Directory /usr/lib/cgi-bin> 
     96    SSLOptions +StdEnvVars 
     97  </Directory> 
     98 
     99</VirtualHost> 
     100}}} 
     101 
     102Enable it and restart: 
     103 
     104{{{ 
     105/etc/apache2/sites-enabled 
     106ln -s ../sites-available/stats.transitionnetwork.org.conf 35-stats.transitionnetwork.org.conf 
     107apache2ctl configtest 
     108apache2ctl restart 
     109}}} 
     110 
     111===== MySQL ===== 
     112 
     113As MySQL root user: 
     114 
     115{{{ 
     116CREATE USER 'stats'@'localhost' IDENTIFIED BY '********'; 
     117GRANT USAGE ON * . * TO 'stats'@'localhost' IDENTIFIED BY '********' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; 
     118CREATE DATABASE IF NOT EXISTS `stats` ; 
     119GRANT ALL PRIVILEGES ON `stats` . * TO 'stats'@'localhost'; 
     120FLUSH PRIVILEGES; 
     121}}} 
     122 
     123===== Web Install ===== 
     124 
     125MySQL settings: 
     126 
     127 * database server: 127.0.0.1 
     128 * login: stats 
     129 * password: ******** 
     130 * database name: stats 
     131 * table prefix: (blank - we don't need one, the default is piwik_) 
     132 * adapter: PDO_MYSQL 
     133 
     134Super User settings: 
     135 
     136 * super user login: webproject 
     137 * password: ******** 
     138 * email: webproject (at) transitionnetwork.org 
     139 
     140Suggested JS code: 
     141 
     142{{{ 
     143<!-- Piwik --> 
     144<script type="text/javascript"> 
     145var pkBaseURL = (("https:" == document.location.protocol) ? "https://stats.transitionnetwork.org/" : "http://stats.transitionnetwork.org/"); 
     146document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); 
     147</script><script type="text/javascript"> 
     148try { 
     149var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); 
     150piwikTracker.trackPageView(); 
     151piwikTracker.enableLinkTracking(); 
     152} catch( err ) {} 
     153</script><noscript><p><img src="http://stats.transitionnetwork.org/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript> 
     154<!-- End Piwik Tracking Code --> 
     155}}} 
     156 
     157Suggested image code: 
     158 
     159{{{ 
     160<!-- Piwik Image Tracker --> 
     161<img src="https://stats.transitionnetwork.org/piwik.php?idsite=1&rec=1" style="border:0" alt="" /> 
     162<!-- End Piwik --> 
     163}}} 
     164 
     165===== Configure ===== 
     166 
     167In the General Settings page: 
     168 
     169 * Allow Piwik archiving to trigger when reports are viewed from the browser: no 
     170 * Reports for today (or any other Date Range including today) will be processed at most every: 1800 
     171 
     172Set up cron: 
     173 
     174{{{ 
     175crontab -u www-data -e 
     176 
     1775 * * * * /web/stats.transitionnetwork.org/piwik/misc/cron/archive.sh > /dev/null 
     178}}} 
     179 
     180Test it: 
     181 
     182{{{ 
     183su www-data -c "sh /web/stats.transitionnetwork.org/piwik/misc/cron/archive.sh" 
     184}}} 
     185 
     186This generated this error: 
     187 
     188{{{ 
     189ALERT - script tried to increase memory_limit to 134217728 bytes which is above the allowed value (attacker 'REMOTE_ADDR not set', file '/web/stats.transitionnetwork.org/piwik/core/Piwik.php', line 947) 
     190}}} 
     191 
     192Which can be ignored because in {{{/etc/php5/apache2/php.ini}}} it's set to double that already, 256M, so I don't understand why it tried to raise it. 
     193 
     194Things added to {{{/web/stats.transitionnetwork.org/piwik/config/config.ini.php}}}, taken from {{{global.ini.php}}}: 
     195 
     196{{{ 
     197[General] 
     198force_ssl_login = 1 
     199feedback_email_address = "webproject (at) transitionnetwork.org" 
     200assume_secure_protocol = 1 
     201}}} 
     202 
     203===== GA Import ===== 
     204 
     205First install Python 2.6 from source: 
     206 
     207{{{ 
     208aptitude build-dep python2.5  
     209cd /usr/local/src 
     210wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz 
     211tar -zxvf Python-2.6.7.tgz 
     212cd Python-2.6.7 
     213./configure --with-threads --enable-shared 
     214make 
     215make install  
     216ln -s /usr/local/lib/libpython2.6.so* /usr/lib/ 
     217cd /usr/local/src 
     218wget 'http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e' 
     219tar zxvf setuptools-0.6c11.tar.gz 
     220cd setuptools-0.6c11 
     221python setup.py install 
     222cd /usr/local/src 
     223wget "https://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz" --no-check-certificate 
     224tar -zxvf gdata-2.0.14.tar.gz 
     225cd gdata-2.0.14 
     226python setup.py install 
     227cd /usr/local/src 
     228aptitude purge python-mysqldb 
     229wget "http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz" 
     230tar -zxvf MySQL-python-1.2.3.tar.gz  
     231cd MySQL-python-1.2.3 
     232vim site.cfg 
     233 mysql_config = /usr/bin/mysql_config 
     234aptitude install libmysqlclient-dev 
     235python setup.py build 
     236python setup.py install 
     237}}} 
     238 
     239Then the GA code and import: 
     240 
     241{{{ 
     242cd /web/stats.transitionnetwork.org/ 
     243wget http://clearcode.cc/google2piwik-1.2.5.tgz 
     244tar -zxvf google2piwik-1.2.5.tgz 
     245cd google2piwik-1.2.5 
     246cp google2piwik.conf.sample google2piwik.conf 
     247}}} 
     248 
     249Edit {{{google2piwik.conf}}}:  
     250 
     251{{{ 
     252 
     253## Google Account Credentials 
     254# If you don't know your site table_id type: 
     255#                       ./google2piwik.py -p 
     256[google] 
     257user_login = transitiontownsnetwork [at] gmail.com 
     258user_pass  = XXX 
     259table_id   = ga:XXX 
     260 
     261# MySQL Piwik Database configuration 
     262[mysql] 
     263db = stats 
     264host = localhost 
     265port = 3306 
     266user = stats 
     267passwd = XXX 
     268table_prefix = 
     269 
     270# Set export date range 
     271[export] 
     272start = 2008-01-01 
     273end   = 2011-06-29 
     274 
     275## Piwik configuration of site. 
     276# For default Piwik installation with one website, site_id should be set to 1 
     277[piwik] 
     278site_id  = 1 
     279site_url = http://transitionnetwork.org 
     280}}} 
     281 
     282Test and backup db: 
     283 
     284{{{ 
     285./google2piwik.py -p 
     286./google2piwik.py -c 
     287mysql_backup 
     288}}} 
     289 
     290Then change the timezone to UTC for the site on https://stats.transitionnetwork.org/ run it in screen: 
     291 
     292{{{ 
     293screen 
     294./google2piwik.py --verbose=2 
     295}}} 
     296 
     297=== Kiwi Server === 
     298 
     299The [http://piwik.org/ Piwik] server that is to be installed on the DevelopmentServer, the install was done on ticket:160 
     300 
     301==== Config ==== 
     302 
     303In {{{/web/piwik.transitionnetwork.org/piwik/config}}} 
     304 
     305{{{ 
     306assume_secure_protocol = 1 
     307}}} 
     308 
     309==== Install ==== 
     310 
     311Site:  https://piwik.transitionnetwork.org/ 
     312 
     313===== Download ===== 
     314 
     315{{{ 
     316cd /web/ 
     317mkdir piwik.transitionnetwork.org 
     318cd piwik.transitionnetwork.org/ 
     319wget http://piwik.org/latest.zip 
     320unzip latest.zip 
     321}}} 
     322 
     323===== Apache ===== 
     324 
     325Then set up apache, see /etc/apache2/sites-available/piwik.transitionnetwork.org and run the web installer and: 
     326 
     327{{{ 
     328cd /web/piwik.transitionnetwork.org/piwik/ 
     329chown -R www-data:www-data tmp/ 
     330chown -R www-data:www-data config/ 
     331}}} 
     332 
     333===== MySQL ===== 
     334 
     335Then a MySQL user and database was added using phpMyAdmin which ran the following SQL: 
     336 
     337{{{ 
     338CREATE USER 'piwik'@'localhost' IDENTIFIED BY '********'; 
     339GRANT USAGE ON * . * TO 'piwik'@'localhost' IDENTIFIED BY '********' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; 
     340CREATE DATABASE IF NOT EXISTS `piwik` ; 
     341GRANT ALL PRIVILEGES ON `piwik` . * TO 'piwik'@'localhost'; 
     342}}} 
     343 
     344===== Tracking code ===== 
     345 
     346The installer suggested this JS tracking code, see the docs at http://piwik.org/docs/javascript-tracking/ : 
     347 
     348{{{ 
     349<!-- Piwik --> 
     350<script type="text/javascript"> 
     351var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.transitionnetwork.org.webarch.net/" : "http://piwik.transitionnetwork.org.webarch.net/"); 
     352document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); 
     353</script><script type="text/javascript"> 
     354try { 
     355var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); 
     356piwikTracker.trackPageView(); 
     357piwikTracker.enableLinkTracking(); 
     358} catch( err ) {} 
     359</script><noscript><p><img src="http://piwik.transitionnetwork.org.webarch.net/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript> 
     360<!-- End Piwik Tracking Code --> 
     361}}} 
     362 
     363And this image tracking code: 
     364 
     365{{{ 
     366<!-- Piwik Image Tracker --> 
     367<img src="https://piwik.transitionnetwork.org.webarch.net/piwik.php?idsite=1&rec=1" style="border:0" alt="" /> 
     368<!-- End Piwik --> 
     369}}} 
     370 
     371The following parameters can also be passed to the image URL: 
     372 
     373 *   rec - (required) The parameter &rec=1 is required to force the request to be recorded 
     374 *   idsite - (required) Defines the Website ID being tracked 
     375 *   action_name - Defines the custom Page Title for this page view 
     376 *   idgoal - The request will trigger the given Goal 
     377 *   urlref - The Referrer URL: must be set to the referrer URL used before landing on the page containing the Image tracker. For example, in PHP this value is accessible via 
     378    {{{$_SERVER['HTTP_REFERER']}}} 
     379 *   revenue - Used with idgoal, defines the custom revenue for this conversion 
     380 
     381===== Logo ===== 
     382 
     383Customise the logo: 
     384 
     385{{{ 
     386cd /web/piwik.transitionnetwork.org/piwik 
     387chown -R www-data:www-data themes/ 
     388}}} 
     389 
     390===== Cron ===== 
     391 
     392Set up the [http://piwik.org/docs/setup-auto-archiving/#toc-linuxunix-how-to-setup-a-crontab-to-automatically-archive-the-reports crontab to automatically archive the reports]: 
     393 
     394{{{ 
     395crontab -u www-data -e 
     396 
     3975 * * * * /web/piwik.transitionnetwork.org/piwik/misc/cron/archive.sh > /dev/null 
     398}}} 
     399 
     400===== Python ===== 
     401 
     402For the Google Analytics data import we need Python 2.6 and we are running with Python 2.5.2, so [http://evan.borgstrom.ca/post/845359613/python-2-6-on-debian-lenny-5-0 following this] a source compile was done on the dev server: 
     403 
     404{{{ 
     405aptitude build-dep python2.5  
     406cd /usr/local/src 
     407wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz 
     408tar -zxvf Python-2.6.7.tgz 
     409cd Python-2.6.7 
     410./configure --with-threads --enable-shared 
     411make 
     412make install  
     413ln -s /usr/local/lib/libpython2.6.so* /usr/lib/ 
     414cd /usr/local/src 
     415wget 'http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e' 
     416tar zxvf setuptools-0.6c11.tar.gz 
     417cd setuptools-0.6c11 
     418python setup.py install 
     419cd /usr/local/src 
     420wget "https://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz" --no-check-certificate 
     421tar -zxvf gdata-2.0.14.tar.gz 
     422cd gdata-2.0.14 
     423python setup.py install 
     424aptitude purge python-mysqldb 
     425wget "http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz" 
     426tar -zxvf MySQL-python-1.2.3.tar.gz  
     427cd MySQL-python-1.2.3 
     428vim site.cfg 
     429 mysql_config = /usr/bin/mysql_config 
     430aptitude install libmysqlclient-dev 
     431python setup.py build 
     432python setup.py install 
     433}}} 
     434 
     435===== GA Import ===== 
     436 
     437See python notes above and [http://clearcode.cc/offer/open-source-projects/google2piwik/ Google2Piwik]. 
     438 
     439{{{ 
     440cd /web/piwik.transitionnetwork.org/ 
     441wget http://clearcode.cc/google2piwik-1.2.5.tgz 
     442tar -zxvf google2piwik-1.2.5.tgz 
     443cd google2piwik-1.2.5 
     444cp google2piwik.conf.sample google2piwik.conf 
     445}}} 
     446 
     447Edit {{{google2piwik.conf}}}: 
     448 
     449{{{ 
     450## Google Account Credentials 
     451# If you don't know your site table_id type: 
     452#                       ./google2piwik.py -p 
     453[google] 
     454user_login = XXX@gmail.com 
     455user_pass  = XXX 
     456table_id   = ga:XXX 
     457 
     458# MySQL Piwik Database configuration 
     459[mysql] 
     460db = piwik 
     461host = localhost 
     462port = 3306 
     463user = piwik 
     464passwd = XXX 
     465table_prefix =  
     466 
     467# Set export date range 
     468[export] 
     469start = 2011-05-01 
     470end   = 2011-06-29 
     471 
     472## Piwik configuration of site. 
     473# For default Piwik installation with one website, site_id should be set to 1 
     474[piwik] 
     475site_id  = 1 
     476site_url = http://www.transitionnetwork.org 
     477}}} 
     478 
     479Get the table_id and test and backup db: 
     480 
     481{{{ 
     482./google2piwik.py -p 
     483./google2piwik.py -c 
     484mysql_backup 
     485}}} 
     486 
     487Piwik, for the website you are importing data to, [https://piwik.transitionnetwork.org/index.php?module=SitesManager&action=index&idSite=1&period=day&date=yesterday change the timezone to UTC] and run the script: 
     488 
     489{{{ 
     490./google2piwik.py --verbose=2 
     491}}} 
     492 
     493 
     494=== Requirements === 
     495 
     496The [http://piwik.org/docs/requirements/ requirements are]: 
     497 
     498 * PHP version 5.1.3 or greater, We highly recommend using at least PHP 5.3 as it is much more memory efficient than previous PHP versions, we have: PHP 5.2.6-1+lenny10 with Suhosin-Patch 0.9.6.2 (cli), when the server is migrated to squeeze we will get a new php, it can wait till then. 
     499 * MySQL version 4.1 or greater, we have 5.0.51a-24+lenny5-log 
     500 * (enabled by default) PHP extension pdo and pdo_mysql, weh have these already installed and they are configured via /etc/php5/apache2/conf.d/pdo.ini and /etc/php5/apache2/conf.d/pdo_mysql.ini 
     501 * PHP GD extension, installed already 
     502 * Increase your PHP memory_limit value in your php.ini config file to be at least memory_limit = 128M, we have 256M already in /etc/php5/apache2/php.ini 
     503