Tuesday, December 28, 2004

WAMP

There are other tutorials on how to set up Apache, PHP and MySQL on a Windows machine, but for what it's worth, this is how I do it. It's important to note that this is used on a testing server in a trusted environment. I have not gotten involved in any security issues here as it's not necessary in my particular case.

For the record, this applies to the following versions:

  • Windows XP Professional

  • Apache 1.3.31

  • PHP 4.3.10

  • MySQL 4.1.7


Let's get started!

Setting up Hosts

If you plan to use Apache's virtual hosts feature AND your testing server is on a different computer than the one you use, then you'll need to do some sorting out first. Virtual hosts allow you to run more than one website on a single web server. What this means is that you can have individual sites set up for each client, and be able to reference files in that site from the site root (or /) instead of just creating subdirectories for a single site as I have seen done elsewhere. For example, you can call http://client1 and pull up their test site, and http://project3 and see a completely different site, that can possibly be saved in a completely separate location on your hard drive.

For this to work, the computer running as your webserver should have a fixed IP address. And therefore each one of the computers in your intranet should also have fixed IPs. In Windows XP, click Start -> right-click My Network Places -> left-click Properties. (If you can't see it in your Start menu you can also get there via the Control Panel.) Then right-click the network connection that corresponds with your network card and left-click Properties. Scroll down the list if necessary until you can see TCP/IP. Double-click that and you'll see something like this:
Changing your TCP/IP settings

In this example, my workstation is called 192.168.0.5 and the computer that actually connects to the internet is 192.168.0.1. (Actually that's the address of my modem/router, but that's another story!) Assign a number along these lines to each machine in your intranet and adjust these settings accordingly. You will probably also need to obtain the DNS server addresses from your ISP and enter them into the lower section.

On a standard Windows installation you will find a file called hosts (with no extension - ie it's not called hosts.txt or anything like that) in C:\Windows\system32\drivers\etc. Open it in Notepad (or any other text editor) and below it add the hostnames you want to use next to the IP address you've allocated for your testing server. If the IP address of your testing server is 192.168.0.200, you might add:
192.168.0.200     client1 project3

You can keep adding hostnames, separating them with a space. When you fill the line, start a new one with the same IP address, a tab, and keep going with more names. I'm not sure how many names you can legally put on a line, but I found it stopped working for me if I had too many, so if that happens to you reduce the number on each line.

You will need to copy this file into the directory mentioned above on each computer in your intranet.

Now we can move on to setting up Apache!


Apache

  1. Download the instalation file from www.apache.org and run it.

  2. When prompted, use your computer's name (intranet in my example) as the server name

  3. Choose the desination directory. I prefer to keep all these things together, so I used C:\webserver\apache

  4. After the installation has finished, fire up your browser and enter your computer's name or ip address. You should see something like this:

  5. Apache confirmation page

  6. Now comes the fun - editing the httpd.conf file!


    • Line 342 - change AllowOverride to All (for htaccess files to work)

    • Line 385 - add extra filenames for the default document:
      DirectoryIndex index.html index.php index.php4

    • If you're using Virtual Hosts, uncomment Line 972 - NameVirtualHost *:80

    • Add details for your own virtual hosts as below:


    Adding virtual hosts

  7. Don't forget to restart Apache after making changes to httpd.conf, which you can do via Start -> Apache -> Control -> Restart



PHP

  1. Download the zip version of PHP from www.php.net and extract to C:\webserver, then change full php directory from php-4.3.10-Win32 to just php.

  2. There's a note in the install instructions: "Note: In PHP 4, you should move all files located in the dll and sapi folders to the main folder (e.g. C:\php)." - so do that. In this case, move them to c:\webserver\php

  3. To add the php directory to the system's path, right-click My Computer, choose the Advanced tab, and then click Environment Variables (near bottom of box). Find Path in system Variables, click Edit, and add ;c:\webserver\php to the end of what's already there. Don't forget the initial semi-colon. Click OK, then OK again. See below:

  4. Adjusting the path variable

  5. Rename php.ini-recommended to php.ini (it's in the main php directory)

  6. Now to edit the php.ini file:


  1. Line 397 deals with Magic Quotes. Check what your remote host has them set to and make this the same.

  2. Line 443 - change to extension_dir = "C:\webserver\php\extensions"

  3. Line 565 - uncomment the extension to load GD2

  4. Line 611 - add your ISP's SMTP server address

  5. Line 829 - Change to session.save_path = "C:\webserver\php\temp" and make sure you add a temp folder to your php folder


  • Go back to Apache's httpd.conf, and add this before the Virtual Hosts stuff at the bottom of the file:

  • LoadModule php4_module "c:/webserver/php/php4apache.dll"
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    # specify the directory where php.ini is
    SetEnv PHPRC c:/webserver/php
    # AddModule mod_php4.c

  • Create a PHP page with phpinfo() in it and make sure it works!



  • MySQL

    1. Download the 'essentials' version from www.mysql.com

    2. Choose custom install and change the installation directory as below:

    3. Changing installation directory in MySQL

    4. Choose Standard Config when prompted

    5. Install as a service

    6. Add root password (and don't forget what it is!)

    7. When done, create new file in the root of C called my.cnf, and add:

    8. [mysqld]
      basedir = C:webservermysql
      datadir = C:webservermysqldata

    9. If you haven't already, now is a good time to download phpMyAdmin and install that in a new folder with it's own hostname. Adjust the setting in its config file and fire it up. With a bit of luck you'll see two databases and you can start creating your own!

    No comments:

    Post a Comment