Sunday, July 26th, 2009
Setting up your development environment
Welcome to the the first part of my tutorial series outlining how to build a website from scratch.  In this post I'm going to explain how to set up a development environment. Basically this means that I'll be walking through the steps necessary to set up a real live web server running directly on your personal computer.

This is how I (and many other web developers) write software.  You get everything working on your local server (or development server) and then move it to the live server (or production server).  

 

So let's get started.  I use Windows, and this tutorial will assume you do the same, although it should be pretty easy to translate this into Mac OS or Linux terms.

Installing WAMP
The web server that I use involves three main components:
  
  • Apache is the actual "server". It takes requests from a web browser, decides how to process them, and sends the results back to the browser.
  • PHP is a scripting language.  This is what most of the actual "programming" is done in.  When Apache receives a request for a web page, it tells the PHP server to do all the heavy lifting
  • MySQL is the database program.  It stores data which is accessed by PHP through queries.
localhost
You could install all of these components separately, or you could install a program called WAMP (Windows, Apache, MySQL, PHP).  Download the most recent version and you're done.  Once it's installed, open up a web browser and go to "http://localhost".  If it's working correctly, you should see something like the image on the right.




Installing SQLyog
sqlyogThis isn't absolutely necessary, but I recommend installing a program to help you access the database.  I use SQLyog which is a pretty frustrating program (poor user interface) but it offers exactly what I need.  If you want to use it, click the link and download the community edition (it's free).

Once you install it, try connecting with the default settings.  Make sure you see the image to the left on your screen and click "Test Connection".  Hopefully everything's working for you.

We don't actually need to do anything with the database yet, so you can close SQLyog once you get it working.


 

Set up the file structure
Now that you've got everything installed, let's start creating the project.  You should have a folder at C:wamp/www on you main drive (assuming C is your main drive).  This "www" folder is the root of the project.  That's where all the files you make will go.

You probably already have a file called "index.php" in this folder.  We'll talk later about the significance of this file, but for now, open it up in notepad, delete everything in that file, and replace it with the following:

 

<?php
include_once('include/init.php');
?>

 

Don't worry yet about what any of this means.  Just trust me.  Now make a subfolder of "www" called "include" and make a new file inside called "init.php".  If you're not sure how to make a php file, browse to that folder, right-click in it and select the "New > Text Document" option.  Name it "init.php" and then ignore the warning Windows will give you about changing the extension.  Then open the file in notepad and type in:

 

<?php
die("Hello World!");
?>

 

Ok, that's all you need to do with the file system for now.

Change the php.ini file
Your PHP server has all kinds of different configuration options.  These options are set in a file called "php.ini".  To access this file, click the WAMP icon in your task tray and go to "PHP > php.ini".  This should open up a text document.  The one thing we need to change is the include path.  We need to point it to the root of the project so that we can easily include a library that we'll build later.

php.ini

After opening php.ini in Notepad, hit ctrl+f to search for the following line:

;include_path = ".;c:\php\includes"

 

Change it to

include_path = ".;c:\wamp"
Notice that the semi-colon at the beginning of the line isn't there anymore.  That semi-colon commented out the line so that it wasn't used in the configuration.  By deleting the semi-colon and setting the include path to point at the "wamp" folder, we're telling PHP to let you include files from your project.

Save and close that file.  Whenever you make a change like that, you need to restart the WAMP services.  To do this, click on the WAMP icon in the task menu and select "Restart all services".

 

Change the hosts file
There are a lot of things working together that allow someone to type a URL into their web browser and get back a web page.  The first thing is making sure that the computer is translating the URL into the IP address of the server.

For example, if someone types "google.com" into their browser, the first thing the computer does is figure out Google's IP address.  It does this using something called a DNS server.  We need to establish a domain name for your local server the same way, but we can't really tell DNS servers about it (since your dev server only exists locally).

In windows, there is a file called "hosts" stored in the C:\WINDOWS\system32\drivers\etc folder. This file lets you manually set IP addresses for specific Domain names.  Open the file up in notepad and add this line to the bottom:

127.0.0.1 calendardev
Save and close the file.  That extra line tells your computer that if you type "calendardev" into the address bar of a browser, it should forward the request to the IP address: 127.0.0.1 which is the IP address of your new apache server.

Test it out
Let's recap what we just did.  We installed a server on your PC, installed a program to help you access the database, set up your project in the "/wamp/www" folder, reconfigured PHP to include files from your project automatically, and told Windows that "calendardev" is the name of your website.

If everything worked correctly, you should be able to type "http://calendardev" into the address bar of a web browser and see a blank white page that says "Hello World!".  If you see that, you did everything correctly.  If you don't see that, leave a comment and I'll be happy to help you figure out what went wrong.

I realize that this hasn't been very informative.  I told you what to do and you did it, but you probably have no idea what's going on.  Don't worry, you won't ever need to deal with this configuration stuff again.  If you do, you basically just follow the same steps.  I might explain this stuff in more detail at some point, but for now just consider it black magic that's an unfortunate prerequisite to actual web development.

Stay tuned for the next installment of this tutorial series.  I'll explain to you how to use html to make a calendar show up on a website.



This post has 0 Comments

Leave a comment

Please fill this out to prove you aren't a robot.
You can Create an Account or Log in to hide this.
Name: Required
Email: Required. This will not be shared
Your Website: Optional
Comment:
Email me if other people comment on this post
Receive Email Updates:


About this site
Hi, I'm Tyler King and this is my blog. It's about programming, graphic design, UI design, and anything else related to software development. You can read this post to learn a little bit more about what I'm trying to do here.

If you're interested in learning more about me, check out my Portfolio, Bio or Resume.
Search
Tips
If you have any feedback about the site or you have a topic you'd like me to write about, send an email to tips@TylerKing.net.
Archives
2010 (2)
March (2)
2009 (88)
August (6)
July (17)
June (20)
May (33)
April (12)
Links

More about me:


My friends:


Sites that I really like:


Blog
Portfolio
Resume
Bio
Contact
© 2010 - Tyler King