Configuring Apache, PHP and mySQL under windows (WAMP)

first of all, lets get everything we need downloaded:

  1. Apache http://httpd.apache.org/download.cgi
  2. PHP – http://windows.php.net/download. Now, PHP might tell you to download the VC6 for apache – disregard. download VC9 x86 Thread Safe one. do not download an exe or msi file. download the zip archive file.
  3. mysql server at http://dev.mysql.com/downloads/mysql/. note that there are some other tools in mysql site, you might want to use an overall tool that downloads other things as well.
  4. Microsoft Visual C++ 2010 Redistributable Package. 32 or 64 bit version (this is for the VC9 version of PHP). BTW, if you have visual studio installed (version 9 or better), you don’t need these packages.
  5. If you want an editing software for php I recommend netbeans IDE  (found in the Favorites links section)
  6. You Must disable the User account control under Vista/7. Yes, totally disable. This is a horrible tools, which block you from doing your programming. As for viruses? not so much.
  7. Text editing tool! yes, you can use the IDE editor, but I like to have a fast one that can edit any text file. you can find some in the favorites page.

all the instructions below assumed that you use the default locations and installations.

Now, install Apache. note: if you do use Skype, make sure to disable listening on port 80. go to http://127.0.0.1. you should see a “It works!” message.

Next – PHP. you need to stop Apache server for the actual setup (later).

  1. extract all the files to a well known location. c:\php is the usual place, you can change it, but for now this will do.
  2. C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf is where you will find your httpd.conf file. this is a text file, you can use any editor, I will recommend notepad++ for this job.back this file upbefore changing it! Open this file and you need to add three line (I’m doing that after the “LoadModule” part is all done):first line LoadModule php5_module “c:/php/php5apache2_2.dll” will tell Apache where to look for the module note the reverse slash, unlike windows. VERY IMPORTANT to see that the apache version matches the dll version. make sure you are downloading version 2.2 and above!  next line, AddHandler application/x-httpd-php .php will tell Apache about this new php type. and last one, PHPIniDir “C:/php” will show Apache where to find your configuration file which is php.ini. Save this file and restart Apache.
  3. Now, your documents folder can be found in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs  you should see a file named index.html. right click in this folder and create a new file, named pi.php. edit this file with your favorite text editor, to have the next code:

    <?php phpinfo(); ?>

    Now, go to http://127.0.0.1/pi.php, you should get the php information page. If you do, you configure php correctly.
  4. in C:\php you will find 2 php.ini files php.ini-development and php.ini-production. go on and rename php.ini-development to php.ini. restart apache server. now, go to http://127.0.0.1/pi.php, you should see that the Loaded Configuration File is pointing to the right ini file.
  5. now, let edit the php.ini file. first look for extension_dir and make sure that it is pointing to the right location: C:\php\ext. next, un-remark all the extensions (look for extension ) mentioned here: php_bz2.dll, php_gd2.dll,php_mbstring.dll and anything with mysql in it. you can choose more extensions if you like like exif or any other. Next thing – if you want users to be able to upload stuff to your site (users are also including you if you are using any php application for your site like drupal) need to go to update the following settings for this: post_max_size, upload_max_filesize. Any change in php.ini will require restarting Apache.
  6. go on and go to http://127.0.0.1/pi.php. look for mysqli. found it? you are all set!

Core PHP constants

Here are some PHP constants that are being used heavily, but get forgotten a lot.

  • $_SERVER[REMOTE_ADDR] will give you the client address connected to this script
  • $_SERVER[‘PHP_SELF’] will give you the current PHP file you are in. useful for debugging
  • $_SERVER[SERVER_PORT] will give you the server port, this is usually 80, BUT, if you want to check for ssl, this is one way to do so.
  • $_FILES – files that were uploded by the user
  • more constants can be found here.

Setting default document in Apache

In order to set the default document in Apache, we need to access the httpd.conf and look for the term DirectoryIndex this is what setting the default document for Apache.

usage:

DirectoryIndex index.php index.html index.cfm

Usually, you will find it under a directory instruction. And yes, you can set different root documents for different directories.

You also might want to disable directory browsing.

How to disable directory browsing in Apache

If you don’t have a default document in Apache or for any other reason, you might want to disable the directory browsing.

Like everything Apache, this is done in the httpd.conf file.

  1. Using text editor look for the words options and All Indexes or just Indexes.
  2. Remove the word indexes or all indexes from the directory typing so Options All Indexes FollowSymLinks will become Options All FollowSymLinks MultiViews
    (You can have other values)
  3. restart Apache

You might also want to set up default document as well .