29.5 C
Dubai
Sunday, October 2, 2022
spot_img

Migrate PHP and MySQL Site to Azure App Service


Let’s migrate a Phpmysql site from Godaddy to Azure App Service and Mysql

Go to Marketplace; let’s create a resource group

Web App + Database

Lets use PHP run time stack

It auto-creates MySQL with the wizard with proper private DNS zone

Generated resources after creation

App service is online now

Created Windows 10 VM and Installed SQL Workbench in the same vNet to connect to MySQL and App service FTP easily

You can download SSL and connection information from here.

Connect using MySQL Workbench

Enter the obtained password

Import your old database using .SQL export and import

Choose Target schema

Now DB is imported.

Now you can see Tables have been created.

You can see appropriate tables populated

Let’s load a test PHP file to test DB connectivity , You can see the FTP Credentials

Connect to App Service using FTP

if you are using WinSCP

Placed this file to test mySQL connectivity.

<?php
$servername = "azure365pro-com-server.mysql.database.azure.com";
$username = "izmayfiuav";
$password = "8EHW56653KRSH5MZ$";
$database_name =  "azure365pro-com-database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database_name);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Connection failed: Connections using insecure transport are prohibited while –require_secure_transport=ON.

if you turn off secure transport

if you turn off secure transport

or use SSL from the PHP side (Recommended)

<?php
$servername = "azure365pro-com-server.mysql.database.azure.com";
$username = "izmayfiuav";
$password = "8EHW56653KRSH5MZ$";
$database_name =  "azure365pro-com-database";
$options = array(
    PDO::MYSQL_ATTR_SSL_CA => '/DigiCertGlobalRootCA.crt.pem'
);
// Create connection
$conn = new mysqli($servername, $username, $password, $database_name, $options);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here