Difference between revisions of "Installing GeneWeb 7 on a Raspberry Pi webserver"

From GeneWeb
Jump to: navigation, search
Line 9: Line 9:
 
Download an ISO file of [https://www.raspberrypi.org/downloads/raspbian Raspian Lite ISO]. On a Mac, use [https://www.balena.io/etcher balenaEtcher] to format and flash the ISO image directly from the zip file on to a micro SD card. Copy also the “wpa_supplicant.conf” and “ssh” files to the micro SD card ([https://www.raspberrypi.org/documentation/configuration/wireless/headless.md see for further information]).
 
Download an ISO file of [https://www.raspberrypi.org/downloads/raspbian Raspian Lite ISO]. On a Mac, use [https://www.balena.io/etcher balenaEtcher] to format and flash the ISO image directly from the zip file on to a micro SD card. Copy also the “wpa_supplicant.conf” and “ssh” files to the micro SD card ([https://www.raspberrypi.org/documentation/configuration/wireless/headless.md see for further information]).
  
Start the Raspberry Pi and secure the installation by changing password for the user 'pi' and create a new password for root. Update system with <code>sudo apt-get update</code> and <code>sudo apt-get upgrade</code>. If using the latest version of Debian (Buster) the following may be required: <code>sudo apt-get update --allow-releaseinfo-change</code>.
+
Start the Raspberry Pi and secure the installation by changing the password for the user 'pi' and create a new password for root. Update system with <code>sudo apt-get update</code> and <code>sudo apt-get upgrade</code>. If using the latest version of Debian (Buster) the following may be required: <code>sudo apt-get update --allow-releaseinfo-change</code>.
  
 
== Compiling GeneWeb 7 ==
 
== Compiling GeneWeb 7 ==

Revision as of 10:34, 18 July 2019

This page explains how to run GeneWeb 7 as a CGI service on a home hosted web server running on a Raspberry Pi. Finding a Linux web hosting provider that allows the flexibility needed to run GeneWeb 7 as CGI is neither easy nor cost effective. A Raspberry Pi connected to your home internet connection is a viable alternative, in both flexibility and cost.

This tutorial assumes that you have successfully connected your Raspberry Pi to your home network so that it can be accessed from the internet, i.e. the outside world. This is done by a process called modem port forwarding. Specific instructions on how to do this vary according to the brand and model of your router. Do a search online - surely someone has done it before.

Throughout this article, the IP address referred as 12.12.123.123, the GED file “jones.ged” and the site domain name “mygeneweb.info” are meant to be examples and should be replaced as appropriate. See also the disclaimer at the bottom of this page.

Preparing the Raspberry Pi

Download an ISO file of Raspian Lite ISO. On a Mac, use balenaEtcher to format and flash the ISO image directly from the zip file on to a micro SD card. Copy also the “wpa_supplicant.conf” and “ssh” files to the micro SD card (see for further information).

Start the Raspberry Pi and secure the installation by changing the password for the user 'pi' and create a new password for root. Update system with sudo apt-get update and sudo apt-get upgrade. If using the latest version of Debian (Buster) the following may be required: sudo apt-get update --allow-releaseinfo-change.

Compiling GeneWeb 7

Before compiling Geneweb we need to download and install Opam, OCaml and Camlp5.

Install the following Raspian packages (if not installed already).

sudo apt-get install curl make m4 unzip bubblewrap gcc libgmp-dev git

Install Opam.

sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)

Initialise Opam. This will take some time, as Opam will download and install the latest compiler (switch 4.08.0). This will take time! Be patient.

opam init
eval $(opam env)

Install Opam packages required to compile GeneWeb. Again, this will take some time, as the installation of camlp5 will trigger the downgrade of the OPAM switch from 4.08.0 to 4.07.1.

opam pin add --no-action markup git://github.com/geneanet/markup.ml
opam install camlp5 --unlock-base
opam install cppo dune markup stdlib-shims num zarith

Now that all Opam packages are installed, download and compile GeneWeb.

git clone https://github.com/geneweb/geneweb
cd geneweb
./configure && make && make distrib

Once finished, you should have a directory called directory distribution - this is the compiled GeneWeb!

Setting up GeneWeb 7

Next we need to place the compiled GeneWeb directory on a location from where it can be accessed by Apache. Create the directory /home/GW.

sudo mkdir /home/GW

Move the directory with the compiled GeneWeb files to the new directory /home/GW and rename it as GeneWeb7.

sudo mv ./geneweb/distribution /home/GW
sudo mv /home/GW/distribution /home/GW/GeneWeb7

Create two new directories inside the directory /home/GW, one for imported GED files and GeneWeb databases, another for GeneWeb log files:

cd /home/GW
sudo mkdir bases7
sudo mkdir logs

Changes directory permissions to 775.

sudo chmod 775 bases7
sudo chmod 775 logs

Change directory ownership to pi and www-data.

sudo chown pi:www-data bases7
sudo chown pi:www-data logs

Installing Apache

To run the Raspberry Pi as a web server we need to install Apache (and any dependencies required by Apache).

sudo apt-get install apache2

Change ownership and permissions of the HTML directory created by Apache.

sudo chown -R pi:www-data /var/www/html
sudo chmod -R 770 /var/www/html

Test the "Apache Debian Default Page" on the IP address for your Raspberry Pi (ex: http://12.12.123.123). After testing, for security reasons, delete the file index.html from the directory /var/www/html.

Setting up CGI

CGI scripts are placed in the directory /usr/lib/cgi-bin. To test CGI, place a test command file in this directory.

cd /usr/lib/cgi-bin
sudo nano test-cgi.sh

In the nano editor, copy and paste the following text.

#!/bin/sh
echo 'Content-type: text/html'
echo  
echo '<!DOCTYPE html>'
echo '<html xmlns="http://www.w3.org/1999/xhtml">'
echo '<body>'
echo 'This is a test for CGI commands'
echo '</body>'
echo '</html>'

Crtl-X to save the file. Make the script executable.

sudo chmod +x /usr/lib/cgi-bin/test-cgi.sh

Before we run this test CGI script, we need to enable CGI scripts.

sudo a2enmod CGI
sudo service apache2 restart

On a browser window, type the following (replace with the IP address for your Raspberry Pi):

http://12.12.123.123/cgi-bin/test-cgi.sh

The browser should display:

This is a test for CGI commands

Now, let’s place a CGI script to run GeneWeb.

<code>sudo nano gwd.sh</code>

Copy the following text.

#!/bin/sh
VERS=GeneWeb7
BIN_DIR=/home/GW/$VERS/gw
BASES=/home/GW/bases7
WEB_DIR=/var/www/html
LOGS_DIR=/home/GW/logs
OPT="-cgi -hd $BIN_DIR -bd $BASES -allowed_tags $BASES/tags.txt -add_lexicon lex_utf8-hg.txt"
$BIN_DIR/gwd  $OPT -log $LOGS_DIR/gwdl.log 2>$LOGS_DIR/gwd.log

Press Ctrl+X Make the file executable.

sudo chmod +x gwd.sh

Next, we need to place a symbolic link in the HTML directory /var/www/html to a particular directory holding some GeneWeb resources.

cd /var/www/html
ln -s /home/GW/GeneWeb7/gw/etc gw-etc

Uploading a GED file

(Note that you can also import a GeneWeb .gw file.)

Open a separate terminal window and issue the following command (adjusted to your local and server environment):

scp /Users/your_home_folder/GED/jones.ged pi@12.12.123.123:/home/GW/bases7

Upload a .gwd file corresponding to your GED file.

scp /Users/your_home_folder/GED/jones.gwf pi@12.12.123.123:/home/GW/bases7

For each GED file uploaded, there must be a corresponding .gwf file. If you upload a GED file called “jones.ged”, upload a “jones.gwf” text file.

"Screenshot of a user terminal showing the content of GeneWeb “bases” directory"

A .gwf should contain the following text.

static_path=../gw-etc/
welcome_logo=gwlogo.png
wizard_passwd=
friend_passwd=

#wizard_passwd_file=wiz.auth
#friend_passwd_file=frHe.auth
#wizard_passwd_file=wiz.auth

wizard_just_friend=no
wizard_not_wizard=no
hide_private_names=yes
no_image_for_visitor=yes
death_symbol=+
always_surname=no
event_age=yes
particles="AF","AV","D","DAL","DE","DEN","DES","DI","DU","OF","UND","VAN","VON","ZU","ZUR","DE LES","DO","DA","DAS","DOS"
uppercase=yes
denied_titles_file=denied-hg.txt
allowed_titles_file=allowed-hg.txt
all_titles=off

Go back to the Terminal window where you are connected to the Raspberry Pi, and issue the commands:

cd /home/GW/bases7
/home/GW/GeneWeb7/gw/ged2gwb -f /home/GW/bases7/jones.ged -o jones

GeneWeb will process the GED file uploaded. After importing/processing the GED file, to ensure that GeneWeb 7 works correctly, keep the names of the GeneWeb database and the .gwf file, identical (example: jones.gwb and jones.gwf). If necessary, rename files manually.


Viewing the GeneWeb 7 site

On your browser type a URL with following syntax:

http://12.12.123.123/cgi-bin/gwd.sh?b=jones

Setting up a domain name

If you wish to share your database online, you will need a domain name to make your Raspberry Pi visible on the outside world.

You can use a free dynamic IP address forwarding service (such as noip.com that can provide you with a subdomain, such as http://jones.zapto.org, pointing to your Raspberry Pi’s IP address. Historically, these free hosted subdomains have been harvested by trolls and are frequently bombarded with automated hacking attempts - you will soon see the Apache log files showing the intensity of these “attacks”. They could be also banned on social media such as Facebook that prohibe sharing of addresses using noip.com DNS.

For these reasons, it is advisable to register your own domain. You can register a .com, a .info or even a national domain (.fr or .de, for instance) for a few Euro per year. To register a domain, you will need to use the services of a registrar or an intermediary (such as godaddy.com). Whichever one you choose, make sure that they will allow you to set your own DNS servers for the new domain.

Register the domain using the default DNS server information. Once you have completed the domain name registration, we need to set up the virtual host for that domain on the Raspberry Pi. For the purpose of this exercise, we are using the domain “mygeneweb.info”.

Create the Virtual Host file for the domain. The file name has the domain name followed by a “.conf” extension.

sudo nano /etc/apache2/sites-available/mygeneweb.info.conf

Type the following text, replacing all instances of “mygeneweb.info” with your own domain name.

<VirtualHost *:80>

ServerAdmin your.email@address.com
ServerName mygeneweb.info
ServerAlias www.mygeneweb.info
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/mygeneweb.info_error.log
CustomLog ${APACHE_LOG_DIR}/mygeneweb.info_access.log combined

</VirtualHost>

Press Ctrl+X. Now, enable the new virtual host.

sudo a2ensite mygeneweb.info.conf

Restart Apache.

sudo systemctl restart apache2

Connecting your domain name to your RPi

To have your domain name resolve to your Raspberry Pi hosted GeneWeb site, you need to map the domain name to the IP address of the Raspberry Pi. This is done through a DNS file. For security reasons, we should try to keep this information as obfuscated as possible. As such, we’ll use an intermediary service - Cloudflare - between your domain name registrar and your home network where the Raspberry Pi web server sits.

Go to Cloudflare and create an account. Choose the free plan, valid for one domain. Enter your domain name. Cloudflare will display the minimum information required for the new DNS file for your domain. On the first line starting with “Type A” click on the “points to …” cell and change the IP number displayed with the IP address for your Raspberry Pi. Click continue to save.

"Screenshot of Cloudflare web site for DNS setup"

Clouldflare will now display the names of the name servers where the information for your site resides: adrian.ns.cloudflare.com and dean.ns.cloudflare.com. Go to the site where you manage your domain name and change the name server information for your domain with the Cloudflare’s name servers.

On the Clouldflare site confirm that you have changed the name server information. Cloudflare will queue your site for verification. Once it has verified the updated name server information, the site will be active on Cloudflare.

Enabling encryption

As we are using Cloudflare for the name servers and as intermediary between internet users and our home Raspberry Pi web server, the easiest way to encrypt the GeneWeb site, is to encrypt the traffic between the outside world and Cloudflare. The traffic from Cloudflare to our home server (and vice-versa) is unencrypted. Visitors to the GeneWeb site will still see the site marked with a padlock next to the URL, meaning that is encrypted.

To enable this option, log in to Cloudflare, choose your domain, click on the icon “Crypto” and on the first option “SSL”, choose “Flexible” from the dropdown menu. Your site will show as encrypted.

Set GeneWeb as the default when accessing your site

Go to /var/www/html directory and create an index.html file.

cd /var/www/html
sudo nano index.html

Copy the following code, adjusted for your environment:

<meta http-equiv="refresh" content="0; URL='https://your-domain-name/cgi-bin/gwd.sh?b=your-database-name'" />

Press Ctrl+X to save the file. Make sure that there are no other index.html or index.htm files in the same directory.

Your domain name should now load GeneWeb 7 automatically!

"Screenshot of the welcome page of GeneWeb version 7"

Disclaimer: Like anything involving computers, software, programming languages and the internet, the above procedure has been tested and deemed accurate at the time of writing (July 2019). It is meant to serve as a guide and it may need to be adjusted in the future to take into account any changes to the software or services offered by the third parties referred.

See also

  • Ocaml build GeneWeb on other platforms.
  • https setup a more secure GeneWeb server.
  • Docker install GeneWeb with Docker.