LAMP additional php extension - php-mssql

Hi people!

First, thanks for your top work on whole Nethserver 8 project. Special thanks to stephdl, for LAMP.

It is great, but I need an additional php extension. For some hybrid app I need Microsoft Drivers for PHP for Microsoft SQL Server.

So please, can you add php-mssql in next version of lamp?

Thanks a lot.

1 Like

Thanks for the request, and glad LAMP is useful to you.

One naming detail first: php-mssql no longer exists. The ext/mssql extension was removed from PHP in 7.0, so there is no such package for any PHP version LAMP ships (7.4 to 8.5).

Two things replaced it, and they are very different in cost.

pdo_dblib, the FreeTDS based driver, is a single Debian package (php8.x-sybase). Connection string is dblib:host=...;dbname=.... It pulls nothing from outside Ubuntu and weighs a few kilobytes. I can add that to the image.

The actual Microsoft drivers (sqlsrv and pdo_sqlsrv) are another matter. They are not packaged for Debian or Ubuntu, they have to be compiled with pecl, they need Microsoft’s own ODBC driver from Microsoft’s repository under Microsoft’s licence, and the current release requires PHP 8.3 or newer so older LAMP images would need pinned older versions. That means a build toolchain in the image, a third party proprietary repository, and a licence question I have not settled. I would rather not carry that for a single request. If more people need it, we can revisit.

So, before I add anything, I need to know what your app actually calls. A grep in your source is enough:

grep -rn "sqlsrv_\|PDO(\"sqlsrv\|PDO('sqlsrv\|PDO(\"dblib\|PDO('dblib\|odbc_connect" /path/to/your/app

Replace /path/to/your/app with your source directory. It lists every line where the code opens a SQL Server connection. Check the matched lines before pasting here, people often keep the DSN and the password on the same line.

Also useful, your current PHP version and loaded extensions. As root on the node, replacing lamp1 if your instance name differs:

runagent -m lamp1 podman exec apache2-app php -v
runagent -m lamp1 podman exec apache2-app php -m

First line gives the PHP version, second lists the extensions. Nothing sensitive in there.

If your code uses dblib: or generic PDO, the FreeTDS route covers you. If it calls sqlsrv_* or PDO("sqlsrv:...") directly, pdo_dblib will not help and you would need to port those calls to PDO.

Hi Stephane,

Thank you for your quick and kind response.

The application we plan to run on this LAMP stack is quite old and currently runs on PHP 5. Since it will require manual refactoring, I believe the best approach is to use pdo_dblib to handle the necessary MS SQL connection.

Could you please include this module in future image builds?

Thanks again and best regards, Tomaz

really sorry but php5 is not provided with any module, maybe you should fork webserver yourself, or ns8-lamp, do not know, quite sure if you ask to claude it will be done quick

My friends will rewrite the webapp to php8. So the php extension pdo_dblib into LAMP for php8 will be just great.

Thanks!

Here is how I managed it.

For running module:

  1. runagent -m lamp1 podman exec -ti apache2-app bash
  2. apt-get update && apt-get install -y php8.5-sybase && phpenmod pdo_dblib && service apache2 reload

Add then with editing file /home/lamp1/.config/systemd/user/apache2-app.service:

After line ExecStartPost=runagent wait-after-apache, I added this:

  1. ExecStartPost=/bin/bash -c “sleep 3 && /usr/bin/podman exec apache2-app bash -c ‘apt-get update && apt-get install -y php8.5-sybase && phpenmod pdo_dblib && service apache2 reload’”

So it works also after restarting App or Host.

1 Like