Install PHP on windows 8 – create your own server – part 2

This is the second tutorial in the series of three tutorials to create your own server on your system. Before starting with this tutorial you must have a working Apache server on your system. (To install apache, see this tutorial on how to install apache). In this tutorial we are going to show you how to install php on windows. To install php on any other operating system, the steps would be similar.

Step 1: Downloading PHP

Go to http://windows.php.net/download/ and download the latest thread safe version zip file binaries. For example, while writing this tutorial the latest version was 5.4.10. Therefore, I downloaded the corresponding threadsafe version.

threadsafe php

 

Step 2: Install PHP

PHP does not have any installation wizard. So, we need to manually install PHP. The following are the steps to install PHP

a) Make a new folder named “PHP” in C: drive or wherever you want to install php (I recommend making a new folder in C:Server folder as shown in the below screenshot)

installing php in windows 8

 

b) Now extract the content of the downloaded zip file to this new folder.

c) Now in the extracted files you’ll see a file named “php.ini-development”. Make a duplicate copy of the file by pressing CTRL+C and CTRL+V.

duplicated php.ini - development

d) Now rename the duplicate file to “php.ini”. (Make sure that you have enabled to show file name extensions)

enable show file name extension

rename php.ini-development to php.ini

 

It will ask for a confirmation to change the file name extension. Just press “Yes”.

change file name extension confirmation

 

NOTE: There are two versions of php.ini i.e. php.ini-development and php.ini-production. ‘php.ini-development’ is for development purpose and ‘php.ini-production’ is best suited for Production purpose or live websites.

 

Step 3: Configuring Apache to work with PHP

In the previous step you have just extracted the php files to your computer. It won’t work on your web-server unless you configure your Apache server to work with php. To configure Apache to work with php open start menu and search for “edit apache” (alternatively you can browse to your apache installation folder and open “conf” folder, inside which you will find “httpd.conf” file) and open the file with notepad.

edit apache conf in windows 8

 

Make the following changes in the httpd.conf file:

1. Find “loadmodule” section (using ctrl+f). And add the following line. (If your php installation path was different then make the changes accordingly)

LoadModule php5_module "c:/Server/PHP/php5apache2_2.dll"

2. Find “Addtype” section and add the following line. (Make sure that this is added before </IfModule>

AddType application/x-httpd-php .php

3. Now at the end of the file just add this line. (This is used to tell Apache where PHP is installed)

PHPIniDir "C:/Server/PHP"

4. (Optional) If you want “index.php” to work as index file instead of “index.html” then just change DirectoryIndex index.html to DirectoryIndex index.html index.php

Step 4: Enabling PHP extensions

Open php.ini file from the PHP installation folder (C:ServerPHP).
To enable php extensions just add the following line below  ; extension_dir = "ext"
extension_dir = C:ServerPHPext

Step 5: Testing

Make a new text file in your server root directory ( If you are following my tutorial then the root directory is “C:ServerWebDocs” or if you haven’t change your root directory then it is “C:%apacheInstallationPath%htdocs”. If you want to change your DocumentRoot folder then follow this guide)

Now inside the text file copy this code

<?php phpInfo(); ?>

and save the file as index.php (Remember to keep the filetype as “all files”).

Now go to your web browser and type localhost. If everything is working fine then it will show info about the php installation on your system.

phpinfo

 

Thus you have successfully installed PHP on your system. Now that you have php working and if you want to develop websites using php and databases, sooner or later you will require to install MySQL. So here is the guide on how to install MySQL on windows 8.

Related posts: