Running WordPress in Azure Webapp with Mysql

In August Microsoft launced the preview of Mysql in-app for Azure webapps. This means that you can enable Mysql in your webapp and you’ll get immediate access to a Mysql database within your application. Running WordPress, Joomla or any other PHP/Mysql-based CMS have never been easier. Please note that this is at the moment not for production workloads due to the single-instance database. Read the article for more information at https://azure.microsoft.com/sv-se/blog/mysql-in-app-preview-app-service/.

So how do you get it up and running?

Create a new webapp.

webapp01

Name your webapp and if you don’t have one, create an App Service Plan.

webapp02

Once deployment is finished we need to edit some settings.

Switch to PHP 5.7, and turn off ARR. Click Save.

webapp05

The magic of turning on MySql is up next. Click “on” and if you’re just testing, don’t touch the logging settings. Click “Save”.

webabb06

Now you’ll need to head over to WordPress.org and download the package. Save it on your computer and unzip the files. You’ll also need an FTP client. Assuming you’re running Windows you can grab Filezilla for free.

Edit your deployment credentials if you don’t know then.

webapp04

Check the portal for your FTP hostname and enter the corresponding values in your FTP client.

webapp07

When the upload is done you can use the brand new editor to change wp-config-sample.php.

webapp09

 

You need to delete some code and paste in the following code:

$connectstr_dbhost = '';
 $connectstr_dbname = '';
 $connectstr_dbusername = '';
 $connectstr_dbpassword = '';

foreach ($_SERVER as $key => $value) {
 if (strpos($key, "MYSQLCONNSTR_localdb") !== 0) {
 continue;
 }$connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $value);
 $connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value);
 $connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\\1", $value);
 $connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\\1", $value);
 }

// ** MySQL settings - You can get this info from your web host ** //
 /** The name of the database for WordPress */
 define('DB_NAME', $connectstr_dbname);

/** MySQL database username */
 define('DB_USER', $connectstr_dbusername);

/** MySQL database password */
 define('DB_PASSWORD', $connectstr_dbpassword);

/** MySQL hostname : this contains the port number in this format host:port . Port is not 3306 when using this feature*/
 define('DB_HOST', $connectstr_dbhost);
Remove:
webapp10
Paste the code and save
webapp11
Rename the file wp-config-sample.php to wp-config.php. This can be done in your FTP client.
webapp12
Once done you can click your URL in the portal.
webapp13
If you’ve done everything right so far you’ll see the WordPress installation guide.
Select your language.
webapp14
Enter a username / password.
webapp15
Once it’s done you can visit your site and you’re all done. Now you can apply a custom theme and fill your site with content.
webapp16
Does it work? Well, this site runs in the exact same manner as the guide. So far, so good 🙂

Register resource providers in Azure

These lines of PowerShell will help you register ALL resource providers in Azure in the selected subscription:

# Login
Add-AzureRmAccount

# List subscriptions
Get-AzureSubscription

# Select subscription
Select-AzureSubscription -SubscriptionName “INSERT NAME HERE”

# List all providers and register (if you only want specific ones, you must run commands manually)
$providers = @(Get-AzureRmResourceProvider -ListAvailable)
foreach ($x in $providers) {

Register-AzureRmResourceProvider -ProviderNamespace $x.ProviderNamespace -Force
write-host $x.ProviderNamespace
}
Write-Host “Done!”

Creating a VPN gateway in Azure ARM using PowerShell

Spent a few days at a customer site building stuff. Needed some gateways in ARM (Azure Resource Manager) mode. The code below will create a gateway and all artifacts it depends upon.
Use at your own risk 🙂
# Start here
Login-AzureRmAccount
# Variables
$location01 = “West Europe”
$networkname01 = “AzNet”
$rgname01 = “AzNetRG”
# Azure Network Address Space (/27 for VM use. /29 for gateway use)
# Your Azure network MUST have a subnet named “GatewaySubnet”
# Create your network in the portal, make sure to add all address spaces and subnets before running script. Do NOT forget to add “GatewaySubnet”.
$localSubnets01 = @(“10.1.0.0/27”, “10.1.2.0/29”)
# Remote Network Address Space
$remotenetwork01 = @(“192.168.1.0/24”)
# Remote Network Gateway IP
$RemoteGwIP01 = “8.8.8.8”
# Remote Connection Gateway Name
$RemoteConnectionGwName = “RemGW”
# Remote Connection Name
$RemoteConnectionName = “RemConn”
$VNET01 = Get-AzureRMVirtualNetwork -Name $networkname01 -ResourceGroupName $rgname01
$gwSubnet01 = Get-AzureRMVirtualNetworkSubnetConfig -Name GatewaySubnet -VirtualNetwork $VNET01
# Create a new public IP address.
$gwIP01 = New-AzurermPublicIpAddress -Name ($networkname01 + “-gwip”) -ResourceGroupName $rgname01 -Location $location01 -AllocationMethod Dynamic
# Create VPN gateway configuration.
$gwConfig01 = New-AzurermVirtualNetworkGatewayIpConfig -Name ($RemoteConnectionName + “-gwconfig”) -SubnetId (Get-AzurermVirtualNetworkSubnetConfig -VirtualNetwork $VNET01 -Name GatewaySubnet).Id -PublicIpAddressId $gwIP01.Id
# Create gateway. This will take up to 40 minutes, so be patient.
$gw01 = New-AzurermVirtualNetworkGateway -Name ($networkname01 + “-gw”) -ResourceGroupName $rgname01 -Location $location01 -IpConfigurations $gwConfig01 -GatewayType VPN -VpnType RouteBased -Tag $tags
$localGw01 = New-AzurermLocalNetworkGateway -Name $RemoteConnectionGwName -ResourceGroupName $rgname01 -Location $location01 -GatewayIpAddress $RemoteGwIP01 -AddressPrefix $remotenetwork01
$AzureGW = Get-AzureRmVirtualNetworkGateway -Name ($networkname01 + “-gw”)  -ResourceGroupName $rgname01
$RemoteGW = Get-AzurermLocalNetworkGateway -Name $RemoteConnectionGwName -ResourceGroupName $rgname01
New-AzurermVirtualNetworkGatewayConnection -Name $RemoteConnectionName -ResourceGroupName $rgname01 -Location $location01 -VirtualNetworkGateway1 $AzureGW -LocalNetworkGateway2 $RemoteGW -ConnectionType IPsec -RoutingWeight 10 -SharedKey $sharedKey01
# End here

TechDays 2015 – Pre-conf and Azure Resource Manager

Just got an email confirming mine and Anders Bengtssons pre-conf for TechDays 2015, the “Azure IAAS Ninja Bootcamp”. We’ll teach you as much as you can consume about Azure IAAS during one day! I also got one session on Azure Resource Manager. ARM is by far the biggest leap in producing clean, nicely installed and repetitive environments in Azure. If you’re missing out on PowerShell and ARM along with DSC my guess is that you’ll be doing something else in the future!

Are you going to TechDays 2015 in Sweden?

Check out my sessions here: http://tdswe.kistamassan.se/Program-2015/Talare/(filter)/J

And don’t forget to register: http://tdswe.kistamassan.se/Anmal-dig

Compare installed vs available Microsoft Azure PowerShell versions

When running Microsoft Azure PowerShell certain cmdlets and functions are only available in the latest version of Azure PowerShell. So how do you know if you have the latest version? Well, this snippet will check your currently installed version and then ask the Web Platform Installer for the available version. It’ll then display the version numbers, letting you know if you’re current or not.

Just paste the entire code snippet into your PowerShell-prompt or embed it and just call the function.

— Begin snippet —

function Get-WindowsAzurePowerShellVersion
{
[CmdletBinding()]
Param ()

## - CHECK INSTALLED VERSION
Write-Host "`r`nInstalled version: " -ForegroundColor 'Yellow';
(Get-Module -name "Azure" | Where-Object{ $_.Name -eq 'Azure' }) `
| Select Version, Name, Author | Format-List;

## - CHECK WEB PI FOR AVAILABLE VERSION
Write-Host "Available version: " -ForegroundColor 'Green';
[reflection.assembly]::LoadWithPartialName("Microsoft.Web.PlatformInstaller") | Out-Null;
$ProductManager = New-Object Microsoft.Web.PlatformInstaller.ProductManager;
$ProductManager.Load(); $ProductManager.Products `
| Where-object{
($_.Title -like "Microsoft Azure Powershell*") `
-and ($_.Author -eq 'Microsoft Corporation')
} `
| Select-Object Version, Title, Published, Author | Format-List;
};
Get-WindowsAzurePowerShellVersion

— End of snippet —

Azure PowerShell

SWE: Missa inte Azure pre-conf pÄ TechDays 2015!

Missade du min och Anders Bengtssons fyradagars Azure-workshop? Nu kan du gÄ en heldag i samband med TechDays dÀr vi har kokat ner fyra dagar till en heldag fylld med ytterst lite teori och vÀldigt mycket labbar. Kan du redan allt om Azure finns det fler Àmnen att fokusera pÄ, t.ex. EMS, Office365 eller Datacenter.

LÀs mer pÄ http://tdswe.kistamassan.se/Program-2015/Pre-Conf

 

Sometimes IT works