Page MenuHomePhabricator

Luasandbox doesnt work with PHP 7.2+
Closed, InvalidPublic

Description

I followed the instructions listed on https://www.mediawiki.org/wiki/LuaSandbox to manually install luasandbox, and it doesn’t seem to work on php 7.2 or php 7.3. When I added extension=luasandbox.so to my php.ini and restarted, in the log I found the below error.

PHP Warning: PHP Startup: luasandbox: Unable to initialize module Module compiled with module API=20160303 PHP compiled with module API=20180731 These options need to match in Unknown on line 0

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Which package (and version) are you using? And where did you install it from?

3.0.3-1~bpo9+1~wmf+php72 works fine (available in the WMF apt repos) works fine

@Reedy I’m not using the apt package. I am using the latest commit on the master branch on github.

Legoktm added a subscriber: Legoktm.

PHP Warning: PHP Startup: luasandbox: Unable to initialize module Module compiled with module API=20160303 PHP compiled with module API=20180731 These options need to match in Unknown on line 0

This means you compiled the module with PHP 7.3, and then are trying to run it with PHP 7.2...that won't work. You need to compile it with the same version of PHP as you plan on running it with. But in any case, luasandbox does work under PHP 7.2 - that much has been pretty well tested.

If you can provide some more details about your setup, and how you installed PHP, we might be able to help you debug.

@Legoktm For that I compiled with php 7.3 and am trying to run on the same version. I used the sury php apt repo.

PHP Warning: PHP Startup: luasandbox: Unable to initialize module Module compiled with module API=20160303 PHP compiled with module API=20180731 These options need to match in Unknown on line 0

This means you compiled the module with PHP 7.3, and then are trying to run it with PHP 7.2...that won't work.

It looks to me like the module was compiled with PHP 7.1 ("Module compiled with module API=20160303") and is being run with PHP 7.3 ("PHP compiled with module API=20180731"). Which won't work either.

@MacFan4000 we doin't use php-luasandbox from sury. We use it from debian's official repo. It seems php-luasandbox is incompatible with php 7.2+ from when i tested it failed to find the luasandbox class.

Paladox reopened this task as Open.EditedJan 17 2019, 5:28 PM

Is there any way to support multiple php versions in luasandbox without needing for it to be recompiled?

Our environment is:

php7.2 from sury running on debian 9.

We use php-luasandbox from debian offical repo:

apt-cache policy php-luasandbox
php-luasandbox:
  Installed: 3.0.3-1~bpo9+1
  Candidate: 3.0.3-1~bpo9+1
  Version table:
 *** 3.0.3-1~bpo9+1 200
        200 http://deb.debian.org/debian stretch-backports/main amd64 Packages
        100 /var/lib/dpkg/status

I got it working on my server and so it does work

You built it though, you didn't install from a precompiled package.

PHP Warning:  PHP Startup: Unable to load dynamic library 'luasandbox.so' (tried: /usr/lib/php/20180731/luasandbox.so (/usr/lib/php/20180731/luasandbox.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/luasandbox.so.so (/usr/lib/php/20180731/luasandbox.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Is there any way to support multiple php versions in luasandbox without needing for it to be recompiled?

No. That's not how PHP modules work. You have to compile the module for each version of PHP you want to support, and install to the correct location (e.g. /usr/lib/php/$APIVersion/luasandbox.so).

If you're building a distribution package you can probably include multiple versions of the module in one package if you want to do it that way. For example, the packages (at least the amd64 version) at https://snapshot.debian.org/package/php-redis/3.1.6-1/#php-redis_3.1.6-1:2b:b1 contain versions of redis.so for PHP 7.0, 7.1, and 7.2. On the other hand, Debian has had separate packages for php7.0-mysql, php7.1-mysql, and php7.2-mysql instead of one that contains all three versions.

php7.2 from sury running on debian 9.

We use php-luasandbox from debian offical repo:

That's not terribly likely to work. Since Debian stretch (and stretch-backports) only has PHP 7.0, the stretch-backports version of php-luasandbox only contains the module compiled for that version.

You can likely just download the package source for php-luasandbox and rebuild it to get a version that will work with your setup. At least, assuming sury provides a "php-dev" package matching the rest of what you have installed from there.

sudo apt-get build-dep php-luasandbox
apt-get source php-luasandbox
cd php-luasandbox-3.0.3/
# Edit debian/changelog if you want to reflect your rebuild
dpkg-buildpackage -b -uc