Friday, December 17, 2010

Downloading and Installing php 4

Downloading php

To download php, visit www.php.net. This is the official php site. And go to Downloads. In the download section go to Windows Binaries. You have two options. Either you can download the installer package or you can download the zip package. Don’t go for the installer package because it will only configure IIS and not Apache. Download the zip package.



Installing php

Extract the php zip package to a folder in your computer.

Make sure you extract the zip file into a folder with the folder name not having spaces. This is very important because otherwise you will have some configuration problems when you are trying to configure php with Apache.

Open the “install.txt” file in the php folder.
Go to the “Installing as an Apache module” section and follow the instructions in there.

Or you can directly do this. But it is always better to have a look at the “Installing as an Apache module” section in the “install.txt” file.

OK, let’s assume that you have php 4 and you extracted the contents of the zip file into C:\php.

Open the folder named “SAPI” in C:\php.

Copy the file named “php4apache2.dll” in that folder and paste it in C:\php.
Now, open the Apache httpd.conf file (Start > All Programs > Apache HTTP Server 2.0.54 > Configure Apache Server > Edit the Apache httpd.conf Configuration File)
Go to the “LoadModule” block and add this line to the end.

LoadModule php4_module C:/php/php4apache2.dll

And to enable Apache to recognize and handle php files add the following line to the “AddType” section.

AddType application/x-httpd-php .php

Now save the file and restart the Apache server.



Configuring The php.ini File

When you have completed above steps, php will work without much of a problem. However there is another step to complete the installation. That is setting up the php.ini file. By doing this you can harness the full potential of php. Otherwise you won’t be able to load dynamic modules to support php.

Here is how

In your php directory (ex. C:\php) there is a file called “php.INI-RECOMMENDED”. First make a copy of it in the php directory. And then rename the copy of “php.INI-RECOMMENDED” in to “php.ini”. It is very important that you don’t use the original “php.INI-RECOMMENDED” for configurations.

Now open the Apache httpd.conf file (Start > All Programs > Apache HTTP Server 2.0.54 > Configure Apache Server > Edit the Apache httpd.conf Configuration File)
Add this part to the very bottom of the file

# configure the path to php.ini
PHPIniDir "C:/php"

Note: This directive only works for Apache 2 web servers and above. If you are working with an earlier version of Apache then you will have to use the PHPRC environment variable. Check out the install.txt in the php directory to know more about this method.
Save the file and restart Apache

Now right click on “My Computer” and select “Properties” from the popup menu. Then go to “Advanced” tab and select “Environment Variables”. Choose “Path” from “System variables” and click “Edit”.

Don’t delete the content of the “Variable value” text box (That’s very important). First add a “;” at the end of the content. Then add the path of your php directory after the “;” character (This is the divider that divides different system variables in the same string)

Click “Ok” to save the changes and then restart your computer. This is done because changes to Environment Variables only take effect after restarting the computer.

Once all of these are done you can configure php using “php.ini”

Open “php.ini” in the php directory
This file is mainly used to dynamically load extensions for php. To do so first you will have to tell php where it can find these extensions. These extensions are in a directory named “extensions” inside the php directory. Give the path of this directory to “extension_dir” directive.

extension_dir = "C:\php\extensions"


You are almost done

Now when you want to load a dynamic extension all you have to do is to go to the “Dynamic Extensions” section of the “php.ini” and uncomment the appropriate directive (remove the “;” from the beginning of the directive)

Like this

change

;extension=php_mysql.dll

to

extension=php_mysql.dll


You will have to save the file and restart Apache for these changes to take effect

No comments:

Post a Comment