Thursday, March 22nd, 2007...10:48 am
How To Setup A Local Development Environment In Windows Using Apache, PHP, and MySQL
Deprecated: Function eregi() is deprecated in /nfs/c02/h06/mnt/46791/domains/thewrongadvices.com/html/wp-content/plugins/tpbc.php on line 96
For a long time I used to code on the fly, downloading files, making changes, then reuploading them to the server. It’s a nauseatingly slow way of doing things and if you make a mistake somewhere you’ve just killed your website.
So when I started getting serious about developing I switched to a local development environment. For most of the work I do this involves an Apache web server, PHP, and a MySQL database server. This setup is also perfect to use with WordPress. You can test your changes locally before committing them to your live server.
Now you might be thinking there’s alot of effort involved in setting up a test server like this but really it’s quite straight forward and I’ll take you through those steps now.
First of all you need to download the installation files. We’ll be working with the latest versions of each. Make sure to get the Windows versions that come with an installer.
Once you’ve downloaded those three files your ready to begin. We’ll start with Apache.
This is all pretty straight forward.
Run the Apache .msi install file, and follow the prompts until you get to the window that asks for server information. Enter the following:
- Network Domain: localhost
- Server Name: localhost
- Administrator Email: any email address
Keep following the prompts until Apache is installed.
To test everything is working properly open up a browser and enter localhost as the URL.
If Apache has been installed correctly and the server is running the text should read: It Works!
Next up is PHP. Again this is pretty straight forward.
Run the PHP .msi install file.
When prompted to choose a Web Server select Apache 2.2.x Module.
Next you will be asked for the Apache Configuration Directory. You will want to navigate to where you installed Apache and find the conf directory.
In my case I installed Apache in the default directory so this is where I pointed the installer:
C:\Program Files\Apache Software Foundation\Apache2.2\conf
The next step is important otherwise PHP won’t be able to work with MySQL.
The MySQL extension for PHP isn’t automatically selected so you will have to go in and choose it manually. While your there you may want to see if there are any other extensions you want installed.
Follow the prompts to complete the install. Afterwards you will be asked if you want the installer to configure Apache. Click Yes, and your done installing PHP.
Installing MySQL Server
Unpack the zip file and run Setup.exe.
For setup type, choose typical install.
Once MySQL Server is installed skip the signup and move onto configuration.
Select Standard Configuration and continue.
Leave Install As Windows Service checked and continue.
Next you will be prompted for a password. This is the password you will enter whenever you use the MySQL Command Line Client.
Once that is done MySQL server will be configured and then start up. The MySQL server is now installed.
Getting It All Working Together
Now we’re almost done. There’s just a few things left to configure manually and then your good to go.
First off you want to go back to where you installed Apache and go into the conf directory. Open up the file “httpd.conf”.
Look for this text:
Change the middle line so that it reads:
DirectoryIndex index.html index.php index.php5
Now the next change is optional. By default the directory that will contain your html files will be htdocs in the Apache directory. I prefer to use a directory in a more easily accessible location so I changed it. To do that you need to change the following two lines.
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”
<Directory “C:/Program Files/Apache Software Foundation/Apache2.2/htdocs”>
Congratulations you’ve now completed the Apache/PHP/MySQL install.
One More Tip To Help You Get Started
Creating a new MySQL database using the command line client can be a little intimidating so here’s a small tutorial on how it’s done.
First of all open up the MySQL command line client. Enter the password you chose during the MySQL installation.
A prompt will be displayed that looks like this:
To create a database called my_database we would enter the following at the prompt:
CREATE DATABASE my_database;
Next we need to create a user and assign that user privileges.
To create a user with all privileges to my_database, with the username johndoe and password turnkey you would enter the following at the prompt:
grant all privileges on my_database.* to johndoe@”localhost” identified by ‘turnkey’;
Have fun with your new test server.