Existing Umbraco installation fails after installing Articulate blog (or anything that schedules posts)

2017-04-06 13:42:45,673 [P3048/D15/T45] ERROR Umbraco.Web.Scheduling.KeepAlive – Failed (at “http://(domain)/umbraco”).
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Umbraco.Web.Scheduling.KeepAlive.<PerformRunAsync>d__4.MoveNext()

This may be related to: http://issues.umbraco.org/issue/U4-5965 :

“Create config to explicitly set the ‘base url’ for a website that is not running as a load balanced site – used for scheduled tasks/publishing/keepalive”

Setting umbracoApplicationUrl=”https://(domain name)/Umbraco” in Config/umbracoSettings.config …and restarting the application pool and the website has fixed the problem; the site is responsive once more and the required  nodes have been published:
2017-04-06 14:15:00,997 [P3460/D2/T30] INFO Umbraco.Core.Publishing.PublishingStrategy – Content ‘Blog’ with Id ‘3316’ has been published.
2017-04-06 14:15:01,544 [P3460/D2/T30] INFO Umbraco.Core.Publishing.PublishingStrategy – Content ‘Archive’ with Id ‘3317’ has been published.
2017-04-06 14:15:01,638 [P3460/D2/T30] INFO Umbraco.Core.Publishing.PublishingStrategy – Content ‘Test post’ with Id ‘3320’ has been published.
2017-04-06 14:15:01,716 [P3460/D2/T30] INFO Umbraco.Core.Publishing.PublishingStrategy – Content ‘Authors’ with Id ‘3318’ has been published.
2017-04-06 14:15:01,779 [P3460/D2/T30] INFO Umbraco.Core.Publishing.PublishingStrategy – Content ‘Demo author’ with Id ‘3319’ has been published.



LetsEncrypt with Umbraco – serving static, extensionless URLs within an Umbraco installation.

Situation; you have a bunch of domains and subdomains which are secured using Letsencrypt. by default, Letsencrypt will try to put a static, extensionless file like named e.g.  “jCk1zSkjsiuJHrmnSFnxdvkhkjnnNNkjsaaRo” in a “/.well-known/acme-challenge/” subfolder of the site root.

If that file isn’t reachable and browsable – the Letsencrypt acme servers won’t authenticate your domain. Letsencrypt will warn you at this point and recommend re-ordering the IIS Handler Mappings to promote the “StaticFile” handler above the three “ExtensionlessUrl” handlers.

However even if you reorder the handlers, you’ll still see a 404-page not found error when browsing directly to the static file’s URL e.g. http://yourdomain/.well-known/acme-challenge/jCk1zSkjsiuJHrmnSFnxdvkhkjnnNNkjsaaRo

If you check the logs in your Umbraco /App_Data/Logs directory, you may see “Status code is 404 yet TrySkipIisCustomErrors is false – IIS will take over”

IIS won’t log anything useful though.

What’s happening can only be seen once you tell Umbraco not to pass error handling onto IIS; so edit /Config/umbracoSettings.config and set trySkipIisCustomErrors=true

This will force Umbraco to print its own, more informative error, confirming the problem:

No umbraco document matches the url ‘/.well-known/acme-challenge/jCk1zSkjsiuJHrmnSFnxdvkhkjnnNNkjsaaRo’

Finally; to fix the problem and exclude the /.well-known/acme-challenge/ directory from Umbraco’s control, you need to edit Umbraco’s main Web.config file, and add the following:

<add key=”umbracoReservedPaths” value=”~/umbraco,~/install/,~/.well-known/,~/.well-known/acme-challenge/” />

The next time you load http://yourdomain/.well-known/acme-challenge/jCk1zSkjsiuJHrmnSFnxdvkhkjnnNNkjsaaRo in a browser, you should see a plain-text string of json that the acme server needs to authenticate your control of the domain for which you’re requesting the certificate.

Retrying the Letsencrypt client at this point should be successful.

Have a coffee and don’t forget to revert the logging and error handling changes you just made.


Umbraco fails to update log in App_Data/Logs directory – IIS 8.x – Fixed

Umbraco logs a great deal of helpful debugging information to its /App_Data/Logs subdirectory. If the log files aren’t present or haven’t been added to since a server migration, check that the App Pool user has modify access to the directory tree.

If your Umbraco application is running in an Application pool named “Umbraco Blog Dev” the automatically-generated App Pool user would also be named “Umbraco Blog Dev”

If the”Umbraco Blog Dev” user is missing entirely, add it as “IIS AppPool\Umbraco Blog Dev” in the usual permissions dialogue and add modify access afterwards.

Note: the “IIS AppPool…” prefix is essential, as is the server-name Location scope; Windows won’t find the virtual user without both present.


Switch between any installed php version in MAMP

By default, the MAMP’s free UI only lets you choose between php 5.3 and 5.4.
Developing and patching on hosting platforms that don’t or can’t install the latest version as soon as its available makes it useful to be able to choose *any* of the php versions MAMP makes available.

I could’ve just paid for MAMP Pro, but the pleasure of scripting it myself and revising sed and awk in the process couldn’t be missed.

First, awk the currently active php version from MAMP’s httpd.conf – splitting the matched line with a “/” delimiter:

awk -F '/'

then extracting the 6th “chunk”:

{ print $6 }

Then list the php version directories in the MAMP folder, using sed to erase the bits of the wide directory listing we don’t need, finally sorting the result in proper version order:

versionlist=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1n -k 2,2n -k 3,3n`

Full listing:


# Get current php version
currentphp=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
# include the CocoaDialog app for Platypus' benefit.
# Get the list of currently installed php versions in the MAMP hierarchy.
versionlist=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1n -k 2,2n -k 3,3n`
# Create the drop-down menu.
rv=`$CD dropdown --string-output  --text "The drop-down lists all php versions on this system. $currentphp is active. Which do you want to enable?" --items $versionlist --button1 "Ok"` 
# extract the version number from the drop-down result
chosen=`echo $rv | awk -F' ' '{ print $2 }'`
# Replace the decimal points with slashes
fixed=`echo $chosen | sed 's/\./\\\./g'` 
# Overwrite httpd.conf's existing php version with the new, chosen one.
sed -i 'BAK' -E "s/php5\.[0-9]{1,}\.[0-9]{1,}/$fixed/" /Applications/MAMP/conf/apache/httpd.conf
# Restart apache *gracefully*
/Applications/MAMP/bin/apache2/bin/apachectl graceful
# Re-check the current php version in httpd.conf *just in case*   
newphp=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
# ...and tell the user what the current version is. 
$CD ok-msgbox --no-cancel --text "$newphp is now enabled."

Bundling it into a simple [cmd][space] app with Platypus was as easy as including the CocoaDialog package and adding a few messages:

Screen shot 2013-06-11 at 17.25.16

Used in combination with my command line php version selector, I can test against any of 8 different php versions with minimum effort.

Execute scripts with different versions of php

There are several versions of php in my MAMP installation. I’ve built a script (appified with Platypus) that switches between them on the fly, but no elegant way to switch between them in a shell without *typing* redundantly.

So here’s a script to execute a standard .php file on the command line using any version of php on the system; actually any version just here:


Sample usage:

./phpVersionsExec -sv 3.2 -f factory_methods.php

The script accepts partial command line parameters, or runs interactively, or both if your command line is a little flaky. It tries to use sane defaults (reading the current php version from httpd.conf) and allows you to a useful combination of test file and php version… and at that point I stopped scripting before I’d reengineered Wheel v.1.0.


# Functions are defined

    echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    echo "* Usage:"
    echo "$0 [-f lf | filename.php] [-v {sv | hc | php{ n | n.n | n.n.n} }] | [-i] "
    echo "*"
    echo " -i                        - interactive mode."
    echo " -s                        - store php version and filename as defaults."
    echo " -f filename.php           - use filename.php"
    echo " -f lsd                    - use last-stored default filename."
    echo " -v lsd                    - use last-stored default php version."
    echo " -v chc                    - use current httpd.conf php version."
    echo " -v p -f index.php         - use highest version of php on the system."
    echo " -v 5 -f index.php      - use highest version of php 5."
    echo " -v 5.3 -f index.php    - use highest version of php 5.3 if available."
    echo " -v 5.3.20 -f index.php - use php 5.3.20 if available."
    echo "*"
    echo "* The script stores its 'default' php version (-v sd) and last file used (-f lf) in ~/.phpVersionExec.ini."
    echo "*"
    exit 1
initialiseDefaults() {
    # Set store-in-ini-file flag to false 
    # Set goInteractive flag to false 
    # Set found-your-php-version flag to false 
    # Read all versions of php in MAMP folder hierarchy.
    installedPhpVersions=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1rn -k 2,2rn -k 3,3rn`
    # Read defaults from ini file if present.
    if [ -f ~/.phpVersionExec.ini ]; then
	while read line
	do a=$(($a+1));
	    case "$a" in
		1) iniPhpVersion=$line;;
		2) iniPhpFile=$line;;
	done < ~/.phpVersionExec.ini
    # Read current MAMP default php version from httpd.conf  
    httpdConfPhpVersion=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
storeTheDefaults() {
    # Store last exec'd phpVersion and phpFile
    echo "Storing defaults:" 		    
    echo "$execPhpVersion" > ~/.phpVersionExec.ini
    echo "$phpFile" >> ~/.phpVersionExec.ini
    cat ~/.phpVersionExec.ini
execPhp () {
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* Chosen php version is $execPhpVersion"
		echo "*"
		echo "* Running command: /Applications/MAMP/bin/php/$execPhpVersion/bin/php -d display_errors=On -c /Applications/MAMP/bin/php/$execPhpVersion/conf/ -f $phpFile"
		echo "*"
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* PHP output begins:"
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		/Applications/MAMP/bin/php/$execPhpVersion/bin/php -d display_errors=On -c /Applications/MAMP/bin/php/$execPhpVersion/conf/ -f $phpFile
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* PHP output ends."
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		if [[ $storeDefaults ]] ; then
		exit 0
main() {
        # Use the last-stored-default php version or current Httpd.conf php version
	case $phpVersion in
	    lsd) phpVersion=$iniPhpVersion;;
	    chc) phpVersion=$httpdConfPhpVersion;;
        # Use the last-stored-default filename
	if [ $phpFile = "lsd" ]; then
        # Make sure the file exists - if not, go interactive.
	if [ ! -f $phpFile ]; then
	    	echo "The file selected - $phpFile - doesn't exist."
        # If the finally selected phpVersion is one of those currently in the MAMP stack... use it.
	for z in $installedPhpVersions; 
		if grep --quiet $phpVersion <<< $z; then
        # If the finally selected phpVersion ISN'T one of those currently in the MAMP stack... get interactive.
	if [[ ! $phpVersionExists ]]; then
	    echo "Couldn't parse $phpVersion as an installed php version."   
interactive() {
	echo "Enter as accurate a php version as you need:"
        if [ ${#phpVersion} -gt 0 ]; then
	    echo " - ENTER for already-entered $phpVersion"
	    echo " - chc for httpd.conf php version: $httpdConfPhpVersion"
	    echo " - ENTER for httpd.conf php version: $httpdConfPhpVersion"
	echo " - lsd for Last Stored Default: $iniPhpVersion"
	echo " - N, N.N or N.N.N to select an installed php version:"
	echo "$installedPhpVersions"
	read interactivePhpVersion
	if [ ${#interactivePhpVersion} -gt 0 ]; then
	    echo "Defaulting to: $phpVersion"
	echo "Enter the php file you want to execute:"
	if [ ${#phpFile} -gt 0 ]; then
	    echo " - ENTER for already-entered $phpFile"
	    echo " - lsd for Last Stored Default: $iniPhpFile"
	    echo " - ENTER for Last Stored Default: $iniPhpFile"
	read interactivePhpFile
	if [ ${#interactivePhpFile} -gt 0 ]; then
	    echo "Defaulting to $phpFile"

# Check and store any given options.
while getopts "sihv:f:" opt
        case "$opt" in
        v) phpVersion=$OPTARG;;
        f) phpFile=$OPTARG;;
        h) usage;;
        \?) usage;;
	s) storeDefaults=true;;
	i) goInteractive=true;;
# If goInteractive is true, go straight to interactive mode.
if [ $goInteractive ] ; then
# If exactly four arguments are given, go straight to main() initally bypassing the interactive mode.
if [ $# -eq 4 ] ; then
# If a strange number of arguments are given, display the help.

The Factory Design Pattern

After years of hacking around with OOP, MVC, MVVM etc. I’ve decided to gather some usefully distinct examples of design patterns, and create a few of my own with metaphors that work for me.

Today’s pattern; The Factory.

The Factory pattern allows you to more loosely couple the different parts of your application code.

For instance: A class that needs to create a new User shouldn’t have to care (too much) when the definition of “User” changes – subtly or drastically. The Factory pattern grabs the request to build a new user, worries about the details of the job, whirrs away for a few nanoseconds, and drops a shiny new User into the application’s workspace, ready to be used by the original class.

If the first version of the application needs a user with properties like Gender, Age and Name, we can set up those properties’ initial values as the User is created in the Factory.

If the upgraded application needs to add Favourite Colour, Favourite Animal, Mother’s Name to the definition of a User, all we need to do is alter the Factory; no other code needs to change. We could even redirect the Factory to a new, alternate user-creation class.


First an example in PHP:

#!/usr/bin/php5.3 -d display_errors=On -c /Applications/MAMP/bin/php/php5.3.20/conf/
Different php binaries and conf directories for various MAMP php-cli versions 
(chmod+x factory.php, then run it from the command line as: ./factory.php):
#!/usr/bin/php5.2 -d display_errors=On -c /Applications/MAMP/bin/php/php5.2.17/conf/
#!/usr/bin/php5.3 -d display_errors=On -c /Applications/MAMP/bin/php/php5.3.20/conf/
#!/usr/bin/php5.4 -d display_errors=On -c /Applications/MAMP/bin/php/php5.4.10/conf/
error_reporting(E_ALL | E_STRICT);
print "PHP Version: ".phpversion()."\n";
interface IUser
  function getId();
  function getName();
  function getGender();
class User implements IUser
  public function __construct( $id ) {
    $this->id = $id;
    if ($this->id > 100)
	$this->name = "Jack";
	$this->gender = "Male";
	$this->name = "Jill";
	$this->gender = "Female";
  public function getId()
    return "id was ".$this->id;
  public function getName()
    return $this->name;
  public function getGender()
    return $this->gender;
class UserFactory
  public static function Create( $id )
    return new User( $id );
$u0 = UserFactory::Create( 99 );
echo( $u0->getName()."\n" );
echo( $u0->getId()."\n" );
echo( $u0->getGender()."\n" );
echo( "Direct reference to u0->id: ".$u0->id."\n" );
$u1 = UserFactory::Create( 102 );
echo( $u1->getName()."\n" );
echo( $u1->getId()."\n" );
echo( $u1->getGender()."\n" );
echo( "Direct reference to u1->id: ".$u1->id."\n" );
echo( "All done" );
//borrowed *heavily* from http://www.ibm.com/developerworks/library/os-php-designptrns/


CSS tricks with pseudo elements.

Sometimes simple jobs in restrictive frameworks make for interesting problems. Somerset Film (The Engine Room) love WordPress.com as a playground/sketchpad. Today’s problem was http://inspiresomerset.wordpress.com/ – decorated with AlienWP’s Oxygen theme but still needing a few CSS hacks to bring it up to spec – so I got involved.

When altering someone else’s css; make sparing, targeted changes and assume as little as possible – class-names are designed be re-used, so reference them uniquely by their position in the page hierarchy.  The “>” css child selector is useful here; it forces the browser’s parsing engine to ignore all but parent-child relationships, saving browser-power and time (where we still have to care about power and time).

The only unusual aspect of the job involved replacing a large image – enforced by the theme – with editable text. Setting the image’s css to display: none; hid it; but to replace it I used the before pseudo element to squeeze in extra text *before* the target class’s normal content:

#primary>#content>.recent-articles:before {
 content: "We are a new consortium of Somerset artists and producers bringing the skills and experience of professional arts and media direct to your school, children's youth centre or youth organisation. We have put together an offer we intend will be useful as well as inspirational and we look forward to hearing your feedback and ideas for taking the work forward - so do get in touch soon - subscriptions are open from March 25th.";

…end result:  Somerset Film are able to edit the front page text with their CSS admin form, independent of any post or page.