Install LWT on a VPS

Install LWT on a VPS
Photo by Manuel Cosentino / Unsplash

The original version of LWT is still available on SourceForge, but doesn't seem to be under active development. There have been several forks. The following repo appears to have the currently most well maintained and further developed version: https://github.com/HugoFara/lwt

The "Linux" install instructions from the original document are the most relevant: https://hugofara.github.io/lwt/docs/info.html#install, but several of the steps below were added following troubleshooting errors which appeared only on starting to use LWT.

Preparation

  1. Add DNS A record of required domain / subdomain name to point to server IP address e.g. lwt.example.com
  2. Create a new mysql (mariadb) database and user for LWT
  3. Enable the following PHP extensions in php.ini: mbstring and mysqli
  4. Enable local_infile for mysqli extension in php.ini:  mysqli.allow_local_infile = On
  5. Restart php-fpm (I think, or just reboot!): sudo systemctl restart php8.0-fpm
  6. Check phpinfo now looking good with regards to these settings

Japanese only

Install MeCab and NEologd following instructions here: http://www.robfahey.co.uk/blog/japanese-text-analysis-in-python/

Test with: 日本語 - should be one word; 6日 - should be one word; 特急はくたか - should be two words.

testing mecab installation

Files setup

  1. Download the latest release from github to e.g. /var/www/lwt
  2. Update permissions: sudo chmod -R 755 /var/www/lwt
  3. Create config file: cd lwt && sudo cp connect_xampp.inc.php connect.inc.php
  4. Edit connect.inc.php and add database details
  5. Install dependencies. This wasn't in the install docs at all, but when I tried to load the /docs/*.md in the browser I was getting 500 internal server error and log messages about not being able to find vendor/autoload.php. Running composer in the install director sorted it out (no idea if this is what I should be doing or not.) Further note - I had to ignore the platform dependencies because the composer.json in the project required PHP 7.4 and my server was running PHP 8: composer install --ignore-platform-reqs
  6. Create the media directory in the root of the lwt directory: mkdir media
  7. Update owner of directory: sudo chown -R www-data:www-data lwt

Nginx configuration

  1. Create a new configuration file: sudo vi /etc/nginx/sites-available/lwt.example.com
  2. Add the following basic config with PHP enabled:
server {
	server_name lwt.example.com;

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

	location / {
		try_files $uri $uri/ =404;
	}

	# pass PHP scripts to FastCGI server
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
		include fastcgi_params;
	}
}
  1. Validate nginx config: sudo nginx -t
  2. Enable site: sudo ln -s /etc/nginx/sites-available/lwt.example.com /etc/nginx/sites-enabled/lwt.example.com
  3. Restart nginx: sudo systemctl restart nginx
  4. Browse to URL on HTTP and check working ok e.g. http://lwt.example.com

Add SSL

  1. sudo certbot --nginx -d lwt.example.com
  2. When prompted 2 to send all HTTP requests to HTTPS

Restrict access

Consider white listing your IP address to stop all and sundry on the internet discovering the installation

  1. Edit the newly created nginx conf file to additionally have the following
	location / {
		allow 44.45.46.47;
		deny all;
		try_files $uri $uri/ =404;
	}

Issues

  1. Adding terms which are found in the text works fine, but I currently get an error trying to "add a new term" not in the text. Something to do with login failing for the user, although everything else works and appears to be using the same credentials.
  2. Show sentences requires a bug fix - parameters round the wrong way
  3. jplayer