Blog Post

Apps on Azure Blog
2 MIN READ

Easy way to migrate an existing PHP site with MySQL to Azure App Service.

vinku85's avatar
vinku85
Icon for Microsoft rankMicrosoft
Mar 14, 2023

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:

 

  • 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.
  • 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
],
);

 

 

Updated Mar 14, 2023
Version 1.0
No CommentsBe the first to comment