Jump to content

Product Opener/Installation: Difference between revisions

Replaced content with "Category:ProductOpener Category:Developer Installation instructions for Product Opener (see Product Opener). The newest installation instructions are on https..."
(Replaced content with "Category:ProductOpener Category:Developer Installation instructions for Product Opener (see Product Opener). The newest installation instructions are on https...")
Β 
Line 3: Line 3:
Installation instructions for Product Opener (see [[Product Opener]]).
Installation instructions for Product Opener (see [[Product Opener]]).


== Before you start ==
The newest installation instructions are on https://en.wiki.openfoodfacts.org/Infrastructure#Server_configuration
Β 
Product Opener is not yet released as open source. The instructions below are for reference and for early testers of Product Opener. 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.
Β 
When it is released, Product Opener will have much easier to use install scripts and instructions.
Β 
== Install directory ==
Β 
Instructions below use /home/obf for the install directory, replace with your install dir.
Β 
== Product Opener code ==
Β 
=== Configuration ===
Β 
==== startup.pl ====
Β 
This file is used to preload Perl module in Apache.
It contains a path that needs to be updated:
Β 
# Needs to be configured
use lib "/home/obf/cgi/";
Β 
==== Config.pm ====
Β 
==== Config2.pm ====
Β 
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.
Β 
# server constants
$domain = "openbeautyfacts.org";
# server paths
$www_root = "/home/obf/html";
$data_root = "/home/obf";
$mongodb = "obf";
Β 
=== Libraries ===
Either <code>brew install</code> or <code>apt-get install</code> these dependencies as appropriate:
zbar imagemagick graphviz tesseract
=== Required Perl modules ===
The following Perl modules need to be installed (some of them might be included with Perl).
Β 
<pre>
Cache::Memcached::Fast
Crypt::PasswdMD5
DateTime
DateTime::Format::Mail
Digest::MD5
Digest::SHA1
Encode::Punycode
File::Copy
File::Path
Geo::IP
Getopt::Long
GraphViz2
Hash::Util
HTML::Defang
HTML::Entities
Image::Magick
Image::OCR::Tesseract
IPC::Open3
JSON
LWP::Authen::Digest
</pre>
Β 
To install a module, you can sometimes use packages.
Β 
e.g. on Debian / Ubuntu :Β  <code>apt-get install libdatetime-perl</code>
Β 
Or you can use ''cpan'': <code>cpan install DateTime</code>
Β 
Or ''cpanm'': <code>perl cpanm --installdeps .</code>
Β 
== MongoDB database ==
Product Opener requires [https://www.mongodb.com/ MongoDB] to run.
Β 
* Install MongoDB.
Β 
* The MongoDB database name is configured in PROJECTROOT/cgi/Config.pm
Β 
* The MongoDB database is created when the first product is added.
Β 
=== MongoDB indexes ===
Β 
See [[Product Opener mongodb indexes]]
Β 
== Apache servers ==
Β 
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.
Β 
If the traffic is low or moderate, you can use only one Apache mod_perl server that also serves images etc.
Β 
In the example below, the Apache mod_perl server listens on port 19000.
Β 
=== Light-weight reverse proxy for static files ===
Β 
Compile:
Β 
./configure --prefix=/home/xyz/proxy --enable-rewrite --enable-proxy --enable-proxy_http --disable-userdir --enable-headers --enable-expires --enable-mime --enable-so --with-included-apr
Β 
Add to httpd.conf:
Β 
<pre>
Β 
<VirtualHost *>
DocumentRoot /home/obf/html
ServerName world.openbeautyfacts.org
ServerAlias *.openbeautyfacts.org
Β 
ErrorLog /home/obf/logs/proxy_error_log
CustomLog /home/obf/logs/proxy_access_log combined
ServerAdmin stephane@openbeautyfacts.org
Β 
<Directory "/home/obf/html">
Β  Β  Options -Indexes FollowSymLinks
Β  Β  Order allow,deny
Β  Β  Allow from all
</Directory>
ProxyPreserveHost On
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>
Β 
Β 
<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]
Β 
</VirtualHost>
Β 
</pre>
Β 
=== modperl Apache server for dynamic pages ===
Β 
# 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
# <code>./configure --with-mpm=prefork --prefix=/home/obf/apache --enable-rewrite --enable-proxy --enable-proxy_http --enable-deflate --disable-userdir --enable-headers</code>
# <code>make</code>
# <code>make install</code>
# Download the latest version of mod_perl from http://perl.apache.org/
# Extract the source
# <code>perl Makefile.PL MP_APXS=/home/obf/apache/bin/apxs</code>
# <code>make</code>
# <code>make install</code>
Β 
==== Configuration ====
Β 
In /home/obf/apache/conf/httpd.conf:
Β 
Change the port:
Β 
<code>Listen 19000</code>
Β 
Add at the end:
Β 
<pre>
LoadModule perl_module modules/mod_perl.so
Β 
PerlWarn Off
PerlRequire /home/obf/cgi/startup.pl
Β 
Β 
<Location /cgi>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all
</Location>
Β 
Β 
<VirtualHost *>
DocumentRoot /home/obf/html
ServerName world.openbeautyfacts.org
ErrorLog /home/obf/logs/error_log
CustomLog /home/obf/logs/access_log combined
ScriptAlias /cgi/ "/home/obf/cgi/"
</VirtualHost>
Β 
PerlPostReadRequestHandler My::ProxyRemoteAddr
</pre>
Β 
== Installation issues ==
Β 
Depending on your environment (in particular different versions of Linux, Apache, MongoDB, Perl, Perl modules etc.), you may encounter some issues when installing or running Product Opener.
Β 
[[Product Opener installation issues]] lists those issues and steps to resolve them.