BETA version 0.4.5 "Defiant"
Report bugs to beta@denyconformity.com

DenyConformity.com

How to Make a Website: Part 2

Series: How to Make a Website

So you’ve enabled your computer’s secret ability to be an Internet. Big deal! What do you do with that puny little Internet of yours? You make a website, of course! Ok, then, off you go; go have some website. What, you still don’t know how to website?

Oh, right, that’s what I’m trying to teach you. Well, we had better get started, then.

Part 2: PHP Doesn’t Stand For Anything

We have to start with a bit of a lecture, I’m afraid. Essentially, the Internet is made up of two types of computers - servers and clients. Your computer’s browser is a client. It connects to websites and downloads HyperText Markup Language (that’s what HTML stands for) so you can read about celebrities and check Facebook statuses. A server compiles lots of code and does all sorts of magic on it before sending it out to the client as HTML. As you might imagine, there are therefore two basic types of programming for the Internet - server-side and client-side. The end goal of all web programming, whether on the client or the server, is to generate certain HTML markup for the browser to display. For the most part, then, all languages for making websites are designed to wrangle data somehow, turn it into HTML somehow, and send it to the browser somehow. This is about as basic as I can be without just saying “ELECTROBOX DO MAGIC.”

One popular client-side programming language is called Javascript (it’s actually a scripting language, but we don’t need to get that specific). A popular server-side programming language is called PHP (again, it’s a scripting language, but whatever). Neither is better or worse, they have very important strengths and weaknesses and are used for very specific and different things. How this matters to you is that you need to configure your new web server to handle the server-side technologies that you’re going to throw at it. Since client-side stuff doesn’t happen on the server, your server could not possibly care less about it. By default, Microsoft’s web server technology (IIS) doesn’t know how to deal with PHP, so we need to tell it what’s up.

There is some contention over what PHP actually stands for. Originally it meant “Personal Home Page” but now it stands for “PHP: Hypertext PreProcessor” which doesn’t really make any sense. Anyway, just head over to windows.php.net/download/ and download the latest Non Thread Safe version of PHP (get the first “Zip” on the page). Don’t worry about “Non Thread Safe.” That’s just technical mumbo-jumbo that means nothing to you.
Open up a Windows Explorer window (do this quickly by holding the Windows Key - the little flag button between the left control and alt keys - and pressing “E”). Go right to C: and create a new folder simply called “php” right there.
Extract the contents of that Zip file you just downloaded from php.net into your new php folder. At the time of writing this post the latest version of PHP (5.4.2) has three folders and 41 files to extract into there. I won’t hold your hand and tell you how to extract Zip files, but if you’re having trouble maybe making a website isn’t for you.
PHP relies on this super config file called php.ini. You should find two versions in your php folder, php.ini-development and php.ini-production. These are sample files that have most of the usual configuration settings for those environments. Since we’re setting up a development environment, we can use that one. Just rename that file “php.ini” You should probably disable the “hide file extensions for known filetypes” setting in your folder options if you haven’t already.
You can just open php.ini in Notepad, now (right click it and go to “open with”). This can be a really intimidating file, so try not to get lost in all that crazy stuff. Also, don’t touch anything, because you can cause lots of problems if you mess something up here. Just find the following settings and make sure they’re set as such (you can hit Ctrl + F to search for each setting). Each setting should be on its own line, and will probably have a semi-colon before it. Make sure you remove that semi-colon, as it tells PHP to ignore the line. To be clear, make sure your php.ini file has the following things all on their own lines exactly as they are here:

fastcgi.inpersonate = 1

fastcgi.logging = 0

cgi.fix_pathinfo = 1

cgi.force_redirect = 0

If you are a wimp or something, you can just download the php.ini file I prepared for this tutorial and put it in your C:/php folder (make sure to rename it “php.ini” too). It is for PHP version 5.4.2, but it will probably work for any version 5.whatever.whatever.

Remember how to get to the IIS Manager? There’s actually an easier way. Just press the Windows Key and “R” at the same time to open the Run dialog box. Then type “inetmgr” into the box and hit Enter (or click OK). I told you the slow way before so you get this neat little reward for coming back to read the second part of the tutorial. Good work, you.
Are you super happy to see the old IIS Manager again? We’re going to tweak and add a few settings to your brave little webserver to make it operate the way we need it to in order to host a really great website place. Just follow along, and hopefully this will be as painless as possible. It might also help if you stop sitting on those thumbtacks and get that cat to stop biting you, but I’m not going to tell you how to live your life.
Make sure your server is selected under Connections (just select the first node, the one with your computer’s name) and open “Handler Mappings”
Click on “Add Module Mapping” and fill it out as follows:

Request path: *.php

Module: FastCgiModule

Executable: C:phpphp-cgi.exe (either type it in or hit the “OK” button - but make sure you switch it from .dll files to .exe files when you’re looking for a file to open)

Name: PHP_via_FastCGI

Click “Request restrictions,” and check the box next to “Invoke handler only if request is mapped to:” and pick “File or folder.” Hit “OK” a few times, and when it asks you if you want to create a FastCGI application, say “Yes.” Now you should be back at the IIS Manager, which now has your new Handler Mapping to handle PHP files. Go back (either click your server in the Connections area or click the back button at the top of the IIS Manager).
Open “Default Document,” click on “Add...” and enter “index.php” This will (after you hit “OK” of course) make sure that any file called index.php will open by default. This is customary procedure.
Go back to the Server Home section once again and select “Error Pages.” Click on “Edit Feature Settings,” change it to “Detailed errors” and hit “OK.” This will make your server send more useful error messages which will probably save you a few headaches in the future if you need to debug any problems with server-side code.

Okay, so PHP should be working on your Internet, now. The last thing we’ll do is create the world’s easiest web page to test that out.

Open your server in the Connections area, open Sites, and then select Default Web Site. Switch to the Content View (the tabs near the bottom of the IIS Manager window). You should see two files: iisstart.htm and welcome.png. Hit the “Explore” button, and it will open a new Windows Explorer window here.
Right click in the blank area, select “new” and then “Text Document.” Rename the file “index.php” making sure that it isn’t “index.php.txt” because Windows really hates changing file extensions. Make sure you’ve disabled the “hide file extensions for known filetypes” setting in your folder options if you haven’t already.
You can now open this mysterious new “index.php” file in Notepad (right click it and say “open with”). This file is much easier to handle than the php.ini file, isn’t it (because this one is completely empty)? You don’t even need to do much programming to make your first web page. I’m assuming, of course, that you’ve never made a website before now. If you’ve made a website before, I guess you don’t need me; I’ll just go sit in the corner and make jokes about busses.
Type exactly this into the file, and then save and close it: “<?php phpinfo() ?>” Seriously, that’s it. You just made your first web page.
Just like at the end of part one, open up a web browser (or open a new tab in the web browser you’re reading this on), and type “localhost” into the address bar. If you see a bunch of stuff about PHP, you have successfully completed this part of the tutorial. If not, you’ll have to go back and see what you missed. I’ll just continue this thing as if it all worked, though.

You’ve actually done quite a bit just now. First, you installed PHP on your computer, and then you set up your computer’s web server to properly use it when somebody accesses a PHP file. You then created a new file that calls a special function in PHP which poops out a bunch of info about your computer’s version of PHP.

A website is just a directory on a computer somewhere. Your new “Default Web Site” is just a folder on your computer (“C:inetpubwwwroot” by default). Any files inside that folder will be accessible when you go to “localhost” in a browser, and the server will handle it a different way depending on what kind of file it is. When you tell the browser to open “index.php” (which it does by default when you don’t give it a specific file to open - remember when you told it to do that?), it sends a request to the server for that file. The server is all, “woah, that’s a PHP file, brah” (because you told it that all files with a .php extension are special files in the Handler Mapping, and your computer is apparently kind of a d-bag) and it opens the file with “php-cgi.exe” just like you told it to.

PHP and your computer compile the code in the file into delicious beeps and boops, and then process those beeps and boops however they’re designed to be processed. In this case, you’ve used the function “phpinfo()” which simply creates this cool little list of all the stuff that’s going on in your server, PHP-wise. You computer compiled your script, and the PHP files you installed processed that function into a bunch of Hypertext which get sent along to your browser. All that stuff happened the instant you hit “enter” in your browser’s address bar! Neat!

This is the actual Hypertext that your browser is showing.

Try right clicking on the page and select “View Source.” Look at all that code that your little web server sent to your browser! That shows the power of server-side technology like PHP. The actual code for the page is only one function - “phpinfo()” - but the code sent to the browser is vastly different. This is only scratching the surface of what you can do with server-side scripting in PHP.

So now we’re one step closer to a super cool website, and now you have a really great development platform for playing around with PHP (among other things). Tomorrow I’ll be back here with another important step in getting your computer ready to be a super cool Internet, and then we’ll get on with doing a website - I promise. Before you know it, you’ll be able to website like a champ.

Related Reading

In the meanwhile, if you’re interested in learning a bit more about client- and server-side languages, there are some great resources online for you to check out. You won't need to know any of this stuff to complete my tutorial, but it's all very important stuff to know if you want to really get into doing websites. Feel free to create more files in your Default Web Site to practice any of this stuff, and bask in how genuinely cool what you're doing actually is.

  • First, you should get the basics of HTML, so you can understand how a website is really made. (HTML Tutorial)
  • Next you can play around with client-side scripting in Javascript. (Javascript Tutorial)
  • Finally, why not play around with some PHP on your new development platform? (PHP Tutorial)
Please wait...
advertise here!
Top
click for gallery
order a print
close
<
>
order a print