Modern web development involves an amalgam of constantly shifting technologies. When any given project begins its technology stack is often a snapshot of what’s available, what matches the requirements, and what fits the budget. This dynamism offers fantastic opportunities to keep new sites fresh and interesting, but it can make the process of development more challenging and time consuming than it needs to be.
.NET developers often run into problems working with Linux-based web technologies like the ubiquitous LAMP stack or the increasingly more common MEAN stack. Other technologies like Ruby, many NoSQL databases, and Docker also fall into the “Linux first, Windows maybe” category. Until very recently Windows developers had to dual boot, use VMs or maintain a completely different machine to keep a foot in both the .NET and Linux worlds. Now, however, there is another option - the Windows Subsystem for Linux.
Windows Subsystem for Linux
There was a time, not too long ago, when it was common to see the denizens of the internet refer to Microsoft as “M$.” As the largest - and for many, only - game in town, the company’s practices rankled a lot of software developers at a time when the open-source community was just starting to come into its own. If you were to dig a commenter out of the internet’s Pleistocene layer they would be hard-pressed to imagine a version of Windows that not only played nice with Linux, but that had a version of Linux built into the core operating system. And yet, that is exactly what has happened.
The Windows Subsystem for Linux is a compatibility layer for running certain Linux binaries natively on Windows 10, albeit with a few limitations. The most noticeable limitation is that there is no Linux GUI available. This may be annoying, but remember that Microsoft is positioning the Windows Subsystem for Linux as a way for developers to access BASH and native Linux command-line tools. Next, not all Linux kernel services have been implemented, so software that relies on the unimplemented services will not work. Finally, at the moment the only Linux image available is a version of Ubuntu 14.04 that was created by a Microsoft and Canonical partnership.
Installing Ubuntu on Windows
In order to use the Windows Subsystem for Linux, you’ll need to ensure that your PC meets the following requirements:
- 64-bit version of Windows 10 with the Anniversary Update (build 14393, released 8/2/2016)
- AMD/Intel x64 compatible x64-based processor
- You need to be a member of the Windows Insider Program
1) Turn on Developer Mode
The Windows Subsystem for Linux is a beta feature intended for developers, so in order to use it you need to have developer mode enabled:
- In Windows, navigate to Settings -> Update and Security -> For developers
- Select the “Developer mode” button
2) Enable the Windows Subsystem for Linux
The feature is disabled by default so it must be manually enabled:
- Press Start and type “turn” to find the “Turn Windows features on or off” menu
- Find and check the Windows Subsystem for Linux (beta) option, then click “OK”
- Once the installation is finished, restart your computer
3) Install the Ubuntu Image
Once your computer reboots and the Subsystem is installed, you need to actually install the Ubuntu image:
- Open a command prompt
- Run “bash”
- Accept the license and wait for it to download and install
4) Set up Ubuntu
With the image downloaded and installed, you’ll automatically be prompted to set up your credentials. The first prompt asks for a UNIX username. This will create your Ubuntu user, which is distinct from your Windows user. Once you’ve chosen a username, you’ll be prompted for a password which is, again, distinct from your windows password. After that’s complete, you’ll be dropped into the Ubuntu BASH shell. Congratulations, you have Ubuntu in your Windows!
What Now? Install Apache!
Now that you have Ubuntu running happily in your Windows 10 machine, what should you do with it? If you’re a web developer, you probably want to install Apache and PHP so you can start getting some work done.
1) Install Apache
- Use apt-get to install apache: “sudo apt-get install apache2”
2) Start the Apache Service
Once Apache is installed, start the service.
- Type “sudo service apache2 start”
This will start Apache if you don’t have anything else listening on port 80. If you do have something listening on port 80, you’ll have to change the port that Apache listens on.
- Open “/etc/apache2/ports.conf” in your favorite Ubuntu text editor
- Find the line that reads, “Listen 80” and change the value to a port that you know is available, then save and close the file
- Open “/etc/apache2/sites-available/000-default.conf” in your favorite Ubuntu text editor
- The first line should read “<VirtualHost *:80>” Change the port, “80,” to match the port that you set in “/etc/apache2/ports.conf,” then save and close the file
- On the command line type “sudo service apache2 start”
Now that Apache is running, navigate to “localhost:81” in a Windows browser of your choice and verify that the Ubuntu default page is being served properly. Remember, the default location for Apache sites is “/var/www/html”.
And Now it’s Time for PHP
PHP is hugely popular, however getting PHP working properly on Windows has always been a less than pleasant experience. Now that Ubuntu and Apache are running natively on Windows, though, setting up PHP is much easier.
1) Install and Verify PHP
Using apt-get again, install PHP and then verify that it’s working.
- Type “sudo apt-get install php5”
- In the default web site directory, “/var/www/html,” create a file named “phpinfo.php”
- Edit “phpinfo.php” so that it includes the single line, “<?php phpinfo(); ?>”
- Save and close “phpinfo.php” and return to the BASH shell
- Restart the Apache server with “sudo service apache2 restart”
With PHP installed you can navigate to “localhost:81/phpinfo.php” and you should see the details of PHP’s configuration.
With Apache and PHP running natively on Ubuntu you can develop in those environments using familiar BASH tools - however, there are some limitations. For example, your Windows drives are accessible in Ubuntu under “/mnt,” but your Ubuntu file system is not accessible in Windows. As you explore the Windows Subsystem for Linux, keep in mind that it is beta software, so there will be some bugs.
Finally, if all else fails, you can uninstall Ubuntu from an elevated Windows command line with the command “lxrun /uninstall /full”
Florida-born Tom Stachowitz spent his childhood in northwestern Connecticut, and the rest of his life everywhere else, including England, Greece, New York, Arizona, Colorado, Washington DC, and Virginia. After college and serving time in the Army, he’s back in the Nutmeg State where he’s focuses on writing, technology and keeping Mintz + Hoke staff in the know. Tom’s spare time is spent hiking, gaming, and spending time with his family, including beautiful wife, Krista, and their furbabies, Ajax and Luna.
Keep me posted
Enter your email and we can notify you when new articles are available.