September 28, 2014
Posted by on
In Part 1 of this series, I showed how to setup your project on Railo so that you could publish your CFML to Microsoft Azure Websites. You should have your project in a state that you want published on the web.
For this part, you will need to have an Azure account. You can sign up for one at http://azure.microsoft.com. Remember, BizSpark and certain MSDN members get free credits on Microsoft Azure.
- Login to the Microsoft Azure “Management Portal”
- At the time of writing, there are two versions of the portal — the Classic and New. I’m going to show the Classic portal as it seems to be changing the least at the moment — but I’m sure the New portal will eventually replace it.
- Create a new “Custom” Website
- After you’ve logged into the Management Portal, click on the “+ New” button on the bottom of the site.
- Chose “Compute” -> “Website” -> “Custom Create”
- Chose a URL for the site, Web Hosting Plan, and if you want a database. Don’t chose the “Publish from Source Control” at this point — we will set this up later.
- It will launch the new site. This will take a few minutes. Once you see “running” on the dashboard, click on it to modify the settings of the site.
- Click on Configure to configure the site.
- Enable Java by setting a version. This will disable PHP, Python and .NET processing.
- Make sure to select Tomcat as your container.
- Your choice on 64 or 32 bit. Railo doesn’t care which is running.
- Web Sockets will allow for outgoing connections from Railo to outside servers (such as HTTP calls). If you don’t do this, keep it off.
- Always On will keep the site “warm” if it is not in active use. If this is off, Azure will unload it from memory if there is not traffic to the site within a half-hour.
- Scroll down to Default Documents. Add index.cfm. You are free to remove the other options if you wish.
- Hit “Save” It will take about 5 minutes for Websites to update your site to use Java.
- Upload your site to Azure (Using FTP)
- Click back to the Dashboard of your site. Scroll down about half way through the page and find your FTP credentials.
- Using your favorite FTP client, login to this FTP site.
- Change to the /site/wwwroot/webapps/ROOT/ folder on the remote side. This is where your files will be served out of.
- Delete the files that exist in the ROOT folder. Upload ALL the files that exist in the output of your exploded WAR directory (in my case, E:\Projects\SampleWebsite\out\artifacts\SampleWebsite_war_exploded\).
- In some cases, you may need to restart the website. You can do this via the management portal and clicking on “STOP” on the bottom of the page. You can then click “START” to restart it.
- The first load after you upload the files can take 30 seconds. Don’t be alarmed about this — subsequent loads should be much faster after Railo is loaded into memory.
- Keep uploading subsequent changes to your code and play around with settings in Azure. For example, if you want a “custom domain”, you can change the site to a Standard plan instead of the free one. You can also configure IntelliJ to automatically upload changes via FTP when you deploy a site.
- Upload your site to Azure (Using GIT)
- Deploying via GIT is a pretty cool concept, but it does take a few additional steps to get working. First, we will need to create a new artifact in IntelliJ. This is so we can keep our GIT repository separate from our working one (if we are using GIT for source control).
- Right-Click on the SampleWebsite Module in the Project view. Chose Open Module Settings (or you can press F4)
- Click on the Artifacts tab.
- Add a new Artifact “Web Application: Exploded” -> Empty
- Give the new artifact an obvious name, like Azure Push.
- Make a note of the output directory name. This will be the root of your new GIT repository
- Under Output Layout, click the create directory button to add a new directory named “webapps”
- Add another directory below that named “ROOT” (caps matter)
- Under Available Artifacts on the right-column, drag “SampleWebsite war:exploded” to be under ROOT
- Click Apply, then OK to get out of the Artifact setup.
- Go back to the Azure Management Portal. Open your site, and go to the dashboard.
- FTP into the site using the site using the instructions above. You don’t need to upload the files, but you DO need to remove all the files in ROOT in order to get a clean site started.
- Go back to the site dashboard.
- Click “Setup Deployment From Source Control”
- Click on “From Local GIT Repository”
- Load your GIT client (like git bash), and go to the output directory of the artifact we just created.
- Follow the commands on the Azure site on how to commit your initial files to your local GIT repository. Don’t clone the existing site.
- After you’ve committed your first file, and connected it to Azure GIT, do a git add * , and commit those files to your site.
- Your Azure site may need to be restarted after your first commit. I’ve seen it both ways. If it still shows a generic Azure is running Java page, try restarting the site.
- In order to refresh the site’s contents, follow the following steps :
- In IntelliJ, Go to the Rebuild Menu -> Rebuild Artifacts -> Azure Push -> Build. This will refresh your site’s artifact. DO NOT CHOSE REBUILD OR CLEAN — these will remove the GIT database files and you will have to re-connect it to GIT.
- In GIT, add *, then commit. This should update the site with the latest.
And that is it. A few notes, however :
- You can’t deploy .WAR files onto Azure websites. It doesn’t work for some odd reason — and when it does (it happens sometimes), it breaks your site because of partial loads.
- It seems that connections to Amazon S3 are blocked. You can’t use the s3:// commands.
- If you use Microsoft’s Azure SQL Server, you can’t use any ORM (hibernate). Azure SQL Server requires some changes to the SQL Statements to allow for clustered indexes. You can use their “free” MySQL instance. Manual SQL statements via Stored Procs and CFQUERY work fine.
- If you do things like update Railo or upload files locally on your machine, make sure that you update your local project or those files may not make it into your deployed project on Azure.
Hope this tutorial gets you in the right path! I’ve been deploying a few sites using this method with great success. (I’m using GIT to deploy my sites — it’s already in my toolchain and seems to work well).
September 28, 2014
Posted by on
I was lucky enough to have Microsoft give me some time on Azure through the BizSpark program. If you don’t know what BizSpark is, it is a program from Microsoft to give small businesses a headstart on the Microsoft stack, grattis for three years. That includes MSDN, some credits on Azure and more. Azure is a comparable solution to Amazon’s Web Services that I’ve been using for a few years. Azure’s Websites solution is similar to AWS Beanstalk where you upload your final project to their servers and they take care of the rest (OS, patches, firewalls, etc.)
As I’ve already written in previous blog posts, Railo is simply a Java application that can sit on top of a J2EE server such as Apache Tomcat. Railo is compatible with Adobe ColdFusion, and is 95% there for simply letting ACF code run. The only time you can expect to run into issues is with some of the integration tags like CFEXCHANGE, CFCHART or some of the Active Directory integrations. But on the flip-side, Railo requires no install, no purchase of a license, and (in my opinion) is easier to work with.
In this walk-through I’m going to use Railo 4.2.1 deployed as a WAR application onto Apache Tomcat running on Azure Websites and using IntelliJ IDEA 13.1 as my IDE. You should be able to easily substitute Eclipse or ColdFusion Builder for the IDE — I just don’t happen to use those anymore.
Downloading all of the required components:
You will need:
Setting up your environment:
Do the following:
- Extract the Tomcat .ZIP file to a directory on your computer. Doesn’t really matter where — as long as you know where it is. This will be where your local, testing environment will run from.
- Rename the Railo .WAR file to .ZIP. This will be the files you will start with.
- Install IntelliJ, if you haven’t already.
- Add your Tomcat setup to IntelliJ.
- Go into the IntelliJ Settings by clicking on Configure -> Settings from the Quick Start menu, and search for Application Servers under IDE Settings.
- Click the green [+] and then select Tomcat Server.
- Provide the Tomcat Home directory. This is the directory where you extracted Tomcat to.
- Hit OK, then Apply to commit this new application server to IntelliJ
- Add a new Java Project to IntelliJ
- Go back to the Quick Start menu, and choose Create New Project
- Select Java and then Select Web Application. You may need to add a new Project SDK by clicking on New… on the upper-left of the screen and letting IntelliJ know where your copy of Java is installed.
- Don’t select to create the project from a template. Click Next.
- Give the project a name and a location. Click Finish to create the project.
- After IntelliJ creates the project, in the Project area, you should see a src folder, a web folder, a JSP file, and a WEB-INF folder.
- Test your application setup with Tomcat.
- From the “Run” drop down, select “Edit Configurations…” to add a new run configuration.
- In the “Run/Debug Configuration” screen, click the [+], select Tomcat Server, then Local to add our run config.
- Give the Run Config a name (like “Local Debugging”)
- Click the “Fix” button near the error that states you don’t have an artifact marked for deployment. This will tell IntelliJ that we plan on deploying our project to our local test server when we click the Run button. The name of the base “artifact” is “SampleWebsite:war exploded”.
- Change back to the Server tab. Change the option “On Frame Deactivation” to “Update Resources”. This means that when you make a change within IntelliJ and switch to your web browser to check that change it will happen automatically.
- Click Apply then OK to close the window.
- Run the Local Application Server and deploy our base application.
- Click the green “Run” button next to the drop-down with the Run configuration we just created. You will see Tomcat spin up in the console messages on the bottom of the screen. Eventually you will see a browser launch with a blank page. This is actually displaying the contents of the index.jsp file in our project.
- Copy Railo into our project.
- Remember when we renamed Railo to be a ZIP file? Extract that ZIP file into our web folder within our project. You most likely have to do this outside the IDE. You will need to overwrite the WEB-INF folder (including the web.xml that is included within it).
- Delete the index.jsp file within the web folder. You don’t need it anymore.
- Within the web folder, create a new file named index.cfm. Add a <cfdump var=”#server#”>
- Click on the green “Run” button next to the drop-down with the Run configuration we created earlier. You will get a dialog asking if you want to update the resources or restart the server. Chose “Restart the server” so that we can load Railo. This is the same option you would use if you ever need to restart CF (for example, to unload a CFC that is loaded into the session memory).
- You will see Railo unpack and launch with the console window. After a few seconds, you should see your browser launch with the debug output. Congratulations, you are now running CF!
- Create your application like you normally would.
- Any files within the WEB folder of your project are essentially in the root of your web server.
- Railo Administration Dashboard (The CFIDE, if you will) is located at http://localhost:8080/railo-context/administrator/server.cfm This is where you would setup your databases, etc.
- Copy your configuration files BACK to your project
- Any files that change on your web server are NOT copied back to your project. This includes configuration changes (like databases) made within the Railo admin. To copy these files back, go to your project folder (in my case E:\Projects\SampleWebsite), then OUT\Artifacts\SampleWebsite_war_exploded\ and copy all the files back to your project. In my previous blog entries I mention which files you can copy back if you are simply looking to save the Railo config files.
Part 2 of this entry I will show how to get this posted on Microsoft Azure Websites.