{"id":15425241,"url":"https://github.com/msimecek/webapps-php-mysql-redirect","last_synced_at":"2025-03-13T14:15:55.638Z","repository":{"id":95299289,"uuid":"317170060","full_name":"msimecek/WebApps-PHP-MySQL-Redirect","owner":"msimecek","description":"Setting up the Redirect functionality for Azure MySQL/MariaDB and PHP on Azure Web Apps. Using the mysqlnd_azure driver.","archived":false,"fork":false,"pushed_at":"2020-11-30T10:48:25.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T09:49:36.650Z","etag":null,"topics":["prototype"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msimecek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-30T09:17:12.000Z","updated_at":"2022-03-18T17:11:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"8db3b7f9-1bdc-4faf-88cd-63045455640c","html_url":"https://github.com/msimecek/WebApps-PHP-MySQL-Redirect","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"93405d51652d0d4b55d04d8811f30463386b0b8b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msimecek%2FWebApps-PHP-MySQL-Redirect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msimecek%2FWebApps-PHP-MySQL-Redirect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msimecek%2FWebApps-PHP-MySQL-Redirect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msimecek%2FWebApps-PHP-MySQL-Redirect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msimecek","download_url":"https://codeload.github.com/msimecek/WebApps-PHP-MySQL-Redirect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243419127,"owners_count":20287806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prototype"],"created_at":"2024-10-01T17:50:32.973Z","updated_at":"2025-03-13T14:15:55.607Z","avatar_url":"https://github.com/msimecek.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure Redirect for Azure MySQL/MariaDB on Linux Azure Web Apps PHP 7.4 without Docker\n\nThis approach is using the mysqlnd_azure.so extension to enable the [redirection functionality](https://docs.microsoft.com/azure/mariadb/howto-redirection) on Azure MySQL/MariaDB instance.\n\n1. Build the *mysqlnd_azure.so* binary with `make` (using Docker container or locally). You can follow [these steps](https://github.com/microsoft/mysqlnd_azure#step-to-build-on-linux).\n\n    ```bash\n    # Using the appsvc/php:7.4-apache_20200522.6 Docker image.\n    apt install git -y\n    git clone https://github.com/microsoft/mysqlnd_azure --depth 1\n    cd mysqlnd_azure\n    phpize\n    ./configure\n    make\n    # If successful, the binary will be in ./modules/mysqlnd_azure.so.\n    ```\n\n    1. Extract the binary from the container (if using Docker): `docker cp \u003ccontainer_id\u003e:/home/mysqlnd_azure/modules/mysqlnd_azure.so \u003cdest_path\u003e`.\n\n1. Add the newly created binary to your project (for instance to a `./bin` folder).\n1. Create a configuration INI file (for instance in an `./ini` folder).\n1. Add the following to the file:\n\n    ```ini\n    extension=/home/site/wwwroot/bin/mysqlnd_azure.so\n    mysqlnd_azure.enableRedirect = on\n    ```\n\n1. [Change the INI scan directory](https://docs.microsoft.com/azure/app-service/configure-language-php?pivots=platform-linux#customize-php_ini_system-directives) for your Web App.\n\n    ```bash\n    az webapp config appsettings set --name \u003capp-name\u003e --resource-group \u003cresource-group-name\u003e --settings PHP_INI_SCAN_DIR=\"/usr/local/etc/php/conf.d:/home/site/wwwroot/ini\"\n    ```\n\n    \u003e Note: This is a simplistic approach. Microsoft documentation recommends creating the `ini` folder outside of `wwwroot` using SSH.\n\n1. Push to the repo and deploy the app.\n1. Don't fogert to change the `redirect_enabled` setting to *ON* on you Azure MySQL/MariaDB instance.\n\nThe directory structure then can look like this:\n\n```\n|- bin\n  |-mysqlnd_azure.so\n|- ini\n  |-mysqlnd_setting.ini\n|- index.php\n```\n\nFinally, test the connection via PHP:\n\n```php\n\u003c?php\n// Based on: https://docs.microsoft.com/azure/mariadb/howto-redirection\n\n$host = getenv(\"DB_HOST\");\n$username = getenv(\"DB_USERNAME\");\n$password = getenv(\"DB_PASSWORD\");\n$db_name = getenv(\"DB_NAME\");\n\necho \"mysqlnd_azure.enableRedirect: \", ini_get(\"mysqlnd_azure.enableRedirect\"), \"\\n\";\n$db = mysqli_init();\n\n//The connection must be configured with SSL for redirection test\n$link = mysqli_real_connect ($db, $host, $username, $password, $db_name, 3306, NULL, MYSQLI_CLIENT_SSL);\n\nif (!$link) {\n    die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . \"\\n\");\n}\nelse {\n    echo $db-\u003ehost_info, \"\\n\"; //if redirection succeeds, the host_info will differ from the hostname you used used to connect\n    $res = $db-\u003equery('SHOW TABLES;'); //test query with the connection\n    print_r ($res);\n    $db-\u003eclose();\n}\n?\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsimecek%2Fwebapps-php-mysql-redirect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsimecek%2Fwebapps-php-mysql-redirect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsimecek%2Fwebapps-php-mysql-redirect/lists"}