Installing PHP 5 for Apache on Windows

December 17, 2008

This tutorial walks through the process of installing PHP 5 on Apache for Windows. This tutorial assumes you have already installed Apache web server, if you have not then please consult our Installing Apache section.

First, download the latest version of PHP from the official website. You can install PHP from the Zip archive but for this article we will use the .exe installer.

Scroll down to the Windows Binaries section of the download page. The non-thread-safe download has to do with some compatibility issues between Windows and Unix based platforms. The non-thread-safe download offers better performance but can cause compatibility issues with some add-ons. For this tutorial, download the PHP 5.x installer

php-download-site

Run the PHP installer. When prompted with the welcome screen, click next.

php-installer-welcome

Accept the license agreement and click next

Choose the directory where you want to install. The directory you install PHP in does not have to be the same directory where you installed Apache. After selecting a location, click next.

php-install-choose-directory

Choose Apache and the appropriate version. Apache 2.2.x is the latest release at the time this tutorial was written. The PHP installer makes some changes to the configuration files for Apache and the configuration files have different syntax between different versions.

php-choose-webserver

After clicking Next, a dialog will prompt for the apache configuration directory. This is the ‘conf’ directory located in the directory where you installed Apache (ex: C:\Program Files\Apache Software Foundation\Apache2.2\conf).

Next, a dialog will appear prompting for which items to install. This is an important step as it will determine what you will be able to use with PHP once installed. You can always install modules later, but it is easier to do so now. If you are unsure whether you will be using the module in the future then you should go ahead and install it now. Items with a red X next to them are items that will not be installed.

php-choose-extensions

Now you are all ready to install, click the install button to start.

install-php-copying-files

Once all the files are copied, click finish.

Now that PHP is installed it is time to test that everything works. Open Notepad and create a file named test.php in your document root (the htdocs folder in your Apache folder by default). Make sure you are saving as .php and not a .txt. Write the following code in your test.php file.

<?php 
echo “PHP Works”;
?>

test-php-code

Now, restart Apache by the icon in the system tray or through the services manager in the control panel. Navigate your browser to http://localhost/test.php (or whatever you named your test script). You should see something like the page below.

php-test-success

If you get some sort of warning or error message then verify you typed the test script correctly. Otherwise you should see a successful “PHP Works.” If you typed it in correctly and see the actual PHP code instead of the output, you may have not installed PHP correctly.

Conclusion and further reading

To learn more about creating scripts with PHP look at our PHP scripting tutorials.

del.icio.us Digg Facebook Google reddit SlashDot StumbleUpon Technorati

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Comments are closed.