Installing libonig4 from source to fix php7.4-mbstring
I have several Raspberry Pis. The one I'd like tot alk about today though is a 3B+, and for 1 reason or another it has PHP installed on it with the excellent deb.sury.org apt PPA for PHP. Recently, I've upgraded to PHP 7.4. This was fine initially, but soon enough I started to get a warning that
php-mbstring couldn't be installed and that I have
held broken packages.
This was not a good sign, but after doing some digging it transpired that the package
libonig4 was missing - and couldn't be installed because it wasn't available in the Raspbian apt repositories. Awkward.
After doing some quick digging into the Ubuntu apt repositories, I discovered that while it does exist, it isn't built for
armhf (the architecture of the Raspberry Pi).
Thankfully though, Ubuntu is open-source - so the source package was available. The Debian tooling makes it relatively easy to build source packages once downloaded too. Unfortunately I couldn't use the
apt-get source command to download it as I didn't have an Ubuntu machine to hand, but their website makes it easy to download packages:
On here, you'll want to download the 3 source package files:
Download them to a new directory. Then, extract the source files like so:
cd path/to/directory; dpkg-source -x *.dsc;
cd into the created directory, and build the source files into a bunch of
cd libonig-6.7.0/; dpkg-buildpackage --no-sign;
--no-sign there is necessary, because otherwise I encountered errors where it tried to automatically sign the resulting package with the original author's secret key, which we obviously don't have access to!
Once done (it might make a moment), a bunch of
.deb files will be generated in the parent directory:
||The actual package itself|
||Debugging symbols generated in the build process|
||Development headers (in case you need to build another package against it)|
Out of these 3, the top and bottom ones are probably the ones you want to install. This can be done like so:
sudo dpkg -i libonig4_6.7.0-1_armhf.deb; sudo dpkg -i libonig-dev_6.7.0-1_armhf.deb;
This completes the process. Now, we can install
php7.4-mbstring as normal:
sudo apt install php7.4-mbstring
Success! This should solve the problem. I figured this out in part by following a Unix Stackexchange answer that I have since lost, but I had to adapt the instructions significantly - so I decided to blog about it here.
Found this useful? Still encountering issues? Comment below!