Loading, please wait...

picture of me
Joe Rushton Fullstack Web Developer

Setting up a Windows machine for a focused PHP development environment

08th September 2017 Reading Time: 17 mins
Tags: General PHP

Here's my guide on how to setup a Windows machine ready to blast out those PHP web apps.

The aim of this guide is to get the ball rolling straight away so you can start coding and stop fiddling around with installers and configration, I won't be teaching you how to use the tools - just how to set things up.


Version Control

First things first, let's get GIT installed on your system for version controlling all of your projects. Download this: https://git-scm.com/download/win and follow the install wizard. This installs the GIT software along with a bash shell which allows you to use GIT on the command line. Go to start > search for "Git Bash" and open it up. Type git --version to verify it's installed.

Verify Git Installation

Then my personal preference on the GUI tool is SourceTree. Download and install for free here: https://www.sourcetreeapp.com/ - you will need to create an Atlassian account during the installation.



Next up we need to set up an SSH key on your system which allows you to connect to web servers and deploy websites. We can actually use Git Bash which we've just installed to make this super quick. Open git bash and enter ssh-keygen. It will ask you a location which should be pre-populated with something like "C:/Users/your-name/.ssh/id_rsa" - this is the standard location for SSH keys (or ~/.ssh/id_rsa for short). A passphrase is optional but make sure you don't forget it.


Node.js & NPM

You are very likely going to be using node package manager (npm) at some point so why not install it now: https://nodejs.org/en/ Download and Install the LTS version and then re-open Git bash and enter node -v then npm -v to verify they have installed.



When you want to manually upload files onto a webserver you will require an FTP client. FileZilla is lightweight and free - download and install here: https://filezilla-project.org/ 



Installing PHP is a pretty obvious requirement for PHP development. I found XAMPP to be the easiest method for this (nb: XAMPP is a fully fledged local web server with MySQL, PHP and Apache but we're only using it for the PHP that comes bundled in the installer) https://www.apachefriends.org/index.html - download the latest version for windows and go through the install wizard.

For consistency, I will be using the htdocs (c:/xampp/htdocs) directory for all of my projects. This is the default directory that XAMPP looks in for your code. E.g. if you were running xampp and went to localhost/test/index.php in a browser, it would execute c:/xampp/htdocs/test/index.php. Even though we aren't using XAMPP, I'm choosing to use this directory to give us that option without any extra setup.



SASS is a must have CSS pre-processor - download the Ruby installer for windows here https://rubyinstaller.org/downloads/ and execute. Once installed, type ruby -v into Git bash to verify it's installation.

Now that Ruby is installed, we can use the gem command to install sass:

gem install sass again enter sass -v to confirm it's installed.

 Verify Ruby & Sass Installation



Pretty much all 3rd Party PHP libraries will be available as a composer package, so for the sake of being able to install a package into any project with a single command, you will definitely need composer. Direct download for windows can be found here: https://getcomposer.org/Composer-Setup.exe - it will ask for the PHP path, it should be pre-populated if you've installed XAMPP.


Text Editor

Install Sublime here:

Now open up Sublime Text 3 and press Ctrl+Shift+P, type in "Install Package" and press enter on "Install Package Manager". Once completed, press Ctrl+Shift+P again, type "Install package", press enter, type "SidebarEnhancements" and press enter. Then open the install packages again and type "Material Theme" and press enter. Install the package called "SASS" as well as "Emmet".


Last part of sublime configuration will be the font and theme activation. I don't want you to strain your eyes so go to Preference > Settings and make your right panel look like this and then save:

	"color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme",
	"font_size": 15,
	"line_padding_bottom": 5,
	"line_padding_top": 5,
	"theme": "Material-Theme-Darker.sublime-theme"

 End Result: a rather pretty looking code editor

Sublime Text Code Editor


Local Web Server

Technically we've already installed a web server if you've made it this far (XAMPP) which is perfectly fine for local development and if you're happy to work with XAMPP then feel free to skip the next couple of steps. From experience I prefer to use a virtual web server to closer emulate how my projects would behave on a live web server and to give me the freedom to configure the server, change PHP versions, simpler vhost configuration etc.

Firstly we need virtual box software: Download and install here.

Next up is vagrant which allows us to configure virtual box: Download Here - again, simply download and install. Enter vagrant version in git bash to verify. If installed successfully run the following command to install windows NFS plugin 

vagrant plugin install vagrant-winnfsd

(using NFS improves vagrant performance significantly, but doesn't work out of the box on windows).

Rather than setting up our own vagrant box from scratch, I like to use Laravel Homestead. Open git bash and enter 

vagrant box add laravel/homestead

Then goto our aforementioned project folder:

cd /c/xampp/htdocs

and run:

git clone https://github.com/laravel/homestead.git Homestead

which has downloaded Laravel Homestead into C:/xampp/htdocs/Homestead. Now open up init.bat from inside that directory and edit the newly generated Homestead.yaml file. We need to change the authorize and keys options to point to the SSH key we created earlier:

authorize: C:/Users/your-name/.ssh/id_rsa.pub

    - C:/Users/your-name/.ssh/id_rsa

Tell it where our projects will be stored (type nfs won't work if you didn't install the vagrant NFS plugin above):

    - map: C:/xampp/htdocs
      to: /home/vagrant/Code
      type: "nfs"

For the next part we need some code to make sure our setup will work. Create C:/xampp/htdocs/test/index.php and populate the file with this:


echo "Hello World!";

Now add your project to the "sites" section of our config file:

    - map: test.app
      to: /home/vagrant/Code/test

This tells homestead that when you go to the URL test.app, it will load our test directory. We also need to tell windows that when we got to test.app, it should load homestead which is done in the windows hosts file. Open up notepad as an administrator. Go to file > open, change the file type to all and open C:\Windows\System32\drivers\etc\hosts.

Add this line to the bottom of that file and save:	test.app

Finally we can turn homestead on by running

vagrant up --provision

in Git Bash from the Homestead directory.

For more projects, all you'll need to do is add the site to the "sites" option in the homestead.yaml file as well as the hosts file and run the following:

vagrant reload --provision

You may find that the vagrant box freezes at this stage (SSH auth method: private key):

vagrant crashing

You will need to enable virtualization in the BIOS - which requires you restarting your pc and pressing the DEL key (or whichever key your motherboard states to enter the UEFI/BIOS mode). Then you just need to find the virtualization option and turn it on.



Homestead comes with MySQL, so by running vagrant up we have it all setup already and can access it through git bash. However if you're like me and prefer to work through a GUI, a super quick way to get this setup is by downloading Adminer here, rename the file to index.php and place it inside C:/xampp/htdocs/adminer.

Now update your homestead.yaml and hosts file to allow access through the browser like so:

homestead setup

hosts file

Reboot your vagrant box with:

vagrant reload --provision

Visit db.app and use homestead / secret as the default username/password. From your PHP app you can connect to your databases with localhost and port 33060


Finishing Touches

Here are a couple of time-savers that I recommend:

Create a .bashrc file inside C:/Users/your-name like this:

touch ~/.bashrc

Then add the following contents to that file and reload git bash:

alias projects="cd /c/xampp/htdocs"
alias server-up="cd /c/xampp/htdocs/Homestead && vagrant up --provision"
alias server-reload="cd /c/xampp/htdocs/Homestead && vagrant reload --provision"
alias server-down="cd /c/xampp/htdocs/Homestead && vagrant halt"

This allows you to jump to your projects folder with the command projects as well as turn on/reload your homestead server with server-up server-reload and server-down

I also suggest bookmarking db.app in your web browser and pinning Git Bash, SourceTree, Sublime and Filezilla to your taskbar.

That's all folks.

Back to Homepage

Find me on social media