This post is going to be relatively short, but I’ll update it with more information as I receive more feedback from users.
File System Issues
Recently there were some changes made in WinCache (v18.104.22.168) which reroutes file system calls such as is_dir, is_file & file_exists to a manifest in Wincache. This means that there is a potential for files that have been deleted on disk, to report as still available. This causes issues when updating WordPress, themes or plugins from a PHP script (such as the one used by the internal WordPress update tool). To remove these redirects follow the instructions below:
Create a file called .user.ini (provided it doesn’t already exist)
Append wincache.reroute_enabled=0 to the end of the file
Upload the .user.ini file to the d:\home\site\wwwroot directory
This will remove any file system based errors which may occur during the update.
If you are running a giant WordPress blog on Azure App Service, there is the possibility that the database updates will take longer than the request timeout time. This will cause HTTP 5xx error messages when you are attempting to update.
In a previous post I outlined how to enable deployment time dependency management with Wep App by hooking the deployment with Kudu. In this post, I will explain how I iterated on the techniques used in that previous post, to enable Composer in Web App via a Site Extension which lowers the barrier to use Composer with Web App.
Cool, but what exactly is a Site Extension?
Site Extensions are a means of extending the Azure App Service platform. The best part about Site Extensions are that they can be created by anyone, it is as simple as creating a Website, WebJob or IIS Module, an applicationHost.xdt file (applicationHost.config Transform), and possibly some supporting files to help install or setup the Site Extension components. These components are then packaged with NuGet and uploaded to the Site Extension Gallery
More information is available on how to create a Site Extension is available in the Kudu Wiki.
Now, How do I use Composer in Web App?
To get started with Composer on Web App, you’ll need to install the Site Extension, luckily I wrote a post which explains how to enable a site extension. You’ll find Composer in the list of Site Extensions.
Creating a web site which uses Composer
Composer has a number of different ways that it can be leveraged, you can run it as a tool from the command line directly to have it build files or you can manually create a composer.json file. I’ll refer you to the documentation to figure out how you’d like to use it.
For my application, I crafted the composer.json file by hand using Packagist as a reference for my file dependencies. I wanted to create an application which lists files from a particular container in Azure Storage, this means I would require the Microsoft Azure SDK for PHP and it’s dependencies. Here is my composer.json file.
The composer.json file should be placed in the root of the repository. The Composer Site Extension has the COMPOSER_VENDOR_DIR set to d:\home\site\vendor which is out of the public wwwroot directory so that the dependencies cannot be addressable publicly.
Now that we have our dependencies taken care of simply build a PHP application which requires the autoloader which is created for us by composer, then write our code. Here is my index.php file which iterates over items in my storage container.
Now we’re ready to deploy the application and configure a few of the settings to make the application come to life. Click the button below to deploy the application into your Microsoft Azure Subscription:
This Deploy to Azure button could be configured to set these App Settings automatically on deployment, If you see a azuredeploy.json file in the repository you can disregard the following steps. As I have found the time to make the Azure Resource Manager template to hydrate these values.
Add the following App Settings to the App Settings list in the Portal:
container – This is the name of the container in your storage account that you’d like to list the values of. This is referenced in the code above by the call to getenv(‘container’) which reads this value from an environment variable
DEPLOYMENT_SOURCE – Typically, I would add a .deployment file to the respository to change the project config setting to web as this will change the deployment directory and only deploy the items in the web folder. Due to how the Composer site extension is hooking the deployment, the .deployment file doesn’t work so this setting is needed to let Kudu know that the contents of web should be copied to the wwwroot directory
Add the following Connection String to the Connection Strings list in the Portal:
BlobConnectionString – This should contain the connection string for your azure storage account. Set the type to Custom.
There is an assumption here that you actually have a few items in the storage account. If you don’t upload a few now then refresh the website.
That’s it! You have successfully deployed a PHP application which uses composer!
WordPress is the most popular CMS on the Web so there are obviously a great set of tools surrounding it to enable the wide variety of developers who build on the WordPress platform. One of such tools is WP CLI which is a command line interface for managing your WordPress site. In this post, I’m going to cover how to install the WP CLI site extension into your Azure Websites hosted WordPress install to enable command line access to your site.
Install WordPress on Azure
Install WP CLI Site Extension
Command line to WordPress
Install WordPress on Azure
This step is a little bit out of scope for this topic, if you’re savvy enough to know there is a command line tool for WordPress, I’d assume you’d know how it set it up. If for some reason you don’t know, I’m just going to leave these here:
To add a site extension, you need to login to the Azure Portal and go into your site.
If you scroll to the bottom of the site blade, you will find a part called Extensions which on that which will open the Site Extensions blade.
Scroll down the list until you find WordPress CLI, click on the item, then accept the license terms. Click OK and the site will begin to install the extension.
Command line to WordPress
Ok great, I have the Site Extension installed but how does that help me? I want to use the command line. There are two different command lines that I want to show off.
Kudu – Debug Console (Web Based)
When you create an Azure Website in the background a second site is created at http://<site-name>.scm.azurewebsites.net which exposes the Kudu Console (Kudu is the deployment engine for Azure Websites). You can access this site using either OAuth (which is enabled by default) or Basic Auth (http://<site-name>.scm.azurewebsites.net/basicauth). It’s cool that you have web based access to your website.
KuduExec (Terminal, PowerShell, Command Prompt)
Although it is really cool to be able to use the command line in a web browser, wouldn’t it be nice to be able to use your command line of choice? Well, the team thought so too, and enabled it using Node.js. KuduExec is a command line tool which gives you command line access to your Azure Website.
To install KuduExec, first you’ll need to install Node. Once you have node and npm installed run the following command.
npm install kuduexec –g
After kuduexec installs you can run it from the command line to login. To use KuduExec, type in kuduexec then the scm endpoint for your site (hint: http://<site-name>.scm.azurewebsites.net) then use your deployment credentials to login.
Then you have full access to your Azure Websites site.
Recently I had someone ask me how to connect to the Microsoft Azure Redis Cache Service from Python. I figured it would be easy considering how simple python is to learn. It turned out to be a little trickier than expected but still not too hard nonetheless.
Below is the sample code, then I’ll explain what each part is doing.
To start you will need to install redis-py (or a redis client of your choice) from your favourite package installer, I’m using pip.
pip install redis
There are three things you need to be aware of when connecting to Redis on Azure:
Most of the time when you connect to a redis server it will be on your local machine which is fairly secure because there is no need for an outbound connection to the internet. When connecting to a Cloud Server there are many things that could go wrong in the security department so the Microsoft Azure Redis Cache uses a few things to avoid security issues.
First is a secure connection (SSL), when you connect to Azure you want to ensure that the data going across the wire is encrypted. Second a Password is used to authenticate access with the cache. Finally, the port number has been changed from the default due to the secure connection.
The key when using any Redis library is to ensure that it supports these three things, then once you know that the client supports them, it may still take some investigating to ensure that they are properly enabled when attempting to connect.
When looking at the connection object in python, you’ll notice that SSL is explicitly set to True this is required or you will receive an exception: ConnectionError: Error while reading from socket: (10054, ‘An existing connection was forcibly closed by the remote host’).
The following post is releasing experimental bits for feedback purposes.
If you’re like me, a clean development environment is crucial to being effective. I used to carry around a portable hard drive with my golden image (starting point VM) and a number of other environments I’ve had already configured for the projects I was currently working on. This could be for a number of different reasons, Development, Testing (to address side-by-side browser issues), etc.
One of the sites that helped make my environments simple was Modern.ie as they provided a series of Virtual Machine images with multiple versions of Windows with different versions of Internet Explorer installed. These images are available for users on a Mac, Linux or Windows machine by taking advantage of different virtualization technologies including Hyper-V, Parallels, Virtual Box and VMware Player/Fusion.
I’m pleased to be announcing a new way to leverage the Modern.ie VMs for your testing purposes — Vagrant. If you aren’t familiar with Vagrant, Vagrant is a handy tool for your tool belt which is used to create and configure lightweight, reproducible and portable development environments.
A special Thank You to the Modern.ie team for their hard work working on these VMs to make them available to Vagrant users. Read the License Terms which are offered in the link below which is outlined on the Modern.ie site.
The Microsoft Software License Terms for the IE VMs are included in the release notes and supersede any conflicting Windows license terms included in the VMs.
By downloading and using this software, you agree to these license terms.
A while back, last year actually, I wrote a blog post on how you can Install CakePHP on Windows Azure Web Sites using the App Gallery. At Build 2014 we introduced a new Preview Portal which enables much more to an application owner including in-place billing information, application analytics and a whole new way to visualize your cloud experience.
In this thread, I’ll show you how to create a new CakePHP application via the Preview Portal.