Getting Apache to work under Ubuntu on Windows Insider Preview build 14316

OK – so that’s a very long title to this post for what is actually a very simple solution.

Like many I’m sure I was eager to try the new build of Windows 10. The first thing I wanted to try when it first booted? Ubuntu and bash of course.

By default, it’s not installed, you have to go into Windows Update Settings, down to ‘For Developers’ and make sure ‘Developer Mode’ is switched on.

Then you have to hit windows key, type ‘Windows Features’ [enter], and scroll to the bottom of the list and tick ‘Windows Subsystem for Linux (Beta)’.

For some I gather you then need to reboot, but on my machine it didn’t.

Anyway, after all that, I thought, ooh, let’s try running Apache on Ubuntu on Windows.

First I typed ifconfig to see what ip address it had, was it different? .. well that command doesn’t work yet so I was thinking maybe apache wouldn’t work either.

So I installed with ‘apt-get install apache2’.

It installs fine, but its not running. It throws the error:

mktemp: failed to create directory via templat ‘/var/lock/apach2.xxxx…’.

Turns out that /var/lock is a symbolic link to /run/lock, which doesn’t exist.

So all you need to do is mkdir /run/lock, restart apache, and hey presto you are up.

But what IP address is it at? .. as Ubuntu is running natively on Windows there is no virtualisation so it has the same IP address as your local machine.

So browsing to localhost should do the trick. If you have another service using that port then edit /etc/apache2/ports.conf and change to a different port.

Hope that helps a few people.

Read More

PHP Enforce Errors

When debugging code I always want to force PHP to display all the errors, including any warnings so I can make sure my code isn’t doing anything unexpected. Its something I do so often that I should know the two lines of code off the top of my head. If I really thought about it I probably do but sadly Google + Copy / Paste is actually quicker than typing it out. So as much for my own benefit as anyone elses, here are the two lines of code I use over and over:


error_reporting(E_ALL);
ini_set('display_errors', '1');

Read More

AngularJS nested controllers

When you are new to Angular it can seem very confusing. One thing that gets especially perplexing is scope, where variables in your project can be accessed. This post looks at nested controllers and how that affects scope and we also look at whether they are passed by reference or by value between controllers.

We’ll use a very simplistic example:

Here we have defined the name variable in the parent and displayed it in both parent and nested controllers. What you will notice is any variable in the parent is automatically available to the child. However, be careful, if you are passing anything that isn’t an object then it is passed by value so if you try and change its value within the nested controller that change doesn’t propagate to the parent.

Now lets look at a different example, encapsulating that name variable into an object:

You will now notice that when you edit the name, both the nested controller and the parent controller are updated. This is because objects are always passed by reference, so in summary anything you want to persist between controllers should be encapsulated within an object first.

Read More