Some environments are just better suited to do a particular type of work. If you want to play tennis you will feel more comfortable in a tennis court. If you want to enjoy the summer, you will feel comfortable at the beach. If you want to develop using PHP, you will feel at home with Linux.
Modern computers do their best to prevent users from changing the Operating System. I recently bought a Laptop and it wouldn't let me install any other OS other than Windows. I commonly use tools like PHP, node, lesscss and since they were designed on Linux machines, they just tend to work better there. And also I am more familiar with the Unix like command line interface. In order to spend more time programming and less fighting the machine, I would prefer to use those tools on Linux, even though my current laptop runs Windows 10.
No! I refuse to run PHP with IIS. Instead I want to use Apache. And not the Apache that comes with WAMP. I want to use Apache in its native environment, Linux. On my Windows machine! Believe it or not this is not crazy talk. There is one simple solution to do so. Virtual Machines
Virtual Machines, in layman terms, is a program that lets you run an operating system inside your current operating system. I have used Virtual Box and never found any reason to use anything else. So I will tell you about my current setup.
Whether you are using Windows, Mac or Linux, you can head to Virtualbox.org and download the latest copy for your operating system.
When you download and install, you can create a new Operating System. In order to do so, you will need to have a copy of the OS. Luckily for us, you can grab a fresh copy of Ubuntu for free.
When it comes to recommending a version of Ubuntu, I always stick to LTS versions. LTS stands for Long term support, meaning you get to enjoy updates and security fixes for a full 5 years. But it is just as secure to download a normal versions, just make sure to upgrade it constantly.
We will need the
.iso file you downloaded to boot and install the operating system. Installing the operating system is intuitive.
Installing Ubuntu (Linux)
Open Virtual Box. Click on New. Select Linux then Ubuntu. You can accept all the default settings. Just make note of the size of your virtual drive. Make sure you have enough space on your machine, I usually set it to 8GB for small projects and 512MB memory.
Now it's time to install. Remember that ISO file we downloaded? We need to make the new operating system believe it is a CD and boot from it.
Go to your settings, and under storage, click on the small disk next to 'Controller IDE'. Click on 'chose disk' and select the ISO file. Now we are ready to boot.
Click on start, follow the instructions and you will have a brand new Ubuntu box ready to work with.
PuTTY, your friendly ssh client.
Although you can connect to your virtual machine directly by opening the window where it resides, I tend to use PuTTY to get the job done. The reason is, it allows you to open multiple terminals to the same machine.
Static IP address
Every time you boot up your VM, there is a chance that it will be assigned a new IP address. This can be a pain, because you constantly have to update your host file to match the new address. To solve the problem, we need to assign the VM a static address.
Start by making sure your VM is shutdown then go to virtualbox's settings (File
-> Settings). Click on the Network tab, then on Host-only Networks. Add a new Adapter by clicking on the plus sign and setting the ip address like the figure below.
Awesome, now boot your VM. With
sudo open this file:
/etc/network/interfaces. And add these lines of code at the end:
# My Custom Host Only
iface eth1 inet static
Note that I set my ip address to be
192.168.56.20, you can set it to whatever you feel like. Restart your VM and we are set. Our machine now has a static ip address.
Let's use our machine now.
Well, the point of this whole exercise was to be able to run Apache, and other Linux software in their native environment. Well, let's get to it.
We can start by installing Apache with this command:
sudo apt-get install apache2
Once installation is complete, you can test it by running it in the browser.
http://< vm ip address >
and you shall see your default Apache page working. You can always go to your host file (
C:\Windows\System32\drivers\etc\hosts) and assign a specific hostname to the ip address
If you don't like working from the terminal and want to write your code on your IDE on windows, you can easily create shared folders. On your Virtual Machine's settings, you can select a folder on windows to share, then you can follow my sharing folders tutorial for Ubuntu(You only need to client part).
That's it! This is the setup I use to work on my PHP projects on a Windows machine. With the addition of source control like git or subversion, I can seamlessly work on all my home machines without writing code to detect which operating system I am working on. Now you can too.