Quantcast
Channel: Andy Hawthorne - Andy Hawthorne
Viewing all articles
Browse latest Browse all 104

PHP Development on Windows

$
0
0

Much as I prefer to develop on a Mac, the reality is: we still have to test on Windows. That got me thinking about what it would be like to develop PHP applications on a Windows machine. Here’s what I found.

First, the development stack

Being used to working on *unix machines the first question was: how do I get everything I need installed on Windows?

There are loads of options:

  • WAMP server
  • XAMPP
  • MAMP
  • etc.

All of these are dead easy to install and don’t need any further explanation here.

To be properly useful though, the stack you choose needs to support:

  • .htaccess
  • Virtual hosts
  • An easy way to to add features

As a minimum.

Hello, WAMP Server

I chose WampServer mainly because I’ve used it a couple of times before.

It’s really easy to install, and provides a nice system tray icon to give you access to all the main features and settings:

In the settings you set the version of PHP, what PHP extensions are installed, and what Apache modules are activated.

You also have access to your alias directories and MySQL.

I like to have URL’s like andy.dev for my projects. On my Mac using MAMP Pro it’s easy to set up. Unfortunately I can’t say the same for WampServer. The good news is, it can be done. The bad news is, it’s a little tricky.

First step – the hosts file

First, you need to add your chosen url to the hosts file. Name-based hosting on a local server generally needs the step so the url resolves properly.

You’ll find the hosts file at:

C;\Windows\System32\drivers\etc

Open up the file in your test editor and add the name of your site at the bottom of the file:

127.0.0.1       yourprojectname.dev

On Windows 7, you’ll have to make sure that you’ve opened your editor using the run as administrator option so that you can save your changes. Each time you create a new project, you’ll need to create an entry in this file.

And now for Apache

Open up:

C:\wamp\bin\apache\Apache2.2.22\conf\httpd.conf

Go to line 467, under # Virtual hosts, uncomment (remove the hashtag [#]) before the line Include conf/extra/httpd-vhosts.conf. Save and close the file.

Next, open C:\wamp\bin\apache\Apache2.2.22\conf\extra\httpd.vhosts.conf

We are going to allow Apache access to our code folder (you can call yours whatever you want) like this:

<Directory C:/Users/Andy/code>
Order Deny,Allow   
Allow from all 
</Directory>

This code goes at the end of the file. Next, after that code, we’ll add an entry for our first virtual host:

<VirtualHost *:80>   
DocumentRoot &quot;C:\Users\you\code\yourproject&quot; 
ServerName yoursite.dev
</VirtualHost>

The important points here are: your document root should be inside the folder you gave Apache permission to (code in this case). The ServerName should match what you added to the hosts file in the first step.

Next, you should choose Restart All Services on your WAMP menu in the system tray. Point your browser at: http://yoursite.dev and away you go…

You will only need to add your required domain name to the hosts file, and an another virtual host entry as above for new sites.


Pretty URL’s

If you code using frameworks (who doesn’t these days?) then you’ll want to be able to use those pretty urls. That means you need your .htaccess file to be read.

That means you need to switch on the Apache mod_rewrite module. That can be done from the WAMP system tray tool too:

That should be it: you can now use pretty urls.


Finally…

So, as it turns out, it is entirely possible to match the basics of your development environment for PHP on Windows as anywhere else. There are still questions to be answered of course. Such as getting Git up and working, and installing Curl. I’ll cover those in a later post.


Viewing all articles
Browse latest Browse all 104

Trending Articles