Showing posts with label Web Server. Show all posts
Showing posts with label Web Server. Show all posts

Sunday, August 10, 2008

Making your home web server

Geek to Live: How to set up a personal home web server

client-server-model.jpg

by Gina Trapani

Last updated: September 2006

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 Lifehacker'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 [1]
  2. An always-on broadband (DSL or cable) internet connection

Step 1. Install Apache HTTP server. [2]

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 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 Software Foundation\Apache2.2\. When you reach the screen prompting for server information, enter your own email address and homeip.net [3] 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. [4]

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 [5], 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 [6], 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 Software Foundation\Apache2.2\bin"

Then create a password file by typing:

htpasswd -c "C:\Documents and Settings\Gina\my_password_file.txt" 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:\Documents and Settings\Gina\my_password_file.txt"
AuthGroupFile /dev/null


require valid-user

Make sure you replace "C:\Documents and Settings\Gina\my_password_file.txt" 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.

Note: If you're using Notepad to create your .htaccess file, when you save the file, put quotes around the filename - ".htaccess" - so that Notepad doesn't automatically put a .txt extension on the file. If there's a .txt file extension, your password won't work!

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. [7]

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 is covered in Lifehacker feature How to access a home server behind a firewall.

Enjoy your new home web server!

Further reading on running a personal 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. [back up]

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

[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. [back up]

[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. [back up]

[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. [back up]

[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. [back up]

[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 Lifehacker feature. See Lifehacker feature Assign a domain name to your home web server for details. [back up]

Tuesday, June 3, 2008

Hosting your website from your home computer!

Hosting your web site from your home/office computer

Typically, a web server is a powerful machine with a stable and reliable operating system and a 24/7 Internet connection. A web server also needs a static I.P. (Internet protocol) address so that the location of the hosted web site/s does not change. In addition to the web server software (which serves web pages), several other software that help in maintenance, enhancing functionality and securing the machine from attacks from hackers need to be installed on the machine.

The need for a good operating system:

Obviously, you need a stable and reliable operating system that can serve web pages quickly and not crash or hang even under heavy traffic.

In-built security features to protect from hackers and virus attacks:
Easy of administration through shell environment or GUI-based software.
Scalability to up-gradations to ensure enhanced stability and security. Also, the process of installation of updates should easy and as smooth as possible.
In-built necessary server software should be a part of the operating system else, they should be available and installed quickly and smoothly.
Availability of third-party software - No operating system is perfect and complete. Third party applications can provide additional security, better features and functionality.
With the above points in mind, the Linux operating system fits the bill pretty well - So does Windows, actually, but you do need to be a little more experienced in server administration if you want to run a Windows based web server.
Linux is also cheaper than Windows and has tons of free third-party software and applications that can be smoothly integrated in the operating system to increase functionality and security. Linux, which is an Open Source Software (OSS), works well with other OSS such as Apache (the most popular web server software), MySQL (a good stable database application and server), PHP (server-side scripting language) and has several in-built applications such as FTP (File Transfer Protocol), sendmail (SMTP email server) etc.

The need for a static I.P. (Internet Protocol) address:
Each computer connected to the Internet needs to have a unique number assigned to it so that it can be identified and there are no conflicts with other computers. This unique number is the Internet Protocol (I.P.) address. The I.P. address is just a series of four numbers each less than 255 and separated by dots (periods). For example, 213.34.17.90 would be a valid I.P. address.
Since, for us humans, I.P. addresses are not as easy to remember, the "powers that be" created domain names. However, each domain name is "tied up" or "associated" with an I.P. address. The domain name and its corresponding I.P. address are stored on several different computers scattered around the globe. These machines called Domain Name Servers help to resolve the domain name to its I.P. address. In layman's language - when you type a domain name on your browser, it first checks with a Name Server and gets the corresponding I.P. address (something that computers understand better than us) and then loads the web site.
An I.P. address is the address of a computer on the internet - it specifies the location of a server that hosts a web site. It follows that if the I.P. address changes, the web site will not be found if you try to load it on a browser by typing its domain name.
Now, most of us use net connections on our home/office computers from the local Internet Service Provider. These ISPs assigned our computers with a dynamic I.P. address each time we connect. Thus, each time we disconnect and start the connection again, our computers are given a different I.P. address. So if the I.P. address of your home/office computer changes, your web site will not load unless you go and change the information on the Name Server. Obviously you cannot make these changes each time your computer's I.P. address changes. For this reason, to host a web site on your home/office computer you need a "static" I.P. address - an I.P. address that does not change.
The problem is that ISPs generally do not allow you to host a web site on your computer. And they do this by allocating a new I.P. address each time you connect and also blocking required ports. Having said that, you can get a static I.P. addresses by either upgrading your package (to something like a "business package") or shift to an ISP that does provides one. The cost of a static I.P. can be an extra $30 to $50 per month (maybe even more). Check with your Internet Service Provider. This, in my opinion, is just too much when web hosting companies offer feature-rich packages for as low as $10 per month.
Also check DynDNS.org if you want a static I.P. from a dynamic address. FYI, some ISPs would actually fine you if you host a web site on their net connection.
The need for 24/7 connectivity to the Internet
A fast Internet connection is as important as a stable 24/7 connection. You would not like your web site to download slowly would you? Any downtime in the net connection would result in your web site being offline.

The need for Server software:
According to Netcraft server statistics, Apache still is the most popular and widely used web server on the net. Apache is an open source software (read free) that can be installed on various platforms including Linux/Unix, Windows, Mac.

Its easy to install the Apache web server. In fact, most Linux versions come with an Apache server already running or one that can be installed and configured in a few clicks.

The need configuring your computer for security and accessibility:
If you plan to host a web site on your home/office you cannot leave it open to attacks by hackers. Also you need to protect important directories - ones containing files of the operating system or other programs that are critical for smooth and error-free running of the server. Your system has to be configured properly to protect against accidental or intentional misuse.

The final conclusions:
Hosting your web site on your home/office computer would be a great learning experience to all adventurous people out there. For most of us, it's wiser and quicker to just go to a reliable hosting company and pick up a web hosting package because these companies take care of maintaining the server, the internet connection, server security and power backups.

Thats it!!!