BotHack

BotHack makes getting things done easy and fun. Delving deep into the technoweb, BotHack brings back simple and totally life-altering tips and tricks for managing your information and time. At this wild moment in the development of human-oriented technology, BotHack is your own personal early adopter, here to guide you through the onslaught of the new. The world is full of fascinating problems waiting to be solved: BotHack can help.

Friday, September 09, 2005

How to set up a personal home web server

A web server is software that continuously runs on a computer and allows other computers to download documents from it. This text that you’re reading right travelled over a network connection from Blogger’s hosting web server to your browser. Web servers are usually loud, scary, headless machines in cold windowless rooms, but you can run one under your desk at home.

Why would you want to run a home web server? Maybe you want to download files on your home computer from anywhere. Like, say, your digital music collection. In this how-to, we’ll set up a home web server that lets anyone (with the right password!) connect to your computer and download your MP3’s from it, for a nice way to share your music collection with friends, or play a song from your home machine at the office for co-workers.

Please note: Running a server on your home computer is a risky undertaking, and before you start, make sure your computer has all the latest patches and security updates, and that you’ve done a thorough spyware and virus scan. This tutorial is for advanced users who feel comfortable editing textual configuration files and exposing port 80 on their home computer to the internet. As always, a strong firewall with explicit user-set rules is recommended. Still game? Carry on.

Let’s get started.

What you’ll need:

  1. A Windows PC
  2. An always-on broadband (DSL or cable) internet connection

Step 1. Install Apache HTTP server.

First and foremost, disable and stop any other firewall or server software you may have running, including Windows Firewall, Skype, Trillian or any other instant messaging applications. This is extremely important, and if it’s not done, can cause the server installation and startup to fail miserably. These programs and services can be started and used again as usual once we’re done setting up the web server.

Download Apache HTTP Server from here, using the link under “best available version” next to “Win32 Binary (MSI Installer).” Start the installation wizard. Accept the license agreement and use the default location for the Apache files, in C:\Program Files\Apache Group\Apache2. When you reach the screen prompting for server information, enter your own email address and homeip.net as the domain information, like so:

apache-server-info.jpg

Complete the installation wizard using the “Typical installation” setting.

When it’s done, open your web browser and go to http://localhost/. If the page you see reads, “If you can see this, it means that the installation of the Apache web server software on this system was successful,” you’re golden.

Step 2. Configure Apache to share documents from the right folder.

Say you want to make your music collection downloadable using your new web server, and all your music files are located in C:\Gina\My Music. Using a plain text editor like Notepad, open the C:\Program Files\Apache Group\Apache2\conf\httpd.conf file. This is Apache’s configuration file, which looks long and scary, but most of the defaults will work just fine for us. We just have to change a few things.

In this httpd.conf file, comment out the line that starts with DocumentRoot and add another with your directory, like this:

#DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
DocumentRoot "C:/Gina/My Music"

Then, comment out the line that starts with

#

Last, about 20 lines below that

AllowOverride None

Change it to:

AllowOverride All

When you’re done, save httpd.conf. Then, click on the Apache icon in your taskbar and choose “Restart.” If Apache restarts successfully, you edited your the file correctly. Visit http://localhost/ in your web browser. This time you should see a listing of your music files. Woo-hoo!

Step 3. Password your web site documents.

But we don’t want just anyone to be able to download your music. Your bandwidth is precious, and we want to secure things a bit. Let’s create a password prompt.

First, open a command prompt (go to the Start menu, choose Run, then type cmd.) Change to the Apache bin directory by typing:

cd "C:\Program Files\Apache Group\Apache2\bin"

Then create a password file by typing:

htpasswd -c C:\Gina\my_password_file gina

Replace the path with the path of your new password file (which should in any folder EXCEPT the web server’s document root.) Replace gina with the username you want to use. When prompted, enter the password you want to set up. Once you’ve done that, a password file will be created.

Now we want to apply that login to your music directory. Open up a new file in a plain text editor like Notepad. Copy and paste the following into it:

AuthType Basic
AuthName "This is a private area, please log in"

AuthUserFile c:\Gina\my_password_file
AuthGroupFile /dev/null


require valid-user

Make sure you replace C:\Gina\my_password_file in the text with your own password file created above. Save this new file IN YOUR WEB SERVER DOCUMENT ROOT (in this case, C:\Gina\My Music) and name it .htaccess. Don’t forget the dot in the beginning, before .htaccess. So, in this case, we’re saving the file as C:\Gina\My Music\ .htaccess.

Now, using your web browser, go to http://localhost/. You should be prompted to log in. Enter your username and password you set up in your password file. Rock!

Step 4. Congratulate yourself. You’ve got a home webserver running.

If you are NOT behind a firewall, you can access your web server from other computers by typing your computer’s IP address into a web browser’s address bar. If you’re not sure what your IP is, visit What Is My IP to find out. If your IP is 12.34.567.890, then type http://12.34.567.890 into a browser’s address bar.

If you ARE behind a firewall (like a wireless router), you’ll need to open up port 80 on the firewall and forward it to your computer. This part is beyond the scope of this article, but will be covered in a future Lifehacker feature.

Enjoy your new home web server!


FOOTNOTES:

[1] Sorry Mac folks, but OS X comes with a web server all set up, so this tutorial’s not for you.

[2] There are other web servers out there, but we’re going with Apache HTTP server because it’s free, stable, and my favorite.

[3] It doesn’t matter what domain you put here. I chose homeip.net because it’s descriptive, and one of DynDNS’s home domains.

[4] A common during-installation error with Apache reads, “Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down. Unable to open logs.” This means that some other server program (like Skype) is interfering with Apache. To figure out what program it is, open a command prompt and type:

netstat -a -o
Find the PID (Process ID) of the program running on your local machine on port 80 (or http.) Then open the Windows Task Manager (Cntl-Alt-Del). In the View menu, choose Select Columns, and check off PID. Then match the PID to the running process to find out what server program is running, and stop the program. Then retry the Apache installation.

[5] There are tons of uses for your personal web server beyond a password-protected jukebox. Publish your blog at home, host a personal wiki, share video files and photos. Basically any file you want to publish as read-only is a good candidate. A home web server has the advantage over special server/client software because it only requires a web browser to connect to it.

[6] If Apache doesn’t start correctly, it’s because it can’t read the httpd.conf file, which means you probably had a typo in your changes. Check your changes very carefully, save and restart Apache to try again.

[7] Keep in mind that depending on your internet service provider, your computer’s IP address may change. There’s an easy way to set up a memorable name that doesn’t change, but that topic will be covered in an upcoming BotHack feature.


Die Dulci Fruere

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home