Computer Science


Installing Apache and PHP

This page describes how to set up Apache 2.2.8 to work with PHP 5.2.5 and MySQL 5.0.51 on your home PC. Other version combinations are not supported on this page.

Some of the downloads are very large. You may want to burn a CD at uni rather than downloading via a phone line or capped ADSL line from home.

I presume that your OS is Win XP, if not, you'll have to see what fits.

Download notes

The download links here are current as of 5/3/2008. Before you download, check apache.org for new versions of their HTTP server, similarly check the NZ mirror of php.net for new PHP versions. Do NOT download the installer version of PHP - its setup is completely different from what is described here.

Downloads (from within the university network)

Downloads (from outside the university network)

Installing Apache

Before you install Apache, ensure that you don't have Microsoft's Internet Information Server (IIS) running - if it runs, it hogs TCP port 80 that is needed by Apache. Go to Control Panel, Administrative Tools, Services, and shut IIS down if you can find it there. Similarly, chase Tomcat away if it's running on port 80.

To start the Apache installation, click on the MSI file and follow the installer instructions. When asked, install Apache for all users on our computer, and enter "localhost" as the server name.

If Apache refuses to start and complains about a port already being in use, ensure that you have no IIS, Tomcat, or other webserver already running on your machine.

After installation, locate the httpd.conf file. It's probably in C:\Program Files\Apache Group\Apache2\conf\. Open the file in a text editor (no, MS Word is not a text editor - use Windows Notepad or somesuch!). You'll need to make a few changes here:

  1. Look for a line that starts with DocumentRoot. Enter your preferred directory here (use forward slashes in the path). E.g., C:/Documents and Settings/joebloggs/My Documents/mywebdir/.
  2. A bit further down there'll be a <Directory ...>-Directive with the comment "This should be set to whatever you set DocumentRoot to". Indeed: Change it to <Directory "C:/Documents and Settings/joebloggs/My Documents/mywebdir/"> or whatever.
  3. Scroll down a few lines until you see a comment that says "Controls who can get stuff from this server". Below the line Order deny,allow insert a line that says Allow from 127.0.0.1. This makes your Apache web server private (i.e., the rest of the world are turned down when they want to spy out your documents).
  4. Almost there: Scroll down a few more lines until you see a piece of code like this:
     
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
    </Files>
     

    Add two more blocks like this, to prevent people from accessing .inc and .phpi files (file extensions you might want to use for includes in PHP):
     
    <Files ~ "\.phpi$">
        Order allow,deny
        Deny from all
    </Files>
     
    <Files ~ "\.inc$">
        Order allow,deny
        Deny from all
    </Files>
     

Save httpd.conf but don't close the text editor yet. Restart Apache. Put an HTML file into the document root directory (e.g., open a Word file, type a few lines and save it as, e.g., yourfilename.html there). Now point your browser at http://localhost/yourfilename.html. If the document displays in the browser, you're in business for now. Time to install PHP.

Installing PHP

Unzip the distribution into your C:\ drive and rename the top directory that it's in from C:\php-5.2.0-Win32 to C:\php

Now rename php.ini-dist in this directory to php.ini. You'll need to edit it a little in a moment, so open it in a text editor.

Go back to your http.conf file that you opened during the Apache configuration. Somewhere in the file will be a whole raft of LoadModule directives. Add the following lines at the bottom of the block:

LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php .php3 .php4 .phtml
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/php"

Finally, find a line that starts with DirectoryIndex and add index.php to the end of the list.

DirectoryIndex index.html index.html.var index.php

Now add c:\php to your path: Right-click on "My Computer", select "Properties" and the "Advanced" tab. At the bottom of the tab, click on "Environment Variables". In the window that opens, go to the bottom list "System Variables" and add c:\php to the existing entry for Path.

Almost done - just that we can't quite talk to MySQL yet. Copy the file c:\php\libmysql.dll to c:\Windows\system32 and overwrite any older version there. Now edit php.ini and remove the semicolon in front of extension=php_mysql.dll and in front of extension=php_sockets.dll. Also, look for the entry extension_dir and set it to "c:/php/ext" - note that the forward slashes are well understood by Windows and are in fact the preferred notation in php.ini.

Save php.ini and  httpd.conf and restart Apache. Still all fine? Great, you're running PHP now.

To install the PHP manual, unzip all the contents of the zip file into a folder and run php_manual_en.chm in that folder to start the help program.

Installing MySQL

Install MySQL by unzipping the ZIP distribution and running Setup.exe. Look at the MySQL manual on how to start the server and how to set up user privileges. Note that it's a good idea to restrict users to users that come from localhost. The MySQL home page also has some GUI admin tools for MySQL. Another good one is PHPMyAdmin.

Feedback

If you find any of the instructions above to be incorrect, please let me know.


Apply now!


Handbook

Postgraduate study options

Computer Science Blog



Please give us your feedback or ask us a question

This message is...


My feedback or question is...


My email address is...

(Only if you need a reply)

A to Z Directory | Site map | Accessibility | Copyright | Privacy | Disclaimer | Feedback on this page