This is part 2 of a 2 part blog post. Read part 1 here.
So in part 1, we’ve created a local Symfony2 PHP website that uses Composer to manage its packages. In this part, we are going to create a Windows Azure Website, setup deployment from source control, and modify the Git post deployment script to automatically run run php composer.phar install after each commit.
Why would you want to do that you ask? Well, the vendors directory, where all the downloaded packages reside, can get quite large, and storing it in source control, and uploading it with your website is a waste of bandwidth.
Creating the website
I’m not going to go through the details here, as it is a well covered topic, I’ll create the website on the portal, and choose to “Publish from source control”
And then choose “Local Git repository”
Fire it up! Bam, 5 seconds, I have a website created.
Create the local Git repo
Go to the Deployments tab for the website, then follow the steps there to create a local repository on my machine and commit my files. I’ll run the commands on Git Bash. Only commit the files locally, don’t add the remote Windows Azure repository and push just yet!
What we need to do now is to modify what happens whenever I commit files. Fortunatley, the great guys at the Windows Azure team have a tool called Kudu which is basically responsible for deploying your code once you push it to a Git source control.
Create the custom Kudo deployment script
For this part, you will need to have the Windows Azure Command Line Tools (CLI) installed.
Once you have it installed, you can launch the Windows Azure Command Prompt that got installed (which you will find under C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2 or whichever version the SDK is current at the time you read this)
If you type azure in that prompt, you will get all the commands that you can use. The command we are interested in is azure site
So change directory into our project location then run the following
Which will generate a .deployment file and a deploy.sh file. This deploy.sh file is what is executed after each push we do on the Windows Azure Git repo.
Customize the deploy.sh script to run composer
Open deploy.sh in your favorite editor
Add the below before the Deployment section
Add the below after the Deployment section
Commit the newly added files to your local repository
Add the remote Windows Azure repository and push to it
You’ll see that I’ve only pushed 270KB and on the server, the composer script kicked in and started downloading all the dependencies without using my bandwidth. Talk about efficiency!
You need to take care of some things when migrating from an Apache based installation to an IIS based installation (like Windows Azure Websites). For example, IIS uses Web.config (in contrast to Apache's .htaccess) to configure stuff, like URL Rewriting.
You may use these excellent posts to understand how to translate .htaccess content to Web.config and if you are running Windows, you can even use a tool provided inside IIS Manager to do the conversion for you.