Multiple OCI8 and PHP versions in parallel

You can easily switch between multiple versions of PHP with:

sudo a2disconf php8.1-fpm
sudo a2enconf php8.0-fpm
sudo systemctl reload apache2

But if you installed the Oracle oci8 extension, you will probably run into the error, that it can not be loaded when switching to the older php version: Unable to load dynamic library 'oci8.so'

This happens, because pecl uninstalls the previous oci8 version automatically unless you explicitly say not to do so when installing:

# NOTE: PECL removes /usr/lib/php/xyz/oci8.so from non-active php versions,
# if you want multiple installations of php with oci8 in parallel, you need to set the php_suffix and prevent other oci8 version from being uninstalled with:
sudo pecl -d php_suffix=8.1 install oci8; sudo pecl uninstall -r oci8
sudo pecl -d php_suffix=8.0 install oci8-3.0.1; sudo pecl uninstall -r oci8

# instead of just installing latest version with
sudo pecl install oci8

Black screen after updating nvidia driver

Updating the nvidia-driver on Linux (Mint) can lead to a black screen after boot. Here is how you can quickly revert to the previous working version:

Press Ctrl + Alt + F1 and log into a the virtual console with your username and password (If that does not work, boot first into recovery mode, then resume boot and then log into the console):

# list available nvidia drivers
$ ubuntu-drivers devices

# install last working driver from the list
$ sudo apt install nvidia-driver-520

How to use a YubiKey for two-factor autenthication on Linux Mint

This post will show you how to setup and use a YubiKey and the Yubico Authenticator application to sign in to a Microsoft Azure Cloud Account using Linux Mint 20 without the need for the Microsoft Authenticator being installed on your mobile phone:

Yubico Authenticator desktop installation

1. Download and install the Yubico Authenticator AppImage:

# install dependency first
$ sudo apt install pcscd
$ sudo systemctl enable --now pcscd

# download latest version with curl
$ cd  ~/Downloads
$ curl -L -O -J https://developers.yubico.com/yubioath-desktop/Releases/yubioath-desktop-latest-linux.AppImage

# make executable
$ chmod +x yubioath-desktop-latest-linux.AppImage

# extract icon, which we can use for the menu item below
$ cp yubioath-desktop-latest-linux.AppImage temp.7z
$ file-roller --extract-here temp.7z 

# move to /opt/yubico
$ sudo mkdir /opt/yubico
$ sudo mv yubioath-desktop-latest-linux.AppImage /opt/yubico/
$ sudo mv temp/com.yubico.yubioath.svg /opt/yubico/
Continue reading “How to use a YubiKey for two-factor autenthication on Linux Mint”

Docker: How to install the php enchant extension

If I try to install the php enchant extension in the docker image php:8.1-fpm with

RUN docker-php-ext-install enchant

I get the following error:

E: Unable to locate package libenchant-2

You need to install the missing enchant library in the dockerfile yourself (along with your wanted spellcheck language, in my case Swiss German):

RUN apt-get install -y libenchant-2-2 libenchant-2-dev aspell-de hunspell-de-ch \
   && docker-php-ext-install enchant

How to get the version of a module from its package.json

node.js < 12

VERSION=$(node -p "require('some-module/package.json').version")

Continue reading “How to get the version of a module from its package.json”

How to Install the CnCNet Client on Linux

If you want to play the classic Games Red Alert 2 and Red Alert Yuri’s Revenge with multiplayer support on Linux (or other old Command and Conquer Games), you need to download and install the CnCNet Client. Here are the instructions on how to get CnCNet 5 working under Linux using Wine.

Screenshot of a wine virtual desktop running Command & Conquer Yuri’s Revenge modded with the CnCNet 5 Client v 8.8.1 on Linux Mint 20.2
Continue reading “How to Install the CnCNet Client on Linux”

How to install SpectraView II on Linux (Mint 20)

NEC (now Sharp) provides a Linux Version of SpectraView II and a corresponding installation guide. Unfortunately, both are pretty outdated. They reference Ubuntu 14 as the latest version 🙁 . Even worse, the application depends on some Qt4 packages which are no longer available in a current Ubuntu/Mint installation. After digging around the internet I found help in the UbuntuHandbook on how to install the missing Qt4 libraries and I was able to successfully install SpectraView II and calibrate my Monitor NEC MultiSync PA32 with the colorimeter X-Rite i1Display Pro on Linux Mint 20.2

Linux Mint 20 running SpectraView II with a X-Rite i1Display Pro connected via USB
Continue reading “How to install SpectraView II on Linux (Mint 20)”

Using a Wacom pen tablet inside VirtualBox 6

I have the tablet wacom intuos pen & touch small CTH-480, which I wanted to use for photo editing in Adobe Lightroom. Since I work under Linux Mint 20, I have a virtual machine running Windows 10 and Lightroom Classic 10. Unfortunately, I got the pen to work as a mouse only by disabling it as an input device, which prevents the buttons from being configurable in the Wacom Desktop Center app.

Screenshot showing the Devices menu of VirtualBox. To use the pen as a mouse, I needed to disable the Wacom tablet in the USB settings. Unfortunately, this prevents detection by the Wacom Desktop Center app and as a consequence the buttons on the tablet can’t be configured.

If I turn the tablet in the USB settings on, the Wacom Desktop Center properly detects the tablet, but movements of the pen are not translated into mouse pointer movements.

Quick Tip: Access Oracle LOB directly from PHP

Access the data from a clob/blob field without having to call OCI-Lob->load() first

When you fetch (binary) data from an Oracle database field of type BLOB or CLOB with OCI8, the (binary) large object is normally returned as LOB descriptor (an instance of the OCI-Lob class). To retrieve the data, you have to call the object’s load or read method, e.g.:

// load and render an image from an oracle database
$sql = 'SELECT myBlob FROM myTab WHERE id = :imgId';
$stmt = oci_parse($dbHandle, $sql);
oci_bind_by_name($stmt, ':imgId', $imgId, 3, OCI_B_INT);
oci_execute($stmt);
$record = oci_fetch_array($stmt, OCI_ASSOC);
$photo = $record['MYBLOB']->load();
header('Content-Type: image/jpeg');
echo $photo;

The call to the load() method can be omitted by passing the constant OCI_RETURN_LOBS to the fetch method, e.g.

...
$record = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_LOBS);
header('Content-Type: image/jpeg');
echo $record['MYBLOB'];

Note: When using oci_fetch_all() lobs are loaded implicitly without having to pass the flag OCI_RETURN_LOBS.

PHP and SQLite FTS4: How to process the matchinfo function part II

Understanding the output from the matchinfo() function

Part I: Reading the binary output from the matchinfo() function

To analyze what the output of the matchinfo() function means, we’ll use a different example dataset than the one from the SQLite FTS4 documentation. Since I’m a bird photographer, let’s create a virtual FTS4 table holding information about photos of birds. It consists of the five columns id, title, description, species and common name (note: id is the image id and not the FTS4 rowid). Then we fill the table with four records making up our example data:

// create the example database
try {
  $db = new PDO('sqlite:example.sqlite');
} catch (PDOException $error) {
  echo $error->getMessage();
}

// create a virtual fts4 table and populate it with example data
try {
  $db->exec("CREATE VIRTUAL TABLE images USING fts4(imgId, title, description, species, speciesEn);
    INSERT INTO images VALUES(1, 'Great Spotted Woodpecker', 'A great spotted woodpecker with a caterpillar in its beak.', 'Dendrocopos major', 'Great Spotted woodpecker');
    INSERT INTO images VALUES(2, 'Woodpecker at the pond', 'A green woodpecker drinks water.', 'Picus viridis', 'Green Woodpecker');
    INSERT INTO images VALUES(3, 'Woodpecker', 'A middle spotted woodpecker is looking for food on an oak tree.', 'Dendrocopos medius', 'Middle Spotted Woodpecker');
    INSERT INTO images VALUES(4, 'Woodpecker', 'A lesser yellownape showing its green wings.', 'Picus chlorolophus', 'Lesser Yellownape');");
} catch (PDOException $error) {
  echo $error->getMessage().'<br>';
}
Continue reading “PHP and SQLite FTS4: How to process the matchinfo function part II”