| 1 | [[PageOutline(2-5, Table of Contents, floated)]] |
| 2 | |
| 3 | Notes moved from the PiwikServer page. |
| 4 | |
| 5 | == Archive == |
| 6 | |
| 7 | The following documentation is outdated. |
| 8 | |
| 9 | === Quince Server === |
| 10 | |
| 11 | The live install at https://stats.transitionnetwork.org/ on the NewLiveServer, the install was done on ticket:160. |
| 12 | |
| 13 | ==== Install ==== |
| 14 | |
| 15 | {{{ |
| 16 | cd /web |
| 17 | cd stats.transitionnetwork.org/ |
| 18 | wget http://piwik.org/latest.zip |
| 19 | unzip latest.zip |
| 20 | cd piwik |
| 21 | chown -R www-data:www-data tmp/ |
| 22 | chown -R www-data:www-data config/ |
| 23 | chown -R www-data:www-data themes/ |
| 24 | }}} |
| 25 | |
| 26 | ===== Apache ===== |
| 27 | |
| 28 | Create {{{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 | |
| 102 | Enable it and restart: |
| 103 | |
| 104 | {{{ |
| 105 | /etc/apache2/sites-enabled |
| 106 | ln -s ../sites-available/stats.transitionnetwork.org.conf 35-stats.transitionnetwork.org.conf |
| 107 | apache2ctl configtest |
| 108 | apache2ctl restart |
| 109 | }}} |
| 110 | |
| 111 | ===== MySQL ===== |
| 112 | |
| 113 | As MySQL root user: |
| 114 | |
| 115 | {{{ |
| 116 | CREATE USER 'stats'@'localhost' IDENTIFIED BY '********'; |
| 117 | GRANT 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 ; |
| 118 | CREATE DATABASE IF NOT EXISTS `stats` ; |
| 119 | GRANT ALL PRIVILEGES ON `stats` . * TO 'stats'@'localhost'; |
| 120 | FLUSH PRIVILEGES; |
| 121 | }}} |
| 122 | |
| 123 | ===== Web Install ===== |
| 124 | |
| 125 | MySQL 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 | |
| 134 | Super User settings: |
| 135 | |
| 136 | * super user login: webproject |
| 137 | * password: ******** |
| 138 | * email: webproject (at) transitionnetwork.org |
| 139 | |
| 140 | Suggested JS code: |
| 141 | |
| 142 | {{{ |
| 143 | <!-- Piwik --> |
| 144 | <script type="text/javascript"> |
| 145 | var pkBaseURL = (("https:" == document.location.protocol) ? "https://stats.transitionnetwork.org/" : "http://stats.transitionnetwork.org/"); |
| 146 | document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); |
| 147 | </script><script type="text/javascript"> |
| 148 | try { |
| 149 | var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); |
| 150 | piwikTracker.trackPageView(); |
| 151 | piwikTracker.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 | |
| 157 | Suggested 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 | |
| 167 | In 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 | |
| 172 | Set up cron: |
| 173 | |
| 174 | {{{ |
| 175 | crontab -u www-data -e |
| 176 | |
| 177 | 5 * * * * /web/stats.transitionnetwork.org/piwik/misc/cron/archive.sh > /dev/null |
| 178 | }}} |
| 179 | |
| 180 | Test it: |
| 181 | |
| 182 | {{{ |
| 183 | su www-data -c "sh /web/stats.transitionnetwork.org/piwik/misc/cron/archive.sh" |
| 184 | }}} |
| 185 | |
| 186 | This generated this error: |
| 187 | |
| 188 | {{{ |
| 189 | ALERT - 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 | |
| 192 | Which 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 | |
| 194 | Things added to {{{/web/stats.transitionnetwork.org/piwik/config/config.ini.php}}}, taken from {{{global.ini.php}}}: |
| 195 | |
| 196 | {{{ |
| 197 | [General] |
| 198 | force_ssl_login = 1 |
| 199 | feedback_email_address = "webproject (at) transitionnetwork.org" |
| 200 | assume_secure_protocol = 1 |
| 201 | }}} |
| 202 | |
| 203 | ===== GA Import ===== |
| 204 | |
| 205 | First install Python 2.6 from source: |
| 206 | |
| 207 | {{{ |
| 208 | aptitude build-dep python2.5 |
| 209 | cd /usr/local/src |
| 210 | wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz |
| 211 | tar -zxvf Python-2.6.7.tgz |
| 212 | cd Python-2.6.7 |
| 213 | ./configure --with-threads --enable-shared |
| 214 | make |
| 215 | make install |
| 216 | ln -s /usr/local/lib/libpython2.6.so* /usr/lib/ |
| 217 | cd /usr/local/src |
| 218 | wget 'http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e' |
| 219 | tar zxvf setuptools-0.6c11.tar.gz |
| 220 | cd setuptools-0.6c11 |
| 221 | python setup.py install |
| 222 | cd /usr/local/src |
| 223 | wget "https://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz" --no-check-certificate |
| 224 | tar -zxvf gdata-2.0.14.tar.gz |
| 225 | cd gdata-2.0.14 |
| 226 | python setup.py install |
| 227 | cd /usr/local/src |
| 228 | aptitude purge python-mysqldb |
| 229 | wget "http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz" |
| 230 | tar -zxvf MySQL-python-1.2.3.tar.gz |
| 231 | cd MySQL-python-1.2.3 |
| 232 | vim site.cfg |
| 233 | mysql_config = /usr/bin/mysql_config |
| 234 | aptitude install libmysqlclient-dev |
| 235 | python setup.py build |
| 236 | python setup.py install |
| 237 | }}} |
| 238 | |
| 239 | Then the GA code and import: |
| 240 | |
| 241 | {{{ |
| 242 | cd /web/stats.transitionnetwork.org/ |
| 243 | wget http://clearcode.cc/google2piwik-1.2.5.tgz |
| 244 | tar -zxvf google2piwik-1.2.5.tgz |
| 245 | cd google2piwik-1.2.5 |
| 246 | cp google2piwik.conf.sample google2piwik.conf |
| 247 | }}} |
| 248 | |
| 249 | Edit {{{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] |
| 257 | user_login = transitiontownsnetwork [at] gmail.com |
| 258 | user_pass = XXX |
| 259 | table_id = ga:XXX |
| 260 | |
| 261 | # MySQL Piwik Database configuration |
| 262 | [mysql] |
| 263 | db = stats |
| 264 | host = localhost |
| 265 | port = 3306 |
| 266 | user = stats |
| 267 | passwd = XXX |
| 268 | table_prefix = |
| 269 | |
| 270 | # Set export date range |
| 271 | [export] |
| 272 | start = 2008-01-01 |
| 273 | end = 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] |
| 278 | site_id = 1 |
| 279 | site_url = http://transitionnetwork.org |
| 280 | }}} |
| 281 | |
| 282 | Test and backup db: |
| 283 | |
| 284 | {{{ |
| 285 | ./google2piwik.py -p |
| 286 | ./google2piwik.py -c |
| 287 | mysql_backup |
| 288 | }}} |
| 289 | |
| 290 | Then change the timezone to UTC for the site on https://stats.transitionnetwork.org/ run it in screen: |
| 291 | |
| 292 | {{{ |
| 293 | screen |
| 294 | ./google2piwik.py --verbose=2 |
| 295 | }}} |
| 296 | |
| 297 | === Kiwi Server === |
| 298 | |
| 299 | The [http://piwik.org/ Piwik] server that is to be installed on the DevelopmentServer, the install was done on ticket:160 |
| 300 | |
| 301 | ==== Config ==== |
| 302 | |
| 303 | In {{{/web/piwik.transitionnetwork.org/piwik/config}}} |
| 304 | |
| 305 | {{{ |
| 306 | assume_secure_protocol = 1 |
| 307 | }}} |
| 308 | |
| 309 | ==== Install ==== |
| 310 | |
| 311 | Site: https://piwik.transitionnetwork.org/ |
| 312 | |
| 313 | ===== Download ===== |
| 314 | |
| 315 | {{{ |
| 316 | cd /web/ |
| 317 | mkdir piwik.transitionnetwork.org |
| 318 | cd piwik.transitionnetwork.org/ |
| 319 | wget http://piwik.org/latest.zip |
| 320 | unzip latest.zip |
| 321 | }}} |
| 322 | |
| 323 | ===== Apache ===== |
| 324 | |
| 325 | Then set up apache, see /etc/apache2/sites-available/piwik.transitionnetwork.org and run the web installer and: |
| 326 | |
| 327 | {{{ |
| 328 | cd /web/piwik.transitionnetwork.org/piwik/ |
| 329 | chown -R www-data:www-data tmp/ |
| 330 | chown -R www-data:www-data config/ |
| 331 | }}} |
| 332 | |
| 333 | ===== MySQL ===== |
| 334 | |
| 335 | Then a MySQL user and database was added using phpMyAdmin which ran the following SQL: |
| 336 | |
| 337 | {{{ |
| 338 | CREATE USER 'piwik'@'localhost' IDENTIFIED BY '********'; |
| 339 | GRANT 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 ; |
| 340 | CREATE DATABASE IF NOT EXISTS `piwik` ; |
| 341 | GRANT ALL PRIVILEGES ON `piwik` . * TO 'piwik'@'localhost'; |
| 342 | }}} |
| 343 | |
| 344 | ===== Tracking code ===== |
| 345 | |
| 346 | The 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"> |
| 351 | var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.transitionnetwork.org.webarch.net/" : "http://piwik.transitionnetwork.org.webarch.net/"); |
| 352 | document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); |
| 353 | </script><script type="text/javascript"> |
| 354 | try { |
| 355 | var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); |
| 356 | piwikTracker.trackPageView(); |
| 357 | piwikTracker.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 | |
| 363 | And 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 | |
| 371 | The 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 | |
| 383 | Customise the logo: |
| 384 | |
| 385 | {{{ |
| 386 | cd /web/piwik.transitionnetwork.org/piwik |
| 387 | chown -R www-data:www-data themes/ |
| 388 | }}} |
| 389 | |
| 390 | ===== Cron ===== |
| 391 | |
| 392 | Set 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 | {{{ |
| 395 | crontab -u www-data -e |
| 396 | |
| 397 | 5 * * * * /web/piwik.transitionnetwork.org/piwik/misc/cron/archive.sh > /dev/null |
| 398 | }}} |
| 399 | |
| 400 | ===== Python ===== |
| 401 | |
| 402 | For 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 | {{{ |
| 405 | aptitude build-dep python2.5 |
| 406 | cd /usr/local/src |
| 407 | wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz |
| 408 | tar -zxvf Python-2.6.7.tgz |
| 409 | cd Python-2.6.7 |
| 410 | ./configure --with-threads --enable-shared |
| 411 | make |
| 412 | make install |
| 413 | ln -s /usr/local/lib/libpython2.6.so* /usr/lib/ |
| 414 | cd /usr/local/src |
| 415 | wget 'http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e' |
| 416 | tar zxvf setuptools-0.6c11.tar.gz |
| 417 | cd setuptools-0.6c11 |
| 418 | python setup.py install |
| 419 | cd /usr/local/src |
| 420 | wget "https://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz" --no-check-certificate |
| 421 | tar -zxvf gdata-2.0.14.tar.gz |
| 422 | cd gdata-2.0.14 |
| 423 | python setup.py install |
| 424 | aptitude purge python-mysqldb |
| 425 | wget "http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz" |
| 426 | tar -zxvf MySQL-python-1.2.3.tar.gz |
| 427 | cd MySQL-python-1.2.3 |
| 428 | vim site.cfg |
| 429 | mysql_config = /usr/bin/mysql_config |
| 430 | aptitude install libmysqlclient-dev |
| 431 | python setup.py build |
| 432 | python setup.py install |
| 433 | }}} |
| 434 | |
| 435 | ===== GA Import ===== |
| 436 | |
| 437 | See python notes above and [http://clearcode.cc/offer/open-source-projects/google2piwik/ Google2Piwik]. |
| 438 | |
| 439 | {{{ |
| 440 | cd /web/piwik.transitionnetwork.org/ |
| 441 | wget http://clearcode.cc/google2piwik-1.2.5.tgz |
| 442 | tar -zxvf google2piwik-1.2.5.tgz |
| 443 | cd google2piwik-1.2.5 |
| 444 | cp google2piwik.conf.sample google2piwik.conf |
| 445 | }}} |
| 446 | |
| 447 | Edit {{{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] |
| 454 | user_login = XXX@gmail.com |
| 455 | user_pass = XXX |
| 456 | table_id = ga:XXX |
| 457 | |
| 458 | # MySQL Piwik Database configuration |
| 459 | [mysql] |
| 460 | db = piwik |
| 461 | host = localhost |
| 462 | port = 3306 |
| 463 | user = piwik |
| 464 | passwd = XXX |
| 465 | table_prefix = |
| 466 | |
| 467 | # Set export date range |
| 468 | [export] |
| 469 | start = 2011-05-01 |
| 470 | end = 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] |
| 475 | site_id = 1 |
| 476 | site_url = http://www.transitionnetwork.org |
| 477 | }}} |
| 478 | |
| 479 | Get the table_id and test and backup db: |
| 480 | |
| 481 | {{{ |
| 482 | ./google2piwik.py -p |
| 483 | ./google2piwik.py -c |
| 484 | mysql_backup |
| 485 | }}} |
| 486 | |
| 487 | Piwik, 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 | |
| 496 | The [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 | |