How to Install PHP on Windows Machine

Hello Friends,

In the last topic i have explained you the procedure to install Apache Server on Windows machine. In this Section I am guiding you how to install PHP on Windows machine. To install PHP on Windows machine Apache Server is a must. So lets begin.

What is PHP?

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.

PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by the PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License.

Why PHP?

PHP is most different from JavaScript and Java. PHP is a server-side scripting language. All of the ?work? is done on the server. JavaScript (and Java) generally run on the client. They have little access to the information that the server has, and mediated access to information on the client. They can do lots of things on the client that PHP cannot. PHP has full access to the information that the server has, and very little access to information that the client has. In fact, it only has information that the client tells the server and that the server passes on to PHP. Because it is on the server, however, PHP cannot be modified by the client. While you cannot necessarily trust the information that the client gives to PHP, you can trust that your PHP is doing what you told it to do. Because PHP is on the server end, your PHP scripts can affect your server–such as by keeping an activity log or updating a database.

Automated PHP Installation

To get a one click installer of PHP check out http://www.php.net and download it. The installation is simple just next–>next…. and its done.

Manual PHP Installation

Step 1: download the files

Download the latest PHP 5 ZIP package from www.php.net/downloads.php

As always, virus scan the file and check its MD5 checksum using a tool such as fsum.

Step 2: extract the files
We will install the PHP files to C:\php, so create that folder and extract the contents of the ZIP file into it.

PHP can be installed anywhere on your system, but you will need to change the paths referenced in the following steps.

Step 3: configure php.ini
Copy C:\php\php.ini-recommended to C:\php\php.ini. There are several lines you will need to change in a text editor (use search to find the current setting).

Define the extension directory:

{code type=codetype}

extension_dir = “C:\php\ext”

{/code}

Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of applications (remove the semi-colon comment):

{code type=codetype}

extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_xmlrpc.dll

{/code}

If you want to send emails using the PHP mail() function, enter the details of an SMTP server (your ISP?s server should be suitable):

{code type=codetype}

[mail function];
For Win32 only.
SMTP = mail.myisp.com
smtp_port = 25;
For Win32 only.
sendmail_from = my@emailaddress.com

{/code}

Step 4: add C:\php to the path environment variable
To ensure Windows can find PHP, you need to change the path environment variable. From the Control Panel, choose System, (then ?Advanced system settings? in Vista), select the ?Advanced? tab, and click the ?Environment Variables? button.

Scroll down the System variables list and click on ?Path? followed by the ?Edit? button. Enter ?;C:\php? to the end of the Variable value line (remember the semi-colon).

Now OK your way out. You might need to reboot at this stage.

Step 5: configure PHP as an Apache module
Ensure Apache is not running (use ?net stop Apache2.2? from the command line) and open its \conf\httpd.conf configuration file in an editor. The following lines should be changed:

Line 239, add index.php as a default file name:

{code type=codetype}

DirectoryIndex index.php index.html

{/code}

At the bottom of the file, add the following lines (change the PHP file locations if necessary):

{code type=codetype}

# PHP5 module
LoadModule php5_module “c:/php/php5apache2_2.dll”
AddType application/x-httpd-php .php
PHPIniDir “C:/php”

{/code}

Save the configuration file and test it from the command line (Start > Run > cmd):

{code type=codetype}

cd \Apache2\bin
httpd -t

{/code}

Step 6: test a PHP file
Create a file named index.php in Apache?s web page root (either htdocs or D:\WebPages) and add this code:

{code type=codetype}

<?php phpinfo(); ?>

{/code}

Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, a ?PHP version? page should appear showing all the configuration settings.

Source

2 Comments+ Add Comment