在 Windows 下将 Lua 沙盒与 MediaWiki 一起使用

Use Lua sandbox with MediaWiki under Windows

我正在 运行 在 Windows 服务器上安装 MediaWiki (1.34.1)。该 wiki 包含一些 Lua 模块,这些模块由 Scribunto 扩展 运行ning Lua 5.1.4 执行。 到目前为止,我正在使用 luastandalone,但我想使用 luasandbox 引擎(应该更快)。

随着最新的PHP luasandbox release 4.0.2 PECL 提供了一个Windows DLL (https://pecl.php.net/package/LuaSandbox/4.0.2/windows).

使用这个 DLL 是否可以在 Windows 下 运行 luasandbox? 我怎样才能在 install/configure PHP/MediaWiki/Scribunto 环境下使用这个 DLL?

是的,可以通过 IIS 在 Windows 下使用 LuaSandbox,实际上这是一种特别方便的方法,您只需安装必要的 Lua 二进制文件作为 PHP 扩展 到您现有的 PHP 解释器(您知道它正在工作,因为 MediaWiki 在 PHP 中实现)。

我在 this conversation on the MediaWiki page Extension Talk:Scribunto 中详细讨论了这个问题,但我也会在这里提供要点:

I did finally get Lua working under IIS on Windows 10, with PHP 8.0. The trick was, I abandoned the luaStandalone binary entirely, and instead downloaded the (just released less than 2 months ago) PHP luaSandbox extension from PECL:

https://pecl.php.net/package/LuaSandbox

Click on "DLL", then choose the build that matches your PHP install (for me it was PHP 8.0, x64, non-thread safe — the details are at the very top of the long, long output of php.exe -i from a command line), and download the provided zip file. After extraction, only two files are important:

  • php_luasandbox.dll, a PHP extension module that goes wherever the rest of your extensions are. (For me, C:\Program Files\PHP\v8.0\ext\.)
  • lua5.1.dll, an embeddable Lua interpreter that gets installed in the directory where the php.exe binary lives. (For me that was C:\Program Files\PHP\v8.0\, the parent directory of the extension location).

After that, just edit your php.ini to add:

extension=php_luasandbox.dll

and edit LocalSettings.php to include:

$wgScribuntoDefaultEngine = 'luasandbox';

(making sure to remove or comment out any lines about luaStandalone).

Relaunch IIS, and that should be that. If you have MediaWiki working at all, you've already got PHP running, so using Lua that way, as a PHP extension, just makes eminent amounts of sense.

正如我在 MediaWiki 讨论中指出的那样,对此存在 一些 程度的争议,因为 Lua 开发人员本身对“沙盒”的概念有点失望Lua”。 They do not believe 它是限制 Lua 访问和消耗系统资源的技术上可行的方法。但是在 Windows 上,他们建议对 standalone 二进制文件施加的大多数限制在 OS 中都不可用,这使得情况更加 confusing/unclear.