Install mosquitto extension for PHP and Apache?

Yup all installed. Re-installed PECL just to make sure.

Basically, I think the mosquitto.so is missing from folder /usr/lib/php/20170718/ - which I don’t really know how to re-install or where to grab a copy from.

Thanks

Is the file not there?

Did you follow the instructions above exactly (I suspect you modified that line, but I’m not one for assumptions)? If so they are for php 7.0 and you have 7.2 so should be…

printf "extension=mosquitto.so" | sudo tee /etc/php/7.2/mods-available/mosquitto.ini 1>&2 sudo phpenmod mosquitto

If that isn’t the problem I’m out of ideas. @pb66 can you help?

The file is in another location, but copying across didn’t work …

$ ls /usr/lib/php/20151012/mos*
mosquitto.so

As @borpin has stated the file should be at /etc/php/7.2/mods-available/mosquitto.ini unless the hierarchy has been radically changed. What do you get in reply to this command?

ls -la /etc/php/*/mods-available/mosquitto.ini

Once that file is present and correct, in the “7.2” folder the module is “known” to php and available to enable.

sudo phpenmod mosquitto

should then enable the module, it does that by creating several symlinks so that the file appears to be in several other locations too, despite there only actually being one copy.

I don’t think that is quite right. The mosquitto.so file is in a similar named folder to @nick in my system (php 7.0).

In the conf.d folder there should be a symlink like
lrwxrwxrwx 1 root root 41 Feb 16 16:17 /etc/php/7.0/fpm/conf.d/20-mosquitto.ini -> /etc/php/7.0/mods-available/mosquitto.ini - I think this is created by the phpenmod command.

I think disable the add in, uninstall it and then reinstall it might be the way forward.

Are the file permissions on the mosquitto.so file as the rest of the directory?
Did you install mosquitto any other way?

Searching on Google with the error as the search term throws up a number of answers.

Well, I tried reinstalling libmosquitto-dev, but no luck still.

$ ls /etc/php/7.2/apache2/conf.d/20-mos* -lah
lrwxrwxrwx 1 root root 41 Aug 16 17:08 /etc/php/7.2/apache2/conf.d/20-mosquitto.ini → /etc/php/7.2/mods-available/mosquitto.ini

$ ls /etc/php/7.2/cli/conf.d/20-mos* -lah
lrwxrwxrwx 1 root root 41 Aug 16 17:08 /etc/php/7.2/cli/conf.d/20-mosquitto.ini → /etc/php/7.2/mods-available/mosquitto.ini

$ ls /etc/php/7.2/mods-available/mosquitto*
/etc/php/7.2/mods-available/mosquitto.ini

$sudo php phpmqtt_input.php
PHP Warning: PHP Startup: Unable to load dynamic library ‘mosquitto.so’ (tried: /usr/lib/php/20170718/mosquitto.so (/usr/lib/php/20170718/mosquitto.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mosquitto.so.so (/usr/lib/php/20170718/mosquitto.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Fatal error: Uncaught Error: Class ‘Mosquitto\Client’ not found in /var/www/html/emoncms/scripts/phpmqtt_input.php:105

I suspect the extension doesn’t yet support PHP 7.2.

The last changelog only announces provisional support for PHP 7.0

GitHub - mgdm/Mosquitto-PHP: A wrapper for the Eclipse Mosquitto™ MQTT client library for PHP.

PECL :: Mosquitto Changelog

/usr/lib/php/20170718/ is PHP 7.2’s location, If the extension is still installing to /usr/lib/php/20151012/ which is the PHP7.0 location it is most likely oblivious to PHP 7.2.

The jump from 5.6 to 7.0 is only just gathering speed, trying to use 7.2 will no doubt uncover many quirks, is there a reason you need 7.2, unless it’s changed in the last 2 month’s, 7.0 is the default for 16.04. which ASAIK is still the mainstream “latest” release, I know 18.04LTS is released, but it’s not yet the default “current version”.

1 Like

Oh, damn. Yeah, I did a dist-upgrade to Ubuntu 18.04.1 LTS …

I always like to push the boundaries :slight_smile:

Well both go out of security support at the end of this year so they need to get a wiggle on.

http://php.net/supported-versions.php

2 Likes

You could try the manual install method on the GitHub readme.
[edit]
Reading this page PHP: Compiling shared PECL extensions with phpize - Manual, the second comment seems to imply that simply moving the .so file should work.

moving it failed, I seem to remember…

PHP Warning: PHP Startup: mosquitto: Unable to initialize module
Module compiled with module API=20151012
PHP compiled with module API=20170718
These options need to match
in Unknown on line 0

OK, time to understand the rebuild method.

Any ideas?

https://twitter.com/elyob/status/1031962016326529024
“Did you recompile the extension? An ext built for a given minor version is locked to that release branch.”

Can anyone explain the home path?

Looking at the readme;

It suggests you can just use phpize to rebuild the extension.

Just try those commands?

Sure, but I have no idea where the top level source directory of the module is …

“Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module”

(blind leading blind here…)

Do a git pull on that repo so you have the source files? Just a guess.

Had a look at this quickly - might help. https://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/#Heading7

Once you have created the extension with the right PHP version you should be able to just copy it across.

I’ve only ever used phpize the once so don’t take this as gospel.

I think you can clone the repo anywhere, then cd in and run phpize from within that repo. I believe it will find your php config and use that to compile the extn into place.

Then you just do the usual (as per the OEM guide) to enable it but using “7.2” not “7.0”.

Cloned and ran phpize etc … unfortunately the last message is
“$ sudo make install
Installing shared extensions: /usr/lib/php/20151012/”

So, still the same issue.

$ sudo php phpmqtt_input.php
PHP Warning: PHP Startup: mosquitto: Unable to initialize module
Module compiled with module API=20151012
PHP compiled with module API=20170718

2 suggestions found (sorry I cannot test them).

First suggestion I found was to check is what API version is phpize using? Does phpize -v match the old or the new?

Another is to run phpize --clean and the final one is to bump the version for the extension (I’m guessing in the package.xml file).

(still the blind leading etc…)

mosquitto_php.txt (13.1 KB)

Well, I’m really getting nowhere. Despite phpize seems to be configured okay?

PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718

I removed PHP 7.0 which was on the machine (PITA, as loads of stuff disappeared too and my main site is having issues still!)