Easy way to migrate an existing PHP site with MySQL to Azure App Service.
Published Mar 14 2023 07:06 AM 4,098 Views
Microsoft

In this blog, we will cover the easy way to migrate an existing PHP site with MySQL to Azure App Service.

 

  • 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.
  • During the deployment to install any application dependencies like composer packages add an app setting, SCM_DO_BUILD_DURING_DEPLOYMENT, and setting it to 1.  
  • 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:

vinku85_0-1678793204410.png

 

  • 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.

vinku85_1-1678793204417.png

 

1.png

 

  • 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​

vinku85_3-1678793204430.png

 

  • This should populate all your data from "dump.sql" into the Azure MySQL - Flexible MySQL database over a secure connection.
  • 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
],
);

 

 

Co-Authors
Version history
Last update:
‎Mar 14 2023 05:49 AM
Updated by: