Saturday, April 14, 2007

Configuring Apache and PHP

First of all, today is Vishu, the wonderful festival of keralities.Just read about it and you will find that what wonderful land is Kerala, God's own Country.

Copy the PHP files that you downloaded to "D:\Server\PHP\". We have to add this directory to our startup path so that Windows can access the directory whenever any references are made to PHP. Right click on My Computer. Click on Properties. Select Advanced. Click on Environment Variables. From the System Variables Group, select Path and click on edit. Append at the end of the Variable Value field, ";D:\Server\PHP"(without the quotes). Restart your computer. When Windows come back, to verify whether your computer has access to PHP, fire up the Run prompt. Type in cmd. In the command prompt, type in php -v. If everything is right, you will get information about the PHP version that you have downloaded and installed.

Navigate to the PHP directory and find the file named php.ini-recommended. Rename the file to php.ini. Open up the file in any text editor of your choice. Search for a phrase called doc_root. This is the root directory of our website. since we've decided it to be "D:\Server\", set the doc_root property to that value. Nearby, you can also configure the PHP extension directory. Set its path to a directory of your choice.
Thats all to be done for PHP.

Now, on to configuring Apache.

Let us say that you installed Apache in "D:\Server\Apache\". Navigate to that location(and open up the httpd.conf file in any text editor of your choice(or select start»Apache HTTP Server»Configure Apache Server»Edit the httpd.conf file). I use Notepad++ If you find it utterly irritating to type in :8080 with every address that you enter, search around for a phrase Listen 8080 and change that line to Listen 80. Port 80 is the default http port. Restart the Apache Server and verify that if we type in http://localhost in our browser, we will get the Apache page.

We are going to load PHP as an Apache module. PHP can be used as a CGI or as an Apache module. For the time being, lets load PHP as an Apache module. It is usually good practice to load PHP in this manner as it makes your code more secure. Note that you cannot run PHP as a module and a CGI at the same time.

Now, search for a phrase LoadModule in the httpd.conf file. To the list of modules already addded, add the following code :
LoadModule php5_module "D:/Server/PHP/php5apache2.dll"

Now, search for "AddType" section and add the following code:
AddType application/x-httpd-php .php

You can add other extensions as well if you want PHP to parse them.
Finally, add the following line somewhere in the file that seems nice to you :
PHPIniDir "D:/Server/PHP/"


Actually you can add the lines anywhere in the file. I just mentioned you add them in sensible places.

Now for the final check, open up any text editor. Type in the following code :
<?php phpinfo(); ?>
Save the file as phpinfo.php in "D:\Server\". Open up a browser after starting Apache and type in "localhost\phpinfo.php" If all goes well, you would see a screen similar to the one below

Friday, April 13, 2007

Installing Apache Server

So you downloaded Apache and is ready to install it. Double click on the downloaded "msi" file to open the installation window. Agree to the terms and conditions and click on the next button to move to the next step.
The explanations for the fields there are given directly in the Apache documentation. I'll list them below.

Network Domain: Enter the DNS domain in which your server is or will be registered in. For example, if your server's full DNS name is server.mydomain.net, you would type mydomain.net here.

Server Name: Your server's full DNS name. From the example above, you would type server.mydomain.net here.

Administrator's Email Address: Enter the server administrator's or webmaster's email address here. This address will be displayed along with error messages to the client by default.

For whom to install Apache Select for All Users, on Port 80, as a Service - Recommended if you'd like your new Apache to listen at port 80 for incoming traffic. It will run as a service (that is, Apache will run even if no one is logged in on the server at the moment) Select only for the Current User, on Port 8080, when started Manually if you'd like to install Apache for your personal experimenting or if you already have another WWW server running on port 80.
If you are going to run Apache locally on your computer, don't worry about the fields. Just enter "localhost" in the first two fields and some email address in the last field (the email id need not be valid).

It is always better to start Apache manually as adding it as a service causes it to eat up resources. So choose the second option ie
"only for the Current User, on Port 8080, when started Manually"


Click on next an you will find yourself facing a familiar screen like this :

Choose the custom setup type and proceed. The only thing that you have to change in the next screen is the location of your install. Choose the location as "D:\Server\" as we are supposing it to the root folder of all our PHP activities.
On the next screen select "install" and after a successful installation, select finish to quit the installer.


Give a congrats to yourselves. You just installed Apache!
Start the Apache server from your start menu or directly from the location in which you have installed apache. In this case, "D:\Server\Apache\". The first time you start Apache and if you have enabled ICF, it will pop up a warning window. Click on "Unblock" and viola, your computer is a server!

To make sure Apache is running, open up a webserver and type in localhost:8080
If Apache is working, you will see a webpage like this

Thursday, April 5, 2007

The First steps...

I don't think an introduction to PHP is required by any of you readers. If you have come to this site, then you know PHP or at least you want to learn PHP. So let us get started right away :

To run PHP, you need a server. Why? Because, unlike Javascript, PHP is a server side scripting language. This means that you need a server software on which to run PHP. So what does the PHP software you downloaded do? Basically, it reads and interprets the PHP lines you entered. But surprise : You can also run PHP on command line. You can also develop command line applications with PHP. Just code in PHP and compile it using PHP. So lets get started. First of all download the PHP and Apache binaries.

Apache is available here.
Yes guys, I know its Apache 2.0.59. You may wonder why I didn't choose Apache 2.2 that has already been released. The reason is that no compatible PHP modules for the Apache 2.2 have yet been released as of this writing.
Next, download PHP 5 from here.
Select a suitable mirror and proceed to download. While downloading make sure that you are downloading the zip package and not the installer. There is no need to install softwares unless and until absolutely necessary. It does not affect Linux distros, but in Windows, installing softwares lead to writing unwanted registry entries which are to be avoided.

So that starts your PHP learning class.
Next, you need to setup a directory structure in your hard drive.
Assume that you are using your "D:" drive for learning and setting up PHP. Web pages have directory structures similar to your folder names. The only difference is that they all have forward slashes while your directories have backslashes.

Suppose that you create a directory called "server" in D:\ and you wish to make it your root directory. All you have to do is to create your directory. The configurations are done in the Apache configuration file httpd.conf.
So the directory server will be your root directory. All web pages that you create will be stored here. Its time to begin the installation of Apache. Fire up the Apache installer.