SWI-Prolog on a Raspberry Pi

I’ve been experimenting with creating Prolog driven websites. However, my webhost does not support Prolog, so it became necessary to find some other means of making these accessible to the outside world. My solution was to setup Prolog on a Raspberry Pi, which functions as my own personal webserver.

Hardware:
Raspberry Pi – I used an older version of the Model B, but any Raspberry Pi should do.

Software:
Raspbian (September 2014 version)
SWI-Prolog 7.1.28

Getting Started

Start by completing a basic setup for the Raspberry Pi.

Raspbian comes bundled with a version of swi-prolog. Unfortunately, this is an older version and did not include several of the libraries that are useful for website projects. To gain access to all of these libraries, you will need to install several dependencies and compile swi-prolog from source.

These dependencies can be installed easily on Raspbian with the help of apt-get.

Run the following commands:

sudo apt-get install build-essential autoconf curl chrpath
sudo apt-get install ncurses-dev libreadline-dev libgmp-dev
sudo apt-get install libxext-dev libice-dev libjpeg8-dev libxinerama-dev
sudo apt-get install libxft-dev libxpm-dev libxt-dev pkg-config
sudo apt-get install libssl-dev unixodbc-dev openjdk-7-jdk junit
sudo apt-get install zlib1g-dev libarchive-dev libossp-uuid-dev

 

Next, we need to clone the source files from GitHub.

Run the following commands:

git clone http://github.com/SWI-Prolog/swipl-devel.git ~/swipl
cd ~/swipl

 

Then we need to fetch the required submodules.

Run the following commands:

./prepare

 

Now that we have the source files, we need to compile SWI-Prolog and all of the packages.

Run the following commands:

./configure --with-world
make
sudo make install

 

Prolog and all of its libraries should now be installed. To test to ensure everything worked correctly, return to the home directory, and start swipl.

Run the following commands:

cd ~/
swipl

 

Once in the swipl terminal, try loading a library to make sure it works.

?- use_module(library(http/http_files)).
true.

 

Update (February 6, 2015):

The check_installation predicate can be used to verify that everything installed correctly and all extensions can be loaded. If an extension fails to load, a link pointing to the Wiki page for that extension is provided.

?- check_installation.
% Checking your SWI-Prolog kit for common issues ...
% 
% Version: ............. 7.1.29-5-g0a3d88a
% Address bits: ........ 64
% Architecture: ........ x86_64-linux
% Installed at: ........ /usr/local/lib/swipl-7.1.29
% Cores: ............... 16
% 
% Checking gmp ................................. ok
% Checking command_line_editing ................ ok
% Loading library(archive) ..................... ok
%   Supported filters: bzip2, compress, gzip, grzip, lrzip, lzip, lzma, lzop, none, rpm, uu, xz
%   Supported formats: 7zip, ar, cab, cpio, empty, gnutar, iso9660, lha, mtree, rar, raw, tar, xar, zip
% Loading library(cgi) ......................... ok
% Loading library(crypt) ....................... ok
% Loading library(double_metaphone) ............ ok
% Loading library(filesex) ..................... ok
% Loading library(http/http_stream) ............ ok
% Loading library(http/json) ................... ok
% Loading library(isub) ........................ ok
% Loading library(jpl) ......................... FAILED
Warning: Cannot load required shared library
Warning: See http://www.swi-prolog.org/build/issues/jpl.html
% Loading library(memfile) ..................... ok
% Loading library(mime) ........................ ok
% Loading library(odbc) ........................ ok
% Loading library(pce) ......................... ok
% Loading library(pdt_console) ................. ok
% Loading library(porter_stem) ................. ok
% Loading library(process) ..................... ok
% Loading library(readutil) .................... ok
% Loading library(rlimit) ...................... ok
% Loading library(semweb/rdf_db) ............... ok
% Loading library(semweb/rdf_ntriples) ......... ok
% Loading library(semweb/turtle) ............... ok
% Loading library(sgml) ........................ ok
% Loading library(sha) ......................... ok
% Loading library(snowball) .................... ok
% Loading library(socket) ...................... ok
% Loading library(ssl) ......................... ok
% Loading library(syslog) ...................... ok
% Loading library(table) ....................... ok
% Loading library(time) ........................ ok
% Loading library(tipc/tipc) ................... ok
% Loading library(unicode) ..................... ok
% Loading library(uri) ......................... ok
% Loading library(uuid) ........................ ok
% Loading library(zlib) ........................ ok
Warning: Found 1 issues.
true.


Further Reading