Articles
Articles of Interest for the UBB Developer
Reviews
Grab Reviews of all (software, hardware, sites) that's important to you as a developer.
Interviews
Interviews in the world of internet community-building.
Member Spotlight
Grab Honorees for excellence in site design, color scheme, member experience, appropriate use of modifications, and site integration.
Team UBBDev
Join the Team!
Team UBBDev is our name for the United Devices cancer research project started here at UBBDev.
Join today and donate your computer's unused CPU time to a worthy cause. When you sign up, you'll be helping to search for a cure for cancer, and you'll also get a nifty haxxor icon.
posted
Article: Setting up your own Web Server Tutorial by: Matt Jacob
Setting up your own Web server
Who should read this series?
Anyone who wants to have a fully-functioning Web server operating on their own computer should read this series. There are a few important benefits to having your own server, including:
You can test your scripts and applications without having to upload them;
You can create a personal Web site to share with friends and family;
You can possibly save hundreds of dollars a year on hosting*.
What will you learn in this series?
My goal here is not to make you an expert on all possible aspects of server technology. All I want to do is teach you how to install and run a server locally, on your own computer. Here's what you'll learn:
How to install and configure Apache 2.0.39;
How to install and configure ActivePerl 5.6.1;
How to install and configure PHP 4.2.1;
How to install and configure MySQL 3.23.51;
How to make your server accessible to the world using dynamic DNS;
Necessary security cautions to take in order to protect your computer;
Note: version numbers above are current as of 7/5/02**.
Conventions used in this series
Constant width is used to indicate HTML tags, code examples, and keyboard commands
Constant width bold is used to indicate on-screen labels and user-entered text
Italicized text is used to indicate filenames, directory names, and URLs
Minimum system requirements
There are a few prerequisite items that you need to meet before you go any further.
First, these instructions are geared to Windows users only. Sorry if you're a Mac person--I like 'em too--but this series just isn't for you. Second, you need to have either Windows 2000 or Windows XP Professional installed, but nothing earlier. And absolutely no Win95, Win98, or WinME. I'll be using Windows 2000 with Service Pack 2, but I assure you that XP also works just fine. Third, you need to be able to download and unzip files, some of which are quite large. I estimate the combined size of the downloads at about 30 megabytes, so access to a broadband connection will come in handy.
*This is actually only feasible if you have a broadband connection, and even then it's a little sketchy. Some ISPs don't allow you to run a HTTP server through their connection, so please check with your ISP before advertising that your server is accessible to the outside world.
**That date would be July 5, 2002 for the uninformed.
You can find the binary of Apache 2.0.39 for Windows at: http://www.apache.org/dist/httpd/binaries/win32/ [direct link]. The file is 3.2 MB, and is distributed as an MSI package.
Installing Apache
Open the file you just downloaded and read the prompts until you get to a screen that looks like the one below. Fill in the information as I have, and then enter your own email address in the last box.
The rest of the installation prompts are self-explanatory, so all you have to do is pick a directory to install to and then wait for the installer to finish. I recommend installing Apache to a separate partition or drive in order to keep things neat and clean (if that's an option for you). I should also mention that unless you choose otherwise, Apache2 will be appended to all folder paths. This means that if you install to something like H:\Apache\, it'll actually get installed to H:\Apache\Apache2\. I guess it's just one of those weird idiosyncrasies that everyone loves.
Having done all that, open your browser and type http://127.0.0.1/. If you see a page that looks like the one below, you may sit back and relax, knowing that half the battle is already over.
If you don't see that page, uninstall Apache, and then start over, making sure to read each prompt carefully. If you still can't get it to go after trying, say, ten more times, email me and I might be able to help you out. Alternatively, you can peruse the Apache help docs, located at http://httpd.apache.org/docs-2.0/.
Configuring Apache
And now comes the fun part.
Opening the httpd.conf file for editing
Click on Start, then Apache HTTP Server 2.0.39, then Configure Apache Server and finally Edit the Apache httpd.conf Configuration File. This will open up the httpd.conf file in Notepad so that we can edit it. Know that if you make any huge mistakes while editing this file, there's always a backup copy available for you, and it's located in your H:\Apache2\conf\ folder. The backup is named httpd.default.conf.
Setting up some basic values
Search for DocumentRoot and then change it from DocumentRoot "H:/Apache2/htdocs" to wherever you want to keep your site's HTML files. Mine is DocumentRoot "H:/httpdocs", because I have my HTML files located at H:\httpdocs\. Now search for <Directory "H:/Apache2/htdocs"> and change that path to the same as the previous one you picked out.
Turning on Server-Side Includes
If you don't know what SSIs are, or you just don't want to use them, you can safely skip over this section. Otherwise, this is what you need to do in order to turn site-wide SSIs on.
Search for Options Indexes FollowSymLinks and change it to Options All MultiViews. Then, search for #AddOutputFilter INCLUDES .shtml and change it to AddOutputFilter INCLUDES .html .htm .shtml .shtm.
Note: you can customize that last bit to your liking, if you wish. If you don't want all files with the extensions .html and .htm to be parsed, remove .html and .htm from the list. If you want any other file extensions besides the ones I've added to be parsed, add them in the same manner to that list.
Restarting Apache
Restarting Apache is easy to do, and it will need to be done whenever you make any changes to the configuration file (httpd.conf). Because the file gets read only when Apache starts, new changes won't take effect until you restart Apache. Double-click the Apache Service Monitor icon in the system tray (it's the one that looks like a feather with a green triangle on it) to open the monitor. Now just click the Restart button and wait for Apache to do it's thing.
After the server has been restarted, you'll see a message letting you know that the changes went through successfully. If you made a major error editing the file, Apache will let you know about it with an error message.
You can find the binary of ActivePerl 5.6.1 for Windows at: http://www.activestate.com/Products/Download/Get.plex?id=ActivePerl [direct link]. The file is 8.6 MB, and is distributed as an MSI package.
Installing ActivePerl
Start the installer, and then click through it (hopefully reading the prompts along the way) until you get to a screen that looks like the one below.
I highly advise that you install Perl to a directory similar to mine, which is H:\usr\ (yours needs to be whatever drive you have Apache installed on, i.e. C:\usr\ or D:\usr\). This is quite helpful if you also have a Unix or Linux Web server, because then the Perl path (the first line of any Perl file, usually #!/usr/bin/perl) will remain the same no matter what. Look at the screen below to see what I mean regarding installation paths.
Continue to set up Perl until you get to the screen below, for which you should make your options the same as mine.
Finish the installation by following the rest of the prompts, then continue on to the next section when you're done.
Testing the Perl installation
Create a new blank document in Notepad, and then copy and paste the code below into the file.
#!/usr/bin/perl print "Hello, World";
Save the file as C:\hello.pl. Start up the Command Prompt and wait until you see C:\>. Type perl hello.pl, hit Enter, and you should see Hello, World. If you see this, this means that Perl was installed successfully!
Allowing Perl to run freely
Back in your httpd.conf file, search for ScriptAlias /cgi-bin/ "H:/apache/cgi-bin/" and change it to #ScriptAlias /cgi-bin/ "H:/apache/cgi-bin/". Now find #AddHandler cgi-script .cgi and change it to AddHandler cgi-script .cgi .pl. What we've done here is allowed Perl to run from any directory, and also for files with the extension .pl to be treated as Perl files (which they should be!).
You'll need to restart Apache for these new changes to take effect (see the previous page for information on how to restart Apache).
Testing Web-based Perl
Create a new blank document in Notepad, and then copy and paste the code below into the file.
Save the file as H:\httpdocs\hello.cgi and then go to http://127.0.0.1/hello.cgi in your browser to test that it works. If you see what I see (screen shot below), give yourself a pat on the back!
You can find the binary of PHP at http://www.php.net/downloads.php [direct link]. The file is 5.2 MB, and is distributed as a single zipped file.
Installing PHP
Extract the zip file to a directory of your choice. I put mine at H:\php\. Some servers might crash if there's a space in the path name (i.e. H:\My 3l33t PHP Installation\), so try to steer clear of that.
Copying required files
You'll need to copy the file php4ts.dll to your C:\WINNT\system32\ folder (or C:\Windows\system32\ for Windows XP). Also copy the file php.ini-recommended to your C:\WINNT\ folder (or C:\Windows\ for XP) and rename it to just plain ol' php.ini.
And now for more file copying
Due to some changes in the working of Apache 2.0.39, the standard PHP DLL file for Apache2 will no longer function "out-of-box." This can be solved easily, by downloading http://www.ubbdev.com/files/php4apache2.dll [direct link]. Save and copy that file to your H:\php\sapi\ directory, overwriting any existing file. Life is good--for the moment, at least.
Editing your php.ini
Open up your newly copied and renamed php.ini file. Search for extension_dir = and change it to read extension_dir = H:\php\extensions (making sure to modify it to reflect your actual path). Search for doc_root = and change it to doc_root = H:\httpdocs where the path is the same as the one you picked for your HTML files back in step one. Sounds easy enough, right?
We'll leave the rest of the file alone for now, but if you'd like to modify more on your own, read up at http://www.php.net/manual/en/configuration.php.
Apache, meet PHP
We're going to run PHP as a module for Apache, instead of as a CGI binary, because it's more transparent and secure. And you really care about that, right? You're just waiting for me to get to the good stuff, so here we go.
Open up your httpd.conf file again (it's the last time, I promise) and search for #LoadModule ssl_module modules/mod_ssl.so. Directly underneath that line, add LoadModule php4_module H:/php/sapi/php4apache2.dll.
To try to keep all the "scripting stuff" in the same spot of my httpd.conf file, I put the remaining lines necessary for PHP near the line we modified in order to use Perl before. Search for AddHandler cgi-script .cgi .pl and then add this block of code a line or two below that.
# # To use PHP scripts: # AddType application/x-httpd-php .php .php3 .phtml AddType application/x-httpd-php-source .phps
The final section around that block should look like mine, which is below.
# AddHandler cgi-script .cgi .pl
# # To use PHP scripts: # AddType application/x-httpd-php .php .php3 .phtml AddType application/x-httpd-php-source .phps
# # For files that include their own HTTP headers:
Restarting the server
After making the outlined changes to httpd.conf, save and close the file. Then, double-click the Apache Service Monitor icon in the tray to pop open--you guessed it--the Apache Service Monitor! Click the Restart button and then wait a few seconds while Apache shuts down and starts back up.
When the server comes back online, your screen should look like mine; also take note of the text at the bottom of the window that reads Apache/2.0.39 (Win32) PHP/4.2.2-dev. This just means that all is well in Apache land.
Your first PHP script
Copy 'n paste
code:
<? phpinfo(); >
into a new file in Notepad and then save it as H:\httpdocs\phpinfo.php. To recap, the entire file should read
code:
<? phpinfo(); >
Now browse to http://127.0.0.1/phpinfo.php and check to make sure that what you see looks like my screen shot below.
If you can't see this screen, you hit a bump in the road somewhere along the way. Your first move should be to visit http://www.php.net/manual/en/install.apache.php. Start by reading the newest comments (the ones at the very bottom of the page) to check if your problem has already been encountered by another user.
Enabling compressed output
Optionally, you can choose to compress PHP output using zlib compression. This cuts down on your bandwidth and also helps pages to load faster. If you'd like to turn zlib on, just follow the steps below.
According to the zlib Web site (http://www.gzip.org/zlib/), zlib is "a free, general-purpose, legally unencumbered--that is, not covered by any patents--lossless data-compression library for use on virtually any computer hardware and operating system." So there you have it, straight from the horse's mouth. Let's turn it on already, shall we?
In php.ini, search for zlib.output_compression = off and change it to read zlib.output_compression = on. All you have to do next is search for ;extension=php_zlib.dll and change the line to read extension=php_zlib.dll. Browse to http://127.0.0.1/phpinfo.php once more and then scroll down to the section about zlib. You should see what I see.
You can find the binary of MySQL at: http://www.mysql.com/downloads/mysql-3.23.html [direct link]. The file is 12.1 MB, and is distributed as a single zipped file.
Installing MySQL
I love installing MySQL because of its straightforwardness. It's a nice break from all this configuration file mumbo jumbo that we've been working with. All you need to do is unzip the mysql-3.23.51-win.zip file to a folder (C:\Temporary for all I care) and then execute the setup.exe program. I'd guess that the hardest part of the entire installation is deciding where you want to install to. I picked H:\mysql\, but you can choose whatever you want.
Configuring MySQL
Editing your my.ini
Create a new file in Notepad and copy these three lines into it.
Change the basedir and datadir to suit your actual installation, using mine as a model. Then, save the file as my.ini and place it in your C:\WINNT\ directory, so that the full path of the file is C:\WINNT\my.ini. You can close the file now.
Running as a service
Start up the Command Prompt and wait until you see C:\>. Switch to the drive you installed MySQL to by typing h: and then Enter. To switch to MySQL's bin directory, type cd mysql\bin and hit Enter. To install MySQL as a service under Windows 2000/XP, type mysqld-nt -install and hit Enter.
You should see a screen similar to the one below, with a message letting you know that the service was successfully installed.
At this point, you can restart your computer. You could forge ahead without restarting by typing net start mysql and then pressing Enter. What you'll see is a message confirming that the MySQL service was started successfully. It looks strikingly and amazingly similar to the one below.
Messing with the settings
To change the default MySQL password, enter the mysqladmin -u root password "myNewPass1488" command from the H:\mysql\bin\ directory. Change myNewPass1488 to a real password of your choosing. To make sure that the change went through, type mysqladmin -u root reload and hit Enter. What you want is a message telling you that access was denied.
Let's just play with one more thing before calling it a night (which has no doubt turned back into day by now). Type mysqladmin -u root -p status and press Enter, and then type in your password when prompted. You'll see some basic information about the currently-running service.
To shut down MySQL, type mysqladmin -u root -p shutdown and hit Enter. Enter your password, press Enter again, and then close the Command Prompt window. And that's that for MySQL!
If you've gotten this far, I congratulate and commend you, brave soldier! I know that this subject matter is not exactly on the same "fun level" as riding a roller coaster, but I tried to keep it as straightforward and to-the-point as I possibly could. By now, you should be able to walk away with a fully-functioning, feature-packed, somewhat-secure (just kidding on that one) Web server of your very own to play with.
As your guide through the rough terrain, I can look back and rest easy tonight knowing that someone with the very same questions as me will now have answers to [some of] them.
What to do with this guide
You could:
Print it out for reference;
Save it to your hard drive;
Give it to your niece as a Christmas present;
Let your dog relieve hims--nevermind.
If you found this series useful, spread the word by emailing your friends, posting a link back to it in your blog, or even writing a short blurb on your site about it.
Going live with it all
Everyone loves .coms
If you have a broadband (cable, DSL, T1) connection to the Internet, you've probably got this crazy notion in your head that you can just leave your computer on all the time and start printing your IP address on your business cards in place of a URL. Well, you could do that, but I've got a better idea.
I suggest you read about DNS2Go at http://dns2go.deerfield.com/. The program is free to download and use, and you can even get a free subdomain of your choice when you sign up. If you've already got your own FQDN (Fully Qualified Domain Name), you can even use that, too! There are far too many good features of DNS2Go to list here, so instead of trying, I'll just remind you to check out that URL above.
Server security concerns
If you're planning on making your computer available to the world 24/7, you're going to need some protection for it. Luckily, half the work has already been done, because we're using Apache instead of IIS. However, there are a few more products you'll need to obtain in order to have some system security. I recommend getting:
A hardware firewall (Linksys makes an excellent router/firewall);
A software firewall program, such as ZoneAlarm by Zone Labs;
A good anti-virus program, such as Norton AntiVirus by Symantec.
Also make sure that Windows is fully patched and that your virus definition files are up-to-date. IE6 is notorious for having gaping security holes, so just keep an eye out for any alerts or warnings you read.
All I ask is that you don't slap your name on the front page and publish this guide elsewhere to gain quick recognition from your friends and family. If you want to re-publish this on any site or actually anywhere, for that matter, please just get my permission first by dropping me a line. I'd be more than happy to help you out.
Thanks for investing your time by listening to my drivel, and I hope this has been as much fun for you as it was for me!