Using MS Open Tech to Quickly Build Your Virtual Machine

Azure Marketplace is a great place to start your search for a Virtual Machine to start building your app or infrastructure on. However, these VM’s are sometimes vanilla and will need to be configured to your liking. Let’s use Rails as an example. In order to get a Rails app on a Virtual Machine there are a bunch of steps you will need to perform. First, create the operating system VM, Linux. Make sure that is up to date (sudo apt-update). Then you need to install Rails, Nginx, Unicorn, some sort of database like Postgres and dont forget permissions and users.

Having a custom install is cool but sometimes the situation does not call for that. There is MS Open Tech for that.

msopen

Microsoft Open Technologies, Inc., (MS Open Tech) is a wholly owned subsidiary of Microsoft Corporation to advance Microsoft’s investment in openness including interoperability, open standards and open source.

At MS Open Tech, we focus on providing our customers with even greater choice and opportunity to bridge Microsoft and non-Microsoft technologies together in heterogeneous environments. We believe that openness is good for our customers, good for the community and good for our business.

We’re a diverse team of engineers, standards professionals and technical evangelists who are experienced and passionate in working with an equally diverse set of technologies from Microsoft and others.

Every day, we are powering interoperability and opportunity across developers, partners, customers and competitors.

We build open source code. We create interoperability bridges. We contribute open standards specs. We work with a variety of standards organizations such as: W3CIETFOASISEcmaDMTF, and open source communities including: JQueryMongoDB,Apache CordovaRedisApache, Qpid.NET Foundation, OpenJDKEclipseNode.jsCocos2d,  Web Platform DocsSymfony, DoctrineWebKitGitHubCodePlex and more.

Our team works closely across Microsoft business groups to support our customers’ journey in a mobile first, cloud first world.

As a result, you can do more and achieve more with the openness of the Microsoft platform.

  • You can build with the tool of your choice.
  • You can work across platforms.
  • You can collaborate through code.

There are Projects that MS Open Tech builds, HTML5 Labs that contributes to the Edge platform and VM Depot where a community managed repository of Linux and FreeBSD virtual machine images for easy deployment to Microsoft Azure reside.

You can search for a open source product or platform and most likely there is an image that is ready to go and deploy. Let’s use WordPress as an example.

  1. Search for WordPress and you will see a listing of results.
  2. Choose the result that best fits your need.
    wpubu
  3. Click on Create Virtual Machine (or if you are familiar with PowerShell you can get a deployment script)
  4. Login to the MS Open Tech website using one of the 3 Authentication methods.
  5. You can fill out the minimum to create an account on the MS Open Tech site.
  6. Accept the T&C and Click Save
  7. The next step is to link your Azure account with MS Open Tech to create the deployment. If you have your publication file you can upload it, otherwise you can click the Azure Publish Settings link within the copy and it will download one for you (as long as you are currently logged into the Azure portal).
  8. Once downloaded, you can now upload it to the site.
  9. Once that is connected, you now can configure some of the VM settings. DNS Name, Username/Password as well as region, storage accounts and endpoints.
  10. Once you are happy with your configuration, click I agree and Create VM. It should take a few minutes and your new VM will show up in your Azure portal.
  11. One thing to note. If you choose a VM with configured software you might need to read the README to find out usernames and passwords to certain products.

 

Library of Congress

Managing ConnectionStrings and Environment Variables with WordPress on Azure

One of the cool features of Azure is the ability to have a “deployment slot” for your web app.  Web app content and configurations elements can be swapped between two deployment slots, including the production slot. Deploying your application to a deployment slot has the following benefits:

  • You can validate web app changes in a staging deployment slot before swapping it with the production slot.
  • Deploying a web app to a slot first and swapping it into production ensures that all instances of the slot are warmed up before being swapped into production. This eliminates downtime when you deploy your web app. The traffic redirection is seamless, and no requests are dropped as a result of swap operations. This entire workflow can be automated by configuring Auto Swap when pre-swap validation is not needed.
  • After a swap, the slot with previously staged web app now has the previous production web app. If the changes swapped into the production slot are not as you expected, you can perform the same swap immediately to get your “last known good site” back.

As a web developer, this makes your life easy. Production and Staging can be exactly the same. How many times have you used a staging environment that was a different  OS version than production. “It works on staging but not on production” is the common quote.

When I’m told that my code is broken in production

Setting up deployment slots are pretty straightforward. You can read more about them on this Azure post. However, how do you handle the environment variables for each slot? I need my production code to access my production database.

There are 3 ways that this can be accomplished.

1. The RCP Way

The RCP Way stands for Rename, Copy and Paste. You would rename your connection string or variable file to connstring.stage or connstring.prod and then copy and paste the appropriate values in them. Works fine. However, when deploying from Git or some version tracker can get a bit tricky.

2. The If Then Way

IF “Production” THEN production values ELSE staging values. You can either get the ip address, domain name, server name or even a boolean value that if it signals that you are on production you load in the production values. This works fine but now your one file has 2 or more sets of variables that will need to be maintained.

3. Environment Variables

This is part of Azure which makes deployment slots work so well. I configure my values within Azure per environment. This way my code does nto have to have any usernames or passwords just the variables to store them in.

I am going to show a quick example of how to set up your WordPress Blog using the connection string variables within Azure. This can be applied to any application but I will use WordPress as the default.

Step 1. Create your web app.

I am not going into detail on how to create a wordpress web app but you can follow this tutorial to get that up and running.

Step 2. Find your connection string

This can vary. You might have a Virtual Machine that is custom hosting your database or you might use the default database within Azure. Either way finding your connection string can be done by determining the Username for the DB. the Password for the DB. The data source and DB name. You can also get this info from the wp-config.php file within your root of your WordPress website. You might want to look in there since we will be modding that file in a moment.

Step 3. Build your string

Once you have those 4 parts you can build together your connection string. Your string can look like this.

Step 4. Add your string to the portal

Go into your web app and choose All Settings then Application Settings.

Application Settings

The Application Settings blade will appear. Scroll down a bit until you see the section called “Connection Strings”.

There are 4 form elements that you can configure.

  • Name: This is your name of your connection string. MyClientDB or AnalyticsDB as examples. Whatever you name it, Azure will add a prefix to it that I will explain in a moment.
  • Value: This is your value. You connection string. See step 3.
  • Type: You can choose Custom, SQL Server, SQL DB or MySQL. When you choose any of these Azure appends the following text to the front of your “name”
    • SQL Server: SQLCONNSTR_
    • MySQL: MYSQLCONNSTR_
    • SQL Database: SQLAZURECONNSTR_
    • Custom: CUSTOMCONNSTR_

Note:

For .NET apps, these connection strings are be injected into your .NET configuration connectionStrings settings at runtime, overriding existing entries where the key equals the linked database name.

For PHP, Python, Java and Node applications, these settings will be available as environment variables at runtime, prefixed with the connection type. 

Now if I need to access my MySql connection string called MyClientDB, it would be accessed through the environment variable MYSQLCONNSTR_MyClientDB.

I then can create a deployment slot with the same connection string “name” but different values and my code will use those values to connect to staging or production data.

You can see how this would be valuable when you are moving from dev to test to prod. You can also use App Settings to store “app specific” data in there as well per environment.

Step 5. Update our WordPress

Remember I said we are going to need that wp-config.php, well if it is open great, if not please open it in your favorite code editor, mine is Visual Studio Code, a free download and works great.

The first couple of lines are comments but then there are a few “define” constants that the application will use.

Your file might have actual data in your file but that is fine. We will be replacing that with the values from our environment variable that we just created in Azure. To access it’s data you can call the get_env function to retrieve it.

At this point you have your connection string and you can $echo it out to see what comes back. To make it a bit easier to get each element of the connection string you can add this function to the top of the wp-config.php file.

This is a handy little function that coverts a string into an array with a predefined delimiter.

You can var_dump the returned value to see what is returned.

Then you can replace the 4 defined constants with the following:

Done!

Now you can deploy stage and prod and have your WordPress blog access different databases very easily.

Here is the link to the full file on GitHub

Open Source on Azure

Get Your Startup Running on Azure Using Open Souce and More!

When you hear the words “Microsoft Cloud” or “Microsoft Azure” do you think of the Microsoft Stack? All apps running .NET and Microsoft Windows Server? It can be. But it does not have to be. Ranging from PHP Websites to full Linux VM’s, Azure has plenty for your business or startup.

This is a round up of a few quick starts to get you up and running on Azure and using open source technologies.

Step 1: CloudDev Camp

To get going a good place to start is with the the CloudDev Camp. This is a few step learning plan that goes over the big areas to use the Azure platform for your startup. There are a bunch of tutorials focused around Microsoft, however, module 7 is a great session on Azure and the Open Source cloud services. Give the full course a look, you can perform many features using services rather than spinning up virtual machines for everything.

Step 2: Deploying Linux VM’s

Once you have the solid foundation of the cloud platform, you can jump right in to getting your envrionment set up.  Learn about the offerings that Microsoft has made available for Linux and FreeBSD-based IaaS solutions running in Microsoft Azure. Already setup with Linux or VM’s somewhere else? Learn hou you can migrate your existing Linux-based IaaS solutions from your private cloud to Azure.

Step 3: Open Source DB

Setting up a database is just not the ending but the begining. Learn the performance of how a database is impacted by the performance of the underlying resources. To reach optimal performance, cloud environments require the consideration of several constraints, unlike private datacenters.

Step 4: Networking Fundamentals

Technically this might be step 1 or step 2 (depending upon your solution). At some point you are going to want to learn how to network and commnicate between services and Virtual Machines. This course gets you going.

Step 5: Pick your focus

Now that you have a good fundamentals of what can be set up or consumed on Azure you can now focus on what your app or startup does best.

PHP for Azure

Check out one of the most popular server side scripting languages, the easy-to-learn PHP, which is used in many blogging platforms. Hear about the history of PHP, explore its pros and cons, and take a look at configuration and debugging

Java on Microsoft Azure

Curious about what Microsoft has to offer the Java community? You might be surprised! Join us to explore the latest tools and technologies to help Java developers get in the cloud with Microsoft Azure, like plug-ins for Eclipse and IntelliJ, along with a look at options in Windows and Linux for authentication, security, and continuous integration (CI).

A MongoDB Jump

Wondering what the buzz is all about with NoSQL? If you’re an open source developer and you want to store unstructured data, see why MongoDB, a scalable document-oriented database, is so popular in this arena, plus explore how to use it on Azure. Learn how to set up MongoDB and how to load data in bulk, do simple queries, scale for data with sharding, and much more. Experts Steven Edouard and Rami Sayar show you how easy it is to get up and running, as they explore NoSQL, Documents, Map Reduce, and scaling via C# and Node.js. Check out this course, watch some cool demos, and see if MongoDB is for you!

Building Apps with Node.js

In this course see step-by-step demos and get practical tips and detailed explanations. By the end of the day, you know how to set up Node.js on your Windows machine, develop a web front end with Express, deploy an Express app to Azure, use Socket.IO to add a real-time layer, and bring it all together

MEAN Stack Jump Start

Want to build scalable web apps quickly and easily? Check out the MEAN stack, a collection of technologies (MongoDB, Express, AngularJS, and Node.js) that fit well together to provide a solution that allows for a full-stack JavaScript implementation of web applications. Popular experts Helen Zeng and Steven Edouard walk you through MEAN and create “Chirp,” a Twitter clone. They integrate MongoDB into a REST API with Node.js and Express and then connect that with an AngularJS front end. They even deploy the live app to Microsoft Azure via GitHub. Check out this practical primer on MEAN, and learn to build an end-to-end web app, all using JavaScript.

Mobile Apps to IoT: Connected Devices

With the incredible growth of devices and the Internet of Things (IoT), you know that mobile apps present a huge opportunity. Windows Azure Mobile Services lets you build a back end for your mobile apps in minutes

Migration of AWS to Azure

If you fell in love with Azure (which I am sure you did by now) you might want to move some of your existing VM’s on over. This module does that.

Embrace Open Source Technologies to Accelerate and Scale Solutions

This module focuses on open source technologies on Azure. Walk with engineers through how to best deploy and manage a Linux environment with tools you know and use today. Learn how to use your existing Chef and Puppet configurations and how to scale new ones to massively scale and deploy your solution. Wrap the day with a look at the new capabilities of containerization with Docker.

Exploring Microservices in Docker

Enjoy updating monolithic applications? Probably not! Take an in-depth look at a different way to architect that can help you update your site in milliseconds. Microservices, supported by Microsoft Azure and offered as a service, are highly scalable, resilient, and composable units of deployment for modern applications. Self-contained for fit and purpose, they are a key part of the world of continuous delivery and DevOps.

Linux Powered By Azure – 5 Part Series

If you are a modern day developer you do not have the luxury to know just one type of technology or language. Sure, you can have your specialty, but the more knowledge you have the more valuable you can become. When I worked in the digital agency world, we did not have the luxury to use just one type of technology stack. We had to support all types. Java, Struts, LAMP, .NET, ASP and more. Based on our clients needs we had to switch from using C# with .NET to coding with PHP and CodeIgniter. At Microsoft as an evangelist, it works the same way. I do not have the “traditional” clients, but you do. I support you as a developer and you have many clients with different technology stacks.

This series is to explain how to run Linux VM’s out on Azure, configure and edit and debug as well. The other big thing to note, is this can all be done on a non-Microsoft system, ie. Mac.

  1. Getting Started
  2. Turn on the LAMP
  3. WordPress Installation
  4. Remote Editing with NetBeans
  5. Remote Debugging with NetBeans

Read more “Linux Powered By Azure – 5 Part Series”

Linux Powered By Azure – NetBeans Debugging

Now that we got NetBeans communicating with the remote server, we need to configure the remote server to enable debugging.

Prerequisites

We need to SSH to our remote machine. I am not going to go over that since that was covered in the setting up the Linux VM tutorial.

Read more “Linux Powered By Azure – NetBeans Debugging”

Linux Powered By Azure – NetBeans Editing

Intro

When it comes to editors there are a few that stand out. Visual Studio is a first class editor. Packages can be added and it can be customized to fit your needs. C#, VB, C++. You can do Unity Development in it, Xamarin Development, Arduino Development. There are a ton of cool features and uses. However, it does not run on a Mac or Linux. When it comes to those platforms there are also some good options. PhpStorm, Eclipse, Android Studio, xCode and more. The editor I like to use, especially when I am building PHP sites is NetBeans. I have been a fan of NetBeans for some time now. Lightweight. Easy to use. Robust. And more importantly, it has debugging and remote publishing built in.

Read more “Linux Powered By Azure – NetBeans Editing”

Linux Powered By Azure – YAWIP

On to step 3! We created a Ubuntu VM. We configured it to be LAMP ready. And now…YAWIP (Yet Another WordPress Installation Post). Yes, I am sorry. Another post about how to install WordPress. It is quite alright. WordPress is super popular and it goes nice with this series.

WordPress is available via the Azure Websites but sometimes you want more control over the features or server and these tutorials are meant for that.

Read more “Linux Powered By Azure – YAWIP”

Linux Powered By Azure – Turn on the LAMP

Welcome to part 2 of this series entitled, Linux Powered by Azure (#poweredbyazure).  In the previous tutorial we stood up an Ubuntu virtual machine and connect to is securely through SSH by creating a private and public key pair using openssl. The server is up and running but is not really configure to do anything. In this tutorial we will look at filling out the LAMP stack (Linux, Apache, MySQL, PHP)

Read more “Linux Powered By Azure – Turn on the LAMP”

Linux Powered By Azure Series

I am starting a 4-5 part series on running Linux out on Azure. Starting from standing up a virtual machine to installing WordPress and remote debugging and deploying.

Azure provides three compute models for running applications: Azure Websites, Azure Virtual Machines, and Azure Cloud Services. Azure Websites is a quick and easy way to deploy your website running .NET, PHP, Node.js and Java along with many frameworks and applications that are ready to go. However, there are some instances that you may want bit more control over the configuration of your website. This tutorial will show how to build a Linux based webserver out on Azure just for that reason.

Read more “Linux Powered By Azure Series”