Search code examples
phpazurephprediskudu

How to load php_redis.dll when running post deployment script in Kudu Console


I have a webapp running on Azure App Service. I am trying to test a Post deployment script in Kudu Debug CMD console.

php -d extension=php_redis.dll -f postdeploy.php

Here is my postdeploy.php file

<?php

ini_set('error_reporting', -1);
ini_set("display_errors", 1);

function exception_handler($exception) {
    echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');

$redis = new Redis();

...

?>

I get the following error

Fatal error: Class 'Redis' not found in D:\home\site\deployments\tools\PostDeploymentActions\postdeploy.php on line 13
PHP Warning:  PHP Startup: Unable to load dynamic library 'D:\Program Files (x86)\PHP\v5.6\ext\php_redis.dll' - The specified module could not be found.
in Unknown on line 0

I uploaded the proper version of php_redis.dll to the PostDeploymentActions folder. This is the same binary that the webapp is using via the app setting in portal PHP_EXTENSIONS = bin\php_redis.dll. However, I am not sure how to load this for this script.

Is there a way that I can load the php_redis.dll in Kudu post deployment script?

I tried php -d extension=./php_redis.dll -f postdeploy.php, php -d extension=%~dp0php_redis.dll -f postdeploy.php and other weird combinations with no luck.


Solution

  • Please try to add the PHP extension via ini settings, refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-enable-extensions-in-the-default-php-runtime at the Configure via ini settings section.

    Generally:

    1. Add an App Setting to your Web App with the key PHP_INI_SCAN_DIR and value d:\home\site\ini
    2. Create an configuration file in d:\home\site\ini called extensions.ini
    3. Add configuration settings to the extensions.ini file using the same syntax you would use in a php.ini file. For example: extension = php_redis.dll.
    4. Restart Web Apps service.

    Via this approach, you can configure the PHP extension into Kudu console site's PHP runtime. And configure via the App Settings will only configure the extension into IIS.

    Any further concern, please feel free to let me know.