In this blog, we will cover the easy way to migrate an existing PHP site with MySQL to Azure App Service.
- In case you do not have an existing App Service and Azure Database for MySQL setup, you can follow this blog: Tutorial: PHP app with MySQL - Azure App Service | Microsoft Learn.
- This setup will create a VNET and MySQL database where the MySQL access will be locked down and not exposed to the public internet, which is compliant with recommended best practices for security.
- To migrate your PHP code to Azure App Service, we can use one of the deployment methods such as Zip Deploy: Run your app from a ZIP package - Azure App Service | Microsoft Learn
- During the deployment to install any application dependencies like composer packages add an app setting,
SCM_DO_BUILD_DURING_DEPLOYMENT
, and setting it to1
.
- To migrate the MySQL database, we can use the Azure App Service Kudu console.
- The easiest way to get to the Kudu console would be to go directly to http://yoursitename.scm.azurewebsites.net/newui (replace "yoursitename" with your actual Web App name) through the browser. You can also launch the Kudu console from the Azure portal:
- Select "File Manager" and drag or upload the "dump.sql" file to the /home/site directory and the certificate needed to communicate over SSL, which you can get from the Azure Portal.
- Select "WebSSH" and go to /home/site, run the below command to import the sql dump after replacing Username, Password, Hostname, port (which is 3306 by default), and destination database name:
mysql -h Hostname -u Username -p --ssl-ca=/home/site/DigiCertGlobalRootCA.crt.pem destination_database_name < dump.sql
- This should populate all your data from "dump.sql" into the Azure MySQL - Flexible MySQL database over a secure connection.
- To establish a secure connection to Azure Database for MySQL over SSL from your application, refer to the following code samples: Configure SSL - Azure Database for MySQL | Microsoft Learn
- For a Drupal application secure database connection, use the below code:
$databases['default']['default'] = array (
'database' => 'quickstartdb',
'username' => ‘myadmin@mydemoserver,
'password' => ‘yourpassword',
'prefix' => '',
'host' => 'mydemoserver.mysql.database.azure.com ',
'port' => '3306',
'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
'driver' => 'mysql',
'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
'pdo' => [
\PDO::MYSQL_ATTR_SSL_CA =>'/home/site/DigiCertGlobalRootCA.crt.pem',
\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
],
);
- To modify the existing NGINX site configuration, please refer to: NGINX Rewrite Rules for Azure App Service Linux PHP 8.x - (azureossd.github.io)
Updated Mar 14, 2023
Version 1.0vinku85
Microsoft
Joined March 07, 2023
Apps on Azure Blog
Follow this blog board to get notified when there's new activity