How to Setup Foswiki with Nginx on Ubuntu Linux

dual screen 1745705 640
dual screen 1745705 640

This brief tutorial shows students and new users how to install and configure the Foswiki platform on Ubuntu 18.04 | 16.04 with the Nginx HTTP server.

Our previous tutorial showed you how to install Foswiki on Ubuntu with an Apache2 HTTP server. This post shows you how to do it with Nginx instead.

Foswiki is a free, open-source, wiki platform that provides enterprise-grade collaboration features that your team can use to share and collaborate directly in their web browser.

Foswiki software offers features that may not be available to other CMS, like WordPress Joomla, or Drupal.

For more about Foswiki, please check its homepage.

When you’re ready to get Foswiki working, continue with the steps below:

Install Nginx HTTP Server

Foswiki requires a web server and Nginx HTTP Server is the most popular web server in use. You might want to install it to run Foswiki.

To install Nginx HTTP on the Ubuntu server, run the commands below.

sudo apt update
sudo apt install nginx libfcgi-perl libfcgi-procmanager-perl

After installing Nginx, the commands below can be used to stop, start and enable the Nginx service to always start up with the server boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

To test the Nginx setup, open your browser and browse to the server hostname or IP address and you should see the Nginx default test page as shown below. When you see that, then Nginx is working as expected.

http://localhost

Install Perl and Related Modules

Foswiki is written in Perl which is supported on any platform. To install Perl and related modules to support Foswiki, run the commands below:

sudo apt update
sudo apt install libalgorithm-diff-perl libarchive-tar-perl libauthen-sasl-perl libcgi-pm-perl libcgi-session-perl libcrypt-passwdmd5-perl libdigest-sha-perl libemail-address-perl libemail-mime-perl libencode-perl liberror-perl libfile-copy-recursive-perl libhtml-parser-perl libhtml-tree-perl libio-socket-ip-perl libio-socket-ssl-perl libjson-perl liblocale-maketext-perl liblocale-maketext-lexicon-perl liblocale-msgfmt-perl libwww-perl liblwp-protocol-https-perl liburi-perl libversion-perl

Download Foswiki Latest Release

Next, visit the Foswiki site and download the latest package. At the time of this writing, the latest version is 2.1.6

If you find a newer version, download it instead of this. Use the commands below to download and extract the archive package, replacing the version number with the current latest.

cd /tmp/
wget https://github.com/foswiki/distro/releases/download/FoswikiRelease02x01x06/Foswiki-2.1.6.tgz
tar xvzf Foswiki-2.1.6.tgz
sudo mv Foswiki-2.1.6 /var/www/foswiki

Then run the commands below to set the correct permissions for Foswiki to function properly.

sudo chown -R www-data:www-data /var/www/foswiki/
sudo chmod -R 755 /var/www/foswiki/

Next, change into the Foswiki directory and run these commands to fix file permissions issues.

cd /var/www/foswiki/tools
sudo sh fix_file_permissions.sh
sudo perl rewriteshebang.pl

When you’re done continue below to create Foswiki’s Nginx vhost file.

Configure the Nginx Foswiki Site

After the settings above, run the commands below to copy the Foswiki default config file from its root directory to Ubuntu defaults folder.

sudo cp /var/www/foswiki/tools/foswiki.defaults /etc/default/

Inside the file should be lines like the ones below:

# Tailor these settings for your installation
FOSWIKI_ROOT=/var/www/foswiki
FOSWIKI_FCGI=foswiki.fcgi
FOSWIKI_BIND=127.0.0.1:9000
FOSWIKI_CHILDREN=3
FOSWIKI_MAX_REQUESTS=-1
FOSWIKI_MAX_SIZE=200000
FOSWIKI_CHECK_SIZE=10
FOSWIKI_PNAME=foswiki

Next, copy the next config file into the Ubuntu systemd directory.

sudo cp /var/www/foswiki/tools/systemd/foswiki.service /etc/systemd/system/

Next, configure the Nginx configuration file for Foswiki. This file will control how users access Foswiki content. Run the commands below to create a new configuration file called Foswiki

A script to auto-generate the configuration file can be found here. Use it to generate one for your environment. Use copy and paste the configuration lines below into the file and save.

sudo nano /etc/nginx/sites-available/foswiki

Then copy and paste the content below into the file and save it. Replace the highlighted line with your domain name and directory root location.

server {
  server_name  example.com;
  set $foswiki_root /var/www/foswiki;

  root /var/www/html;
  index index.html;

  listen 80;

  location /favicon.ico {
    log_not_found off;
    access_log off;
  }
  location /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }
  
  location / {
    try_files $uri @foswiki;
  }

  # redirect short urls to view
  location ~ ^/(?:bin/)?([A-Z_].*)$ {
    rewrite ^/(.*)$ /bin/view/$1 last;
  }

  # any /bin goes to foswiki
  location /bin {
    try_files $uri @foswiki;
  }

  location ~ ^/pub/(System|Applications|cache)/ {
    root $foswiki_root;
    expires 8h;
    gzip_static on;
  }

  location /pub {
    root $foswiki_root;
    rewrite ^/pub/(.*)$ /bin/viewfile/$1;
  }

  location /files {
    internal;
    alias $foswiki_root/pub/;
    expires 8h;
    access_log off;
  }

  location ~ (^/lib|^/data|^/locale|^/templates|^/tools|^/work) {
     deny all;
  }

  # optional location for WebDAVContrib. 
  location /dav {
     gzip off;
 
     fastcgi_pass   127.0.0.1:9001;
     keepalive_timeout 0;
     fastcgi_keep_conn off;

     fastcgi_split_path_info ^/dav/(.+?)(/.*)$;
     fastcgi_param  SCRIPT_FILENAME  $foswiki_root/tools/wedav.fcgi;
     fastcgi_param  PATH_INFO $fastcgi_path_info;
     fastcgi_param  HTTP2 $http2;
 
     include fastcgi_params;
  }


  location @foswiki {
     gzip off;
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_read_timeout 120s; 

     fastcgi_split_path_info ^/bin/(.+?)(/.*)$;
     fastcgi_param  SCRIPT_FILENAME  $foswiki_root/bin/foswiki.fcgi;
     fastcgi_param  PATH_INFO $fastcgi_path_info;
     fastcgi_param  HTTP2 $http2;

     include fastcgi_params;
  }
}

Save the file and exit.

After configuring the VirtualHost above, enable it by running the commands below

Enable the Foswiki Site

After configuring the VirtualHost above, enable it by running the commands below, then restart the Nginx server.

sudo ln -s /etc/nginx/sites-available/foswiki /etc/nginx/sites-enabled/
sudo systemctl daemon-reload
sudo systemctl start foswiki.service
sudo systemctl enable foswiki.service

Restart Nginx

sudo systemctl restart nginx.service

Next, open your browser and browse to the server hostname or IP address to bootstrap your install by browsing to the default view URL for your site in your web browser.

http://example.com/bin/view

Follow the link in the Bootstrap banner of the returned page to the bin/configure tool, address any warnings and save your configuration.

Begin addressing issues on the left. when you’re done save your changes.

Return from configure (button at top of page), and register your first user.

Enjoy!

Conclusion:

You have successfully installed Foswiki CMS on Ubuntu 16.04 | 18.04. For more tutorials on Ubuntu please search our site.

You may also like the post below:

Posted by
Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: