Saturday, July 19, 2014

Install Rails 4 and MySQL Server on Windows 7/8

Introduction

Here are the steps for Installing Rails 4 and MySQL Server on Windows 7/8

Using the code

Install Rails 4 and MySQL Server on Windows 7/8
Watch the following video before installing:
http://www.globalnerdy.com/2013/10/25/how-to-install-rails-4-on-windows-including-windows-8-and-8-1/
other References:
i)   https://github.com/brianmario/mysql2
ii)  http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
iii) http://learnwebtutorials.com/step-by-step-tutorial-on-installing-ruby-on-rails-4-on-windows-8
1) Install Ruby (32Bit Version Ruby 2.0.0-p451)

i) Download Ruby 2.0.0-p451 (32bits version only) from http://rubyinstaller.org/downloads
or download using url (http://dl.bintray.com/oneclick/rubyinstaller/ruby-2.0.0-p451-i386-mingw32.7z?direct)
Note: the 64 bit version of Ruby 2.0.0-p451 is not compactible with MySQL
ii) Choose the installation options as
1. Install tcl/tk support
2. Add Ruby executable to PATH
3. Associate .rb and .rbw files with Ruby
You can select all the options. But make sure you atleast select the 2nd option
iii) Confirm that Ruby is installed
After installation, see that
a) It saved ruby in C:\Programs\ruby200\
b) Added Ruby to the Windows PATH environment variable.
c) Also see that a new Windows tile have been created on your start page that says “Start Command Prompt With Ruby”
d) Opne Command Prompt and run "ruby -v" ruby 2.0.0p451 (2014-02-24) [i386-mingw32]

2) Create Application Folder for your websites
Search for “Start Command Prompt With Ruby”. Click on that to get to the command prompt.
Now create a new folder in Windows at C:\Data\Sites
That will be the location of where we will place our Ruby apps.
At the Command Prompt, it is best to navigate to this directory before typing Ruby commands.

3) Extract 32 bit DevKit (DevKit-mingw64-32-4.7.2-20130224-1151-sfx)
i) Download DevKit for Ruby 2.0 (32bits version only) DevKit-mingw64-32-4.7.2-20130224-1151-sfx from http://rubyinstaller.org/downloads
or download using url (http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe)
ii) Extract the DevKit zip file into C:\Programs\Ruby200\devkit
iii) Navigate to C:\Programs\Ruby200\devkit and run following
a) ruby dk.rb init --force
b) ruby dk.rb review
c) ruby dk.rb install --force
iv) Test Installed DevKit(Optional):
On Command Prompt, run followings
a) gem install json --platform=ruby --no-ri --no-rdoc
b) ruby -rubygems -e "require 'json'; puts JSON.load('[42, 56, 22]').inspect"

4) Download & Extract 32 bit MySQL Connector/c
i) Browse to http://dev.mysql.com/downloads/connector/c/
Note:
a) Ruby uses the same connector that C uses.
b) Even if you have 64 bit MySQL Server, the connector should be 32 bit. The 32bit Ruby communicates to MySQL via this Connector.
ii) Click Looking for previous GA versions?
Note: The latest MySQL 6.1.3 connector is not compatible with Ruby
iii) select & Download Windows (x86, 32-bit), ZIP Archive (mysql-connector-c-noinstall-6.0.2-win32.zip)
Direct URL: http://dev.mysql.com/downloads/file.php?id=377978
iv) Extract mysql-connector-c-noinstall-6.0.2-win32.zip to C:\Programs\

5) Copy "libmysql.dll" from mysql/lib to ruby/bin folder
i) Copy libmysql.dll from C:\Programs\mysql-connector-c-noinstall-6.0.2-win32\lib to C:\Programs\Ruby200\bin

6) Install rails -v=4.0.2
i) On Command Prompt run,
gem install rails -v=4.0.2 --no-ri --no-rdoc

ii) Test the Rails Version installed by running "rails -v" in Command Prompt
Note: Rails 4.1.0 is not compactible with some libraries
7) Install mysql2
On Command Prompt run,
gem install mysql2 --platform=ruby -- --with-mysql-dir=C:\Programs\mysql-connector-c-noinstall-6.0.2-win32 --no-ri --no-rdoc
8) Install Other Gems(Windows 8.1 only)
On Command Prompt run,
gem install node --no-ri --no-rdoc

1) Install XAMPP OR My SQL Community Server
Browse to Url http://www.oldapps.com/xampp.php and download XAMPP 1.8.3-4
or download using direct Url: http://www.oldapps.com/xampp.php?old_xampp=14610
Install XAMP

OR
Install 32/64 bit MySQL Community Server
i) Browse to  http://dev.mysql.com/downloads/installer/5.6.html
ii) I installed MySQL Community Server 5.6 Windows (x86, 32-bit), MSI Installer  (mysql-installer-web-community-5.6.17.0)
url:  http://dev.mysql.com/downloads/file.php?id=451576
Note: you can install 64 bit version as well if you want

iii) Run the mysql-installer-web-community-5.6.17.0
iv) Click Add MySQL Products
v) Install Server Only option or Custom option with only MySQL Server 5.6.17 & Workbench selected.
vi) Select default and hit next. Keep other default option as it is and select next.


1) Create new Ruby on Rails Site
On command prompt, navigate to C:\Data\sites\ and run
rails new <App Name> -d mysql -B
e.g.: rails new DemoApp -d mysql -B
ii) Test version of Rails in the new Site created
open Gemfile and make sure that the value of gem 'rails' is '4.0.2'
iii)update database.yml under config folder.
Update password. Enter Port: <port no> if port of MySQL is other than 3306.
Remove Test & Production section.
iv) On command prompt, cd to C:\Data\sites\<App Name> and run following  command,
bundle install

2) Test MySQL from newly created Ruby on Rails Site

i) On command prompt, cd to C:\Data\sites\DemoApp and run following one after another,
a) rake db:create
Note: Go to your MySQL and make sure that a database with name "DemoApp_Development" is created
b) rails g scaffold user first_name:string last_name:string email:string
c) rake db:migrate
Note: Go to your MySQL and make sure that a table Users is created in database "dbDemoApp"
d) Open command prompt and CD to sites.
rails s
e) On your browser, open http://localhost:3000/users and create new users.'
Note: Go to your MySQL and make sure that a table Users in database "dbDemoApp" has new users.


Thats it. Thank you.

 

Powershell To update Services Password, Sharepoint Managed Acount Password and IIS AppPool Password

Many a times there is a need to update the changed password in Virtual Machines. It can be done manually. But doing it via Powershell will save us a lot of time.

Background

After browsing for a while, I couldn't find an article that pointed me in doing all the above using one script. So I thought to share the powershell comands that I just put together, which can be optimized/refactored by admins to use them in prod environment.

Using the code

//
// Save the below powershell code as ps1 and run in Powershell
// Update Domain, UserName and Password with your actual values
//

$localaccount = "domain\username"
$newpassword = "************"

#Set Execution Policy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -force

#Import SharePoint Module
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA silentlycontinue

#Update Service Account
Write-Host "Updating Password for Services" -foregroundcolor green
$services = Get-WmiObject win32_Service | where { $_.startname -eq $localaccount}

foreach ($service in $services)
{  
    #Update Password
    Write-Host "Updating Password." -foregroundcolor 13
    $status = $service.Change($null,$null,$null,$null,$null,$null, $localaccount, $newpassword)
    Write-Host "Status:  " $status.ReturnValue -foregroundcolor 13 
    
}

#Stop Service
Write-Host "Stop all running Services." -foregroundcolor green
Get-WmiObject win32_Service | where { ($_.startname -eq $localaccount -And $_.state -ne "Stopped" -And  $_.startmode -ne "Disabled") } | stop-service -force

#Start Service
Write-Host "Restarting stopped Services" -foregroundcolor green
Get-WmiObject win32_Service | where { ($_.startname -eq $localaccount -And $_.state -ne "Running" -And  $_.startmode -ne "Disabled") } | start-service

#Update Sharepoint Managed Account
$ManagedAccount = Get-SPManagedAccount -Identity $localaccount
$securePassword = ConvertTo-SecureString -String $newpassword -AsPlainText -Force

Write-Host "Please wait while Passwod for SharePoint Managed Account gets updated." -foregroundcolor red

Set-SPManagedAccount -Identity $ManagedAccount -ExistingPassword $securePassword -Confirm:$false

Write-Host "Password for SahrePoint Updated Successfully" -foregroundcolor green

#Update App Pool Accounts
Import-Module WebAdministration

#Restart IIS
Write-Host "Restarting IIS. " -foregroundcolor green
iisreset /noforce

$appPools = Get-ChildItem IIS:\appPools  | where {$_.state -ne "Started"}

foreach ($appPool in $appPools) 
{    
    if ($appPool.processModel.userName -eq $localaccount)
    {
        $appPoolName = $appPool.Name
        $appPool.processModel.password =  $newpassword 
        $appPool | Set-Item
 $appPool.Recycle()
        Write-Host "Password for AppPool " $appPoolName " updated successfully"  -foregroundcolor green
    }
}

#Restart IIS
Write-Host "Restarting IIS after password reset. " -foregroundcolor green
iisreset /noforce


Write-Host "IIS Restarted Successfully. " -foregroundcolor green