Sette opp WEB-server   
 

Opp

 

 

 

 

 

 

 

 

 

Setting Up a Windows Web Server

Introduction

In this article I’ll show you the basics behind setting up a Windows web server for use at home. Most people working on a website see having a local web server as a benefit as it removes the need for continually uploading to a remote server via ftp. For someone just starting out with PHP and MySQL this reduces the amount of time spent experimenting with scripts and solving problems.


What We’ll Need

A computer

There’s no reason why you can’t install the web server on your main PC. If you chose to do so, as you go through the article, there will be certain sections you can forego, and in other places, IP addresses will have to be changed for our old favourite, 127.0.0.1

The specification of the computer to be used needn’t be too powerful. The only requirement is some sort of network interface.

First off I found an old AT case:

 



After a fair while rummaging around my room I managed to find enough bits to fill it up - 230W AT PSU, Intel 430TX Motherboard, Intel Pentium 200Mhz, 64Mb PC100, 8Mb S3 Virge PCI Graphics Card, Yamaha ISA Sound Card, 10/100Mbps Network Card, 30Gb Seagate Barracuda II, AT Keyboard and PS/2 Mouse. Once it was all in, I installed Windows 2000:

 



Software
 

  • Apache – Apache is the most widely used HTTP server, as of September 2003 it was running on over 67% of the worlds active webservers.
     
  • PHP – PHP is a general purpose server side scripting language, most commonly used for creating dynamic web pages.
     
  • MySQL – MySQL is database server software which is fast and reliable and provides APIs for many languages. The two we’ll be able to use it with are Perl and PHP.
     
  • PHPMyAdmin – PHPMyAdmin will allow control of MySQL through a simple web page interface, and will make administration of the databases far easier.
     
  • RealVNC – RealVNC is remote control software, which will let us view and control what is happening with the server without having to be at/have a monitor.

     

Now lets set to work…

Starting Off

Download Apache

You’ll find the files you’re after at httpd.apache.org.

Select the “Win32 Binary (MSI Installer)”. The filename will be something like “apache_2.0.47-win32-x86-no_ssl.msi”, depending on the version. It comes in at about 6Mb.

Apache 1.3 is still actively maintained, as not all software has support for Apache 2.0. For the purpose of this guide, the latest version should be fine.


Download PHP

PHP can be found at www.php.net/download.

Download the latest stable release of the Windows binaries in the full zip package. The filename will be something like “php-4.3.3-Win32.zip”, depending on the version. It comes in at about 6Mb.


Download MySQL

Get MySQL from www.mysql.com/downloads.

Download the latest production release of the Windows binaries with an installer. The filename will be similar to “mysql-4.0.15-win.zip”, depending on the version. The file will be about 23Mb.


Download PHPMyAdmin

PHPMyAdmin can be found at www.phpmyadmin.net.

Download the latest stable zip version from the .php group. The file name will be something like “phpmyadmin-2.5.4-php.zip”, depending on the version. The file will be about 2Mb.


Download RealVNC

RealVNC’s download files can be obtained from www.realvnc.com.

Download an installable package for Windows with the server and viewer (the details form is optional). The filename will be similar to “vnc-3.3.7-x86_win32.exe”, depending on the version. RealVNC’s installer is about 0.5Mb.

RealVNC will need to be installed on any computers with which you wish to control the server, as well as on the server itself.


Let's get the PC ready while that lots downloading…

Setting Up

First off, we need to have a working network. For this I’ll be using two computers linked together through a 5 port hub.

The server will be 192.168.0.1 and the main machine will be 192.168.0.2. I checked everything was working ok using ping.

To make life easier, we’ll assign a virtual domain name to the server. It’s a simple case of letting the PC know where to redirect when the domain is requested. On a larger network this would be done on the local DNS server, but we’ll just set it up on the local machine.

My own site is telkman.co.uk, so I’ll use the domain name telkman.lo.uk, ‘lo’ being short for local. I don’t want to set the server as the proper domain or I’ll run into problems trying to access them both in future.

To do this, we edit Window’s “host” file. On 98 this can be found in “C:\Windows”. For 2K/XP it’s in “C:\Windows\system32\drivers\etc”.

We add in lines as follows:

127.0.0.1 localhost
192.168.0.1 telkman.lo.uk

To test the domain, we can use ping again. If we get a response, we know the domain works as it should. From now on, we can use that in place of the IP address for the server.


RealVNC

By now, RealVNC should have finished downloading, so we can install it on our two computers. Run the install file on each. For the server, select both Server and Viewer and select to have the server run as a Windows service. On the main PC, only select the Viewer.

When RealVNC runs for the first time on the server, select the checkbox for “Accept Socket Connections” and enter a password. Also select to “Do Nothing” when the last client disconnects.

Now we can test RealVNC. Run the viewer on the main PC. When prompted, enter the virtual domain in the address box, telkman.lo.uk and enter the password for the server. We should see our server’s desktop:

 



Now we can control the server remotely, we can lose the monitor and mouse and keep it somewhere tidy. Because the RealVNC server is running as a service, it starts up as soon as Windows does. This lets us log in with the viewer straight away and use that to log into Windows on the server.

Lets get installing…

Installing Apache

Running the installation program for Apache is straightforward enough. It will ask you for certain details such as your server name and you can fill these in as you wish – we’ll overwrite them when we define the virtual host. I choose to install in C:\Apache to make it easier for me to find things when I need them.

With it installed we can edit the configuration file. Open “Apache\conf\httpd.conf” in a text editor. Despite the large numbers of settings, we only need to add a small section on the bottom to declare the virtual host.

Add this to the end of the httpd.conf:

NameVirtualHost 127.0.0.1
NameVirtualHost 192.168.0.1

<VirtualHost 127.0.0.1 192.168.0.1>
ServerName telkman.lo.uk
ServerAlias www.telkman.lo.uk
DocumentRoot "c:/www"
</VirtualHost>
 

By using name based virtual hosting rather than IP based, more virtual hosts can be added later on.

The easiest way to control the Apache server is by using the Apache Service Monitor, which should already be running in the background and can be accessed by the icon in the system tray. The Apache Server can also be controlled by the icons in the start menu or by executing the programs directly.

It should already be running, so choose the option to restart Apache Server and our new settings should be loaded.

To test it out, we need a basic HTML document to view. Save this as index.html in the directory you declared as the DocumentRoot above:

<html><head><title>Apache Test</title></head>
<body>
*Test*
</body>
</html>
 

Now open up a browser window on your main machine and visit http://telkman.lo.uk and http://www.telkman.lo.uk – We should see the results of the above HTML code displayed.

Now stop the Apache server so we can install PHP…

Installing PHP

First off we need to extract the PHP zip into C:\PHP.

Copy php.ini-dist to your Windows directory and rename it php.ini. This is where the PHP settings are stored.

Find the line containing extension_dir and change it to:

extension_dir="C:/PHP/extensions/"

Then find the line containing doc_root and change it to:

doc_root = "C:/www/"

Next, move php4ts.dll to the system32 directory. This is the script interpreter.

To check PHP should work ok, open a command prompt and enter the two commands below:

cd c:\php
php -v

The PHP –V command will execute a version check to make sure everything will work ok. It should output the PHP version and copyright.

Now we need to add the following two lines into “Apache\conf\httpd.conf” to integrate PHP into Apache:

LoadModule php4_module "c:/php/sapi/php4apache2.dll"
AddType application/x-httpd-php .php

We also need to edit the “DirectoryIndex” line to include index.php so that Apache recognises index.php as an index file in a directory. The line will look something like this:

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

Testing

Test the PHP by saving the following line as index.php in the DocumentRoot (C:\www):

<?php phpinfo(); ?>

Delete the index.html we saved earlier and then access http://www.telkman.lo.uk from the main PC. If the DirectoryIndex has worked, Apache will have found the index.php as an index page. If the PHP install has been successful, the phpinfo() function will have produced vast amounts of information about the current state of PHP.

With a working install of Apache and PHP in place we can get onto MySQL…

Installing MySQL

MySQL is the trickiest of the bunch to setup, and it has a habit of being temperamental. Hopefully this will help you work through it ok, but if you come across any problems, the manual is fairly comprehensive and people will be happy to help in our forums.

First off we need to run the MySQL setup. We’ll install it to “C:\mysql” and use the typical installation options to keep things straightforward.

Although it doesn’t prompt you to, restart the machine to finish of the installation properly. When you start up again, WinMySQLAdmin will likely popup. If it prompts you for a password and username, put them in. Although this will be running, we won’t use it, as PHPMyAdmin is easier to work with. To work with the MySQL server to start with, we’re going to have to use the Command Prompt/Shell on the server through RealVNC.

At the command prompt, run this command to install MySQL as a service:

C:\mysql\bin\mysqld --install

Then run this command to check that the server is up and running. If it is working and you are able to connect to it, it should print out a small table with details of the databases it currently contains:

C:\mysql\bin\mysqlshow

Now lets get into MySQL as root. Run the first command to open up the MySQL Monitor. It will welcome you and the prompt should change from “C:\>” to “mysql>”. The “mysql” at the end of the command selects the MySQL database in which the user details are stored:

c:\mysql\bin\mysql --user=root mysql

Next run this command which will give full access to a user so we can log in through PHP. Change telkman to whichever username you want to use and password to your password of choice. It should give you a message saying no rows have been affected.

GRANT ALL PRIVILEGES ON *.* TO telkman@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;

Then run this command to remove any anonymous access:

DELETE FROM user WHERE Host='localhost' AND User='';
 

Then exit the MySQL Monitor:

\q

Now lets log in with our new user with this command. The –p will mean you are prompted for your password.

C:\mysql\bin\mysql -u telkman –p

If that logs in successfully, close the command prompt so we can install PHPMyAdmin and test our server…

Testing

The PHPMyAdmin install is very straightforward.

Unzip all the files into a folder in the www root such as “C:\www\phpmyadmin”.

Open config.inc.php in a text editor so we can edit certain settings. Change the first line to the second with the location of your PHPMyAdmin folder:

$cfg['PmaAbsoluteUri'] = '';

$cfg['PmaAbsoluteUri'] = 'http://www.telkman.lo.uk/phpmyadmin/';

In the server configuration section that defines the host as “localhost”, edit the following lines with the username and password you defined through the command prompt:

$cfg['Servers'][$i]['user'] = 'telkman';

$cfg['Servers'][$i]['password'] = 'password';

Now lets test it. Open up a browser on your main machine and head to http://telkman.lo.uk/phpmyadmin. In the drop down menu on the left, select mysql to open the MySQL database with all the user details. You should see something similar to this:

 



Now lets set up a quick test database to make sure everything is working as it should. In the drop down box on the left of the PHPMyAdmin interface, select “(Databases) …”.

In the “Create new database” field, input a name for a new database. Lets call it “db_practice” to keep things straightforward.

Create a table with the name “tbl_practice” and 1 field.

Name the field “fld_practice” and set it as TEXT. You can ignore the other options. Click the save button.

Click the “Insert” tab at the top of the page. Ignore the “Function” drop down and put the following code into the “Value” text area:

<blockquote style="border: 1px dashed #000000; padding: 5px">

Here is our database text :)

</blockquote>

With our data in our database field, we can try using PHP to access it. Input this code into index.php and save it in the www root:

<?php

mysql_connect(localhost,telkman,password);

@mysql_select_db("db_practice");

echo (mysql_result((mysql_query("SELECT fld_practice FROM tbl_practice")),""));

? >

Now open up a browser window on the main machine and head to http://telkman.lo.uk/index.php. The page should contain the html snippet that we put into the database.

There we have it – one working Windows webserver. If you have any questions or comments, head on over to the forums.

 

Startside ] Opp ] [Søk]

Copyright © 2002 Øyvind Haugland
Sist endret:  13 januar 2019
 

  Interested in this stuff? Please write to:
 

HTML Counter            stats counter