<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/docgen.php"?>

<document version="0.1">
	<name>PHP Core Concepts</name>
	<category>PHP Core Concepts</category>
	<author>
		<name>Subir Chowdhuri</name>
		<email>subir@desdevpro.com</email>
		<website>http://www.desdevpro.com</website>
	</author>
	<date>31 August 2009</date>
	<tags>
		<tag>PHP</tag>
		<tag>Tutorial</tag>
	</tags>
	
	<intro>
		There is a plethora of PHP resources available on the web. So why did I bother to write this new series? When I started programming PHP, I wanted a quick guide to creating dynamic webpages in PHP. Stop. I didn't want to hear about regular expressions; I had no intention of learning (interestingly named) libraries like PEAR; I didn't care about exceptions, OOP or XML. But what I got were thick tomes that would take a lifetime to master! And PHP was supposed to be easy, wasn't it?
		This series is my idea of how a language tutorial series should be. It meets the requirements of the impatient learner, who wants to get her hands dirty from the word GO! If you are still reading this thing then you are not the impatient sort. For those like you, later parts of the series revisit the key areas in detail to strengthen the concepts. I call this the H-W approach - first I tell you "how" a thing is done and then "why", "when" and "where" it is done.
		Do send in your feedback on how you like/dislike this unorthodox approach to writing a tutorial.
	</intro>

	<para>
		<heading level='1'>Installing PHP on Windows</heading>
		<text>
			The other day a friend said, "I have learned some PHP from wxy.com. But it didn't tell me how to get my scripts running on my computer!" Well, isn't that pathetic? Let me show you how...
		</text>
		<heading level='1'>Things you need</heading>
		<text>
			Before we start, make sure you have these two things ready:
		</text>
		<endl/>
		<bullet>Apache HTTP Server 2.2+</bullet>
		<bullet>PHP 5+</bullet>
		<endl/>
		<text>Here are the links to the download pages:</text>
		<link href='http://httpd.apache.org/download.cgi'>Apache HTTP Server</link>
		<endl/>
		<link href='http://www.php.net/downloads.php'>PHP 5</link>
		<endl/>
		<text>
			Download the Apache with OpenSSL MSI Package, and PHP 5.x Win32 Binary ZIP archive for Windows.
			The PHP MSI installer works too, but this tutorial will assume that you have the Binary ZIP package for Windows.
		</text>
		<text>
			WARNING: !!! Don't download the source packages!!!
		</text>
	</para>
	<para>
		<heading level='1'>Installing Apache</heading>
		<text>
			Before starting installation make sure you have Administrative Privileges on the computer. The installaion will FAIL is started from a limited account. On Windows Vista, you must use the Run As Administrator option. Run the MSI installation. Select Typical install style. When asked for Network Domain, etc. as shown below:
		</text>
		<image>001_apache_install_02.png</image>
		<text>Just enter any values (not necessarily a valid email, etc). Select "Install for all users as service on port 80" option [Don't miss it!]. I chose the following folder for installation.</text>
		<code>
C:\Apache2.2
		</code>
		<text>
			You may chose another, or leave it at default.</text>
		<text>
			Once the installation completes, you can see a new icon in your system tray, called Apache Monitor.
		</text>
		<image>001_apache_monitor_tray.jpg</image>
		<text>Its the one like a red feather.</text>
		<endl/>
		<text>On double clicking the icon you can open up the Apache Monitor Dialog Box. What does this do? It is used to Start/Stop the Apache Server. And what's that supposed to mean? You'll get to know soon. Keep reading!</text>
		<image>001_apache_monitor_01.png</image>
	</para>
	
	<para>
		<heading level='1'>Testing Apache</heading>
		<text>
			Let's make sure your Apache Server works fine. Double click the Apache Monitor icon in your system tray to bring up the monitor dialog box. Make sure the Apache 2.2 Service is started. You an ewasily tell by looking at the small bulb to the left of "Apache2.2". If it is Green, the service is started. Stopped service is indicated by a red bulb. If your service is Stopped, select the Apache2.2 service and click the Start button.
		</text>
		<endl/>
		<text>
			Fire up your browser (any browser will do). In the address bar type
		</text>
		<code>
http://localhost
		</code>
		<text> OR </text>
		<code>
http://127.0.0.1
		</code>
		<text>If your Apache server is running fine you should get a page with the words "It works!" on the browser window. If it doesn't, we have a problem on our hands.</text>
		<text>
			If you have a problem, Go to 
		</text>
		<endl/>
		<text>
			Start -> All Programs -> Apache HTTP Server -> Configure Apache Server-> Test Configuration.
		</text>
		<text>
			If the window closes automatically, then the configuration is correct. If not, then it displays the error encountered in a DOS Console Window. Refer the Apache documentation for detailed troubleshooting.
		</text>
	</para>
	
	<para>
		<heading level='1'>Installing PHP</heading>
		<text>
			Installing PHP is really easy with the ZIP package. Just extract its contents to any folder, like
		</text>
		<code>
C:\php5
		</code>
		<text>
			Again, this path is arbitrary. Just remember what you choose!
		</text>
		<endl/>
		<text>
			Open up the folder C:\php5. Rename the file called php.ini-recommended to php.ini
		</text>
		<endl/>
		<text>
			Copy this file to C:\WINDOWS. REMEMBER: this is your PHP configuration file
		</text>
		<text>
			Open the Apache HTTP Server Configuration File:
		</text>
		<image>001_httpd_conf01.jpg</image>
		<text>
			Find the section with lots of LoadModule lines, somewhat like this:
		</text>
		<image>001_loadmodule01.gif</image>
		<text>
			Add a new LoadModule line:
		</text>
		<code>
LoadModule php5_module c:/php5/php5apache2_2.dll
		</code>
		<text>
			Here, you should replace c:/php5 with your PHP installation path. If you used the same path as me, it would be c:/php5.
		</text>
		<endl/>
		<text>
			Now, your httpd.conf file looks like this
		</text>
		<image>001_loadmodule02.gif</image>
		<text>
			Find another section like the one shown below. It is about 100 lines from the end.
		</text>
		<image>001_addtype01.gif</image>
		<text>
			Add this line
		</text>
		<code>
AddType application/x-httpd-php .php
		</code>
		<text>
			Now the file looks like:
		</text>
		<image>001_addtype02.gif</image>
		<text>
			The stage is set! Now its time to define your site root. This is the folder where all your webpages will be stored.
		</text>
		<endl/>
		<text>
			Create a new folder. Avoid using special characters and spaces in its name. Also, avoid placing the root folder too deep. Try something simple like
		</text>
		<code>
C:\root
		</code>
		<text>
			In your httpd.conf file find this section:
		</text>
		<image>001_root01.gif</image>
		<text>
			Change the highlighted values to your root folder (in my case, C:/root).
		</text>
		<text>
			Save and close the file.
		</text>
	</para>
	<para>
		<heading level='1'>Testing PHP</heading>
		<text>
			First, make sure you can see file extensions. If you can't (or if you aren't sure) open your root folder in windows explorer and go to Tools->Options->View
		</text>
		<image>001_folderoptions.gif</image>
		<text>
			Remove the check mark from the circled option. Apply the changes and press OK. 
		</text>
		<text>
			In your root folder, create a new text file. Rename it to index.html. Open it up in notepad. DONT USE MS-WORD or WORDPAD for this purpose. Type the following code in it:
		</text>
		<code>
&lt;html&gt;
&lt;head&gt;
&lt;title>Home&lt;/title&gt;
&lt;/head&gt;
My Home Page
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;

		</code>
		<text>
			Save and close the file. Restart Apache HTTP Server.
		</text>
		<image>001_apache_restart.gif</image>
		<text>
			Point your browser to http://localhost/index.html. This is how your page should appear.
		</text>
		<image>001_test01.gif</image>
		<text>
			Assuming all went well, lets move on to testing the PHP installation. Create another new text file in your root folder, rename it to info.php and type the following code in it:
		</text>
		<code>
&lt;?php
	phpinfo();
?&gt;
		</code>
		<text>
			Save the file and point your browser to http://localhost/info.php. You should get the following output:
		</text>
		<image>001_info01.png</image>
		<text>
			Getting the above output means that your PHP installation was successful. Now you are all set to start coding in PHP!
		</text>
	</para>
	
	<para>
		<heading level='1'>Troubleshooting Apache</heading>
		<bullet>Before installing Apache, make sure you have administrative privileges on your user account !!
		</bullet>
		<bullet>If you have Apache installed and want to upgrade/install it afresh, make sure to completely uninstall previous version and then manually delete any leftover files. Restart Windows before installing again.</bullet>
		<endl/>
		<text>
			This tutorial wasn't supposed to cover troubleshooting at all. But  Ashutosh brought to my notice a common problem faced suring Apache Installation -- default port (80) already in use. To solve it, you must open your httpd.conf file (discussed above) in Notepad.
		</text>
		<endl/>
		<text>
			Around 50 lines from the top you find:
		</text>
		<image>001_listen01.gif</image>
		<text>
			Change the port number from 80 to any number above 1024, like 8080. Save and close the file. Restart Apache to apply changes. Your pages served by Apache will now be accessible from:
		</text>
		<code>
http://localhost:8080
		</code>
		<text>
			OR
		</text>
		<code>
http://127.0.0.1:8080
		</code>
		<text>Instead of</text>
		<code>
http://localhost
		</code>

		
	</para>
</document>