Sunday, May 11, 2014

Switching Microsoft Azure Subscriptions for WordPress Site

Have you ever wanted to move your WordPress Microsoft Azure Website from a pay-as-you-go subscription to the subscription that you get with an MSDN license? It's not as easy as you would think. Today I spent several hours battling with Microsoft Azure, ClearDB (MySql service Microsoft Azure uses for MySql databases) and WordPress trying to move my website, lunamark.com, from my pay-as-you-go subscription to my subscription that is tied to my MSDN license.

A month ago, I setup my new business website lunamark.com using Microsoft Azure Websites.  At that time I did not have my MSDN license, so I setup a pay-as-you-go subscription in order to use my custom domain. Moving my website from a pay-as-you-go subscription to the new subscription tied to my MSDN license took longer than I anticipated and required more steps.  In the event that you have to move a Microsoft Azure Website between subscriptions, I hope the following notes will make it easier for you.
  1. Backup your website
    • Backup the files for the source website by downloading the wwwroot folder using your favorite FTP program (I used Cyberduck for Mac).  Find your FTP credentials in the source website's publish profile.
    • Backup your database which is a linked resource to the source website by using mysqldump. If you don't have that on your computer you can download the MySql Suite which will include both the mysqldump and mysql commands. Thanks to John Papa's blog post I was able to do easily backup and restore my MySql database. Here is the command I used on my Mac to backup my database:
      /usr/local/mysql/bin/mysqldump -e -u[user] -p[password]
      -h[host] [database] > [output file]

      Note: the -e makes multiple values rows for the insert syntax but is not required
  2. Create a new Microsoft Azure Website (from WordPress gallery).  I will refer to this website as the destination website to keep the two straight.
    Note: This will require a new name (new_name.azurewebsites.net). Later we will need to replace the old_name with the new_name in the backup sql file created above.
  3. Get the connection string from the the destination website created in step 2 and use it to update the wwwroot/wp-config.php file downloaded from the source website with the new database name and login information.
  4. Connect to the destination website with your favorite FTP program and delete the wwwroot folder.
  5. Upload the source wwwroot folder with the updated wp-config.php file (which should now be configured to use the destination's MySql database)
  6. Edit the [output file] that was created in step 1 and replace the old_name of the website with the new_name that was created in step 2
  7. Use the mysql command to update your new database.
    /usr/local/mysql/bin/mysql u[user] -p[password]
    -h[host] [database] < [input file]

    Note: the [input file] would be the name of the [output file] that was created above and modified to replace the name of the old_name with the new_name of the Microsoft Azure Website
  8. Make sure you remove the old Microsoft Azure Website's reference to the custom domain name you are planning to use.
  9. Now set it up your custom domain in the new Microsoft Azure Website.
  10. Last, I would recommend stopping the old Microsoft Azure Website to verify the new website is working as desired before deleting the old website
Please Note:  The steps described above will require some downtime for your website.  If downtime on your website is not an option, then watch this Scott Hanselman video where he recommends to use a load balancer to not have any downtime. 

Monday, November 18, 2013

Installing Ruby on Rails on Mac

Staring this series on my journey of learning Ruby on Rails has been challenging.  Why is it that as soon as you make a commitment to spend your "free time" doing something it seems all your "free time" is gone?  The good news is I have an amazing wife who is understanding and has helped me continue moving forward with my goal to learn Ruby on Rails.

The first thing I needed to do was install Ruby on my Macbook Pro.  Yes, even though I am a Microsoft developer by day I only own Macs.  I made the transition around 6 years ago after building my own PCs since I was in high school but that is another topic for another blog post.

All Macs come with Ruby installed and since I recently upgraded to OS X Mavericks Ruby version 2.0.0 was already installed.  So my first step was complete or so I thought.

Using this Ruby Mac Install video as my guide I started installing the following:

  1. Install git v1.8.3.4
    • I already had git installed and a nice prompt setup thanks to my good friend David Hudson.  Here is a picture of it:
      • Feel free to go to my github repository and copy my prompt logic from the bash_profile that is checked in there if you would like a prompt like this.
    • Install curl v7.30.0
    • Install rvm v1.23.15
      • Used this command: \curl -L https://get.rvm.io | bash
        • Next use this command to install requirements for rvm based on the rvm website's install instructions: rvm requirements
        • Be sure that the [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" is in your ~/.bash_profile file

        • Install ruby v2.0.0-p247 
          • I thought since ruby was already installed on my Mac I could skip the step in the video to install ruby using rvm install 1.9.2.  So even though I didn't discover this until the step in the video to create a gemset I put this here so you knew you needed to install ruby using this command: rvm install ruby

          • Create a gemset in rvm for this tutorial

            • Install rails v4.0.1 - decided to use 4.0.1 based on the Ruby on Rails blog.
              • Rails can be installed using this command:  gem install rails --version 4.0.1

                • During rails install there were several ...unable to convert "\x89" from ASCII-8BIT to UTF8 for... error messages.  A quick google search found this stackoverflow question and answer.  This suggested that I needed to update my version of rdoc and then regenerate all my documents with the newer version of rdoc.  Here is the screenshot of the commands:


                    Now that I have ruby, rails, and a few other necessary tools installed I plan to spend some time over the next few weeks learning the ruby syntax and how to build a simple application in ruby on rails.

                    Until next time continue learning!

                    Monday, November 4, 2013

                    A .NET Developer Learns Ruby on Rails Series

                    I have been developing business applications using Microsoft technologies for over 12 years and really enjoy working with them.  However, learning a new language has been on my mind for some time and this weekend I decided to start that process.

                    This is the first in a series of posts that will capture my journey of learning Ruby on Rails as a C# .NET developer and setting up a development environment on my Macbook Pro.

                    Here is a list of resources that are being used to learn Ruby on Rails:
                    1. Installing Ruby On Rails On A Mac blog post by Bret McGowen
                    2. Ruby on Rails Tutorial installation video by rubyonrailstutorial
                    3. Ruby on Rails Tutorial book by Michael Hartl
                    4. Ruby on Rails - A Jumpstart for .NET Developers pluralsight video by Dustin Davis
                    As I continue to learn and develop, I will be adding to this list other resources and refer to in in the coming posts.

                    If you are currently learning a new language and have any tips please post a comment or send me an email with your advice to paul [dot] gower [at] gmail [dot] com.



                    Saturday, August 10, 2013

                    My Code Kata Talk

                    I had a great time this past Thursday night (08/08/2013) at the Little Rock .NET User Group meeting.

                    Thanks to everyone who came out to watch my presentation on Code Kata.  Here is a link to my slides in case you missed it or wanted to view the slides again.

                    Also I wanted to give a big thanks to David Hudson for setting up this code kata website for us.  Starting Sunday, August 25, 2013 I will be publishing a code kata every two weeks and I look forward to seeing you there.

                    Wednesday, April 3, 2013

                    Web.config and IIS7 Woes

                    Today I spent the majority of my day trying to debug why our QA environment would not work to only figure out one of the two issues.

                    It was supposed to be a simple 30 minute x-copy deploy but it turned into an almost 7 hour deployment.

                    The first set of issues were basic server setup issues like ASP.NET and WCF not being registered properly into IIS.  Once I was able to finally get the website up and running against the QA database I discovered a major bug.  Of course I hadn't encountered it in my development environment and just like the old saying "It worked on my machine!"  Truth be told I don't like that saying very much but it is usually unfortunately true.  As most developers know the hardest type of bugs to find are the ones you can't reproduce easily.

                    Now I have a major bug that is going to cause QA some headaches but on top of that I discover that JavaScript code is not working.  The ASP.NET AJAX functionality was not working properly and was even causing the Infragistics controls to not function at all on some of my pages.  This was a bigger issue than the major one I found initially.  After spending way to long on this issue trying to determine if it was an Infragistincs control issue or if it was a server setup issue or an IIS configuration issue here is what I found to be the problem:

                    The <system.web> section is for IIS6 and below; whereas, the <system.webServer> section is for IIS7. The issue was I had the <httpHandlers> section in the  <system.web> section which I thought was enough; however, I did not have the <handlers> section in the <system.webServer> section.

                    Unfortunately this code was in my web.config in the version that is checked into TFS but some how it was removed which caused me to waste over half my day debugging issues.  So hopefully this blog post will help someone else not waste a half day like I did or if I come across this issue again I can hopefully remember to search my blog before wasting too much time!

                    Tuesday, November 13, 2012

                    Setting up DBMail in SQL Server 2012

                    Recently I needed to setup database mail in SQL Server 2012 and here is what I did (so if/when i have to do it again I will remember how to do it):

                    Run this script to create the sysmail account and profile:
                    use msdb
                    GO
                    DECLARE @ProfileName VARCHAR(255)
                    DECLARE @AccountName VARCHAR(255)
                    DECLARE @SMTPAddress VARCHAR(255)
                    DECLARE @EmailAddress VARCHAR(128)
                    DECLARE @DisplayUser VARCHAR(128)
                    
                    SET @ProfileName = 'DefaultDBMailProfile';
                    SET @AccountName = 'DefaultDBMailAccount';
                    SET @SMTPAddress = 'smtp server address goes here';
                    SET @EmailAddress = 'from email address goes here';
                    SET @DisplayUser = 'from display name goes here';
                    
                    EXECUTE msdb.dbo.sysmail_add_account_sp
                    @account_name = @AccountName,
                    @email_address = @EmailAddress,
                    @display_name = @DisplayUser,
                    @mailserver_name = @SMTPAddress
                    
                    EXECUTE msdb.dbo.sysmail_add_profile_sp
                    @profile_name = @ProfileName
                    
                    EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
                    @profile_name = @ProfileName,
                    @account_name = @AccountName,
                    @sequence_number = 1 ;
                    

                    Run this script to enable Database Mail on the server (MSDN Link to Database Mail XPs Server Configuration Option):
                    USE Master
                    GO
                    sp_configure 'show advanced options', 1
                    GO
                    reconfigure with override
                    GO
                    sp_configure 'Database Mail XPs', 1
                    GO
                    reconfigure 
                    GO
                    sp_configure 'show advanced options', 0
                    GO
                    

                    To test and make sure you have it setup you can use this script:
                    EXEC msdb.dbo.sp_send_dbmail
                    @recipients = 'to email address goes here',
                    @body= 'Test Email Body', 
                    @subject = 'Test Email Subject',
                    @profile_name = 'DefaultDBMailProfile'
                    

                    Please note: many of the variables in the above scripts have test data in them. Be sure to set the variables to the values that apply to your environment.

                    Wednesday, September 19, 2012

                    Robots.txt file in MVC3

                    Recently I was asked to look at adding a robots.txt file to a client's website that we built on ASP.NET MVC3. So I did some research and found out some interesting information about the robots.txt file.
                    1. The file is just a suggestion and bots are not required to follow what you ask them to do via the robots.txt file.  
                    2. The file is really an exclusion list instead of an inclusion list.  This means you have to put the places you don't want the bots to view which could be a bad idea in that it would give the bad bots areas they should focus on hacking.
                    After my research we decided to not put a robots.txt file on the website initially. Soon after our deploy we noticed in the ELMAH logs that we were seeing a considerable amount of errors which contained this error message:
                    The controller for path '/robots.txt' was not found or does not implement IController.

                    So now we decided we at least needed an empty robots.txt file out there to prevent all these unnecessary errors. So I did some more research and developed a solution for MVC3:
                    • Basically you just add the physical robots.txt file to the website by adding it to the project at the root level. It could be empty or could contain the basic level of content required in a robots.txt.
                    Now that you have the physical file on the website it will ignore the ASP.NET MVC3 routing as long as you haven't changed the default setting of the RouteExistingFiles property of the RouteCollection which will ignore routing if a physical file is found that matches the URL pattern.

                    To ensure that the physical file will always be served up even if someone changes the RouteExistingFiles property you can add the following ignore route code to the global.asax.cs file:
                    routes.IgnoreRoute("{robotstxt}", new {robotstxt=@"(.*/)?robots.txt(/.*"});

                    Your mileage may vary with the robots.txt file and it might not be a bad idea to have a robots.txt with some exclusions if you really need to exclude some of your content from web crawlers or bots.

                    This particular client didn't really need one because most if not all the content of their website required that you log into their website so bots and web crawlers wouldn't get much content from crawling their entire site.