Changes

Jump to navigation Jump to search
no edit summary
Line 1: Line 1: −
== Introduction ==
+
Installation instructions for ProductOpener (see [[Project:ProductOpener]]).
   −
ProductOpener is the software used by Open Food Facts to create and maintain its collaborative database of food products in open data.
+
== Before you start ==
   −
== Open source ==
+
ProductOpener is not yet released as open source. The instructions below are for reference and for early testers of ProductOpener. They are very likely to change as the code will be restructured, made more independent of proprietary code and specific Open Food Facts uses etc.
   −
ProductOpener will be released under an open source licence so that it can be reused by other projets, for instance to open the data for other types of products.
+
When it is released, ProductOpener will have much easier to use install scripts and instructions.
   −
The ProductOpener original code includes codes related to the original developer's other projects. Efforts are under way to clean, decouple and document the ProductOpener code so that it can be released as open source.
+
== Install directory ==
   −
== Components ==
+
Instructions below use /home/obf for the install directory, replace with your install dir.
   −
=== ProductOpener Database ===
+
== ProductOpener code ==
   −
==== Product data and history ====
+
=== Configuration ===
   −
The data for each product is stored in a structured object (several levels of hashes and arrays). The data is stored on disk in individual files in Perl's binary format for objects (Storable). The history of each change to the product data is also saved in the same format. There is one binary file for each version.
+
==== startup.pl ====
   −
==== Product data index ====
+
This file is used to preload Perl module in Apache.
 +
It contains a path that needs to be updated:
   −
The current version of each product is stored in a MongoDB database. The database includes indexes and is used to search and display products.
+
<pre>
MongoDB allow storing structured objects as-is, so there is an exact correspondence between Perl's internal format, MongoDB's format and the JSON export of the API.
+
# Needs to be configured
 +
use lib "/home/obf/cgi/";
 +
</pre>
   −
=== Product images ===
+
==== Config.pm ====
   −
Images are saved on disk for each product. Original images uploaded through the web server or mobile applications are kept. Thumbnails are also generated for the final product image.
+
==== Config2.pm ====
   −
==== Aggregated data ====
+
Contains info about the domain, database and path. This is separated from Config.pm so that it is easy to create test instance that share the same configuration in Config.pm but are on other domains.
   −
Some of the data is periodically aggregated and saved in Perl binary files (e.g. average nutrition facts for products of each category).
+
<pre>
 +
# server constants
 +
$domain = "openbeautyfacts.org";
   −
==== Exported data ====
+
# server paths
 +
$www_root = "/home/obf/html";
 +
$data_root = "/home/obf";
   −
The data for all products is periodically exported in CSV and RDF formats.
+
$mongodb = "obf";
 +
</pre>
   −
=== ProductOpener Web Server ===
+
== MongoDB database ==
   −
The web interface for searching, displaying, adding and editing products. (e.g. http://world.openfoodfacts.org for Open Food Facts)
+
== Apache servers ==
   −
The server is written in Perl. In production we use a light weight Apache web server for static files (e.g. images) that does reverse proxying to a modperl Apache server that dynamically generates
+
In production we use a light weight Apache web server for static files (e.g. images) that does reverse proxying to a modperl Apache server that dynamically generates the HTML pages.
the HTML pages.
     −
The form to add and edit product uses Javascript and jquery.
+
If the trafic is low or moderate, you can use only one Apache mod_perl server that also serves images etc.
   −
In the backend, other libraries and software are used, such as Tesseract for optical character recognition for ingredients.
+
In the example below, the Apache mod_perl server listens on port 19000.
   −
=== ProductOpener API ===
+
=== Light-weight reverse proxy for static files ===
   −
ProductOpener provides a JSON API to search products and read their data.
+
Add to httpd.conf:
   −
There is also a limited API to upload product images and edit some of the product data that is used by the mobile applications.
+
<pre>
   −
The API functionality is currently provided by the ProductOpener Web Server, but it may change in the future (e.g. at some point we could implement a full API for accessing (reading + writing) the ProductOpener database, and have the Web Server call the API instead of going directly to the database).  
+
<VirtualHost *>
 +
DocumentRoot /home/obf/html
 +
ServerName world.openbeautyfacts.org
 +
ServerAlias *.openbeautyfacts.org
   −
=== ProductOpener client applications ===
+
ErrorLog /home/obf/logs/proxy_error_log
 +
CustomLog /home/obf/logs/proxy_access_log combined
 +
ServerAdmin stephane@openbeautyfacts.org
   −
==== Apache Cordova mobile app for Android, iOS and Windows Phone ====
+
<Directory "/home/obf/html">
 +
    Options -Indexes FollowSymLinks
 +
    Order allow,deny
 +
    Allow from all
 +
</Directory>
 +
RewriteEngine on
 +
RewriteCond  %{REQUEST_URI}  !/./
 +
RewriteRule ^(/cgi/.*)$ http://localhost:19000$1 [P,L]
 +
RewriteMap escape int:escape
 +
RewriteRule ^/favicon.ico$ /favicon.ico [L]
 +
RewriteCond  %{REQUEST_URI}  !^/images/
 +
RewriteCond  %{REQUEST_URI}  !^/js/
 +
RewriteCond  %{REQUEST_URI}  !^/rss/
 +
RewriteCond  %{REQUEST_URI}  !^/robots
 +
RewriteCond  %{REQUEST_URI}  !^/clicks/
 +
RewriteCond  %{REQUEST_URI}  !^/data/
 +
RewriteCond  %{REQUEST_URI}  !^/files/
 +
RewriteRule  ^(.*)$ http://localhost:19000/cgi/display.pl?${escape:$1} [P,L,QSA]
 +
</VirtualHost>
   −
The current Open Food Facts mobile apps for Android, iOS and Windows Phone are developed with Apache Cordova (previously known as Phonegap) with the same HTML + Javascript (including jquery and jquerymobile) code base.
     −
The Android app uses Moodstocks image recognizer and barcode scanner plugin. The iOS and Windows Phone apps use the BarcodeScanner plugin.
+
<VirtualHost *>
 +
DocumentRoot /home/obf/html
 +
ServerName openbeautyfacts.org
 +
ErrorLog /home/obf/logs/proxy_error_log
 +
CustomLog /home/obf/logs/proxy_access_log combined
 +
DirectoryIndex index.html index.shtml
 +
<Directory "/home/obf/html">
 +
    Options -Indexes FollowSymLinks Includes
 +
    Order allow,deny
 +
    Allow from all
 +
</Directory>
 +
RewriteEngine on
 +
RewriteCond %{HTTP_HOST} ^openbeautyfacts\.org
 +
RewriteRule ^/products$ /products.shtml [L]
   −
The code for the Open Food Facts phonegap app is already in open source:
+
</VirtualHost>
* https://github.com/openfoodfacts/openfoodfacts-android/tree/master/phonegap/Open%20Food%20Facts (with the BarcodeScanner plugin)
  −
* https://github.com/openfoodfacts/openfoodfacts-moodstocks (with the Moodstocks plugin)
     −
== Installation ==
+
</pre>
   −
(In progress.)
+
=== modperl Apache server for dynamic pages ===
   −
See [[ProductOpener installation]]
+
* download the latest version of the source of the Apache httpd server from the 2.2 branch (2.2.29 when writing this)
 +
** do not use the 2.4 branch as mod_perl is not yet compatible with it
 +
* extract the source
 +
* ./configure --with-mpm=prefork --prefix=/home/obf/apache --enable-rewrite --enable-proxy --enable-proxy_http --enable-deflate --disable-userdir --enable-headers
 +
* make
 +
* make install
 +
 
 +
* download the latest version of mod_perl from http://perl.apache.org/
 +
* extract the source
 +
* perl Makefile.PL MP_APXS=/home/obf/apache/bin/apxs
 +
* make
 +
* make install

Navigation menu