Basic (Web)Server Concepts

This is a quick explanation of some basic server concepts, particularly as they relate to webservers and websites.  I wrote this page so that I didn't have to keep repeating things on the pages for my login script, weblog script, mailinglist script, etc.  One of the main goals is to allow me to explain some of the differences between running a Windows server and running a Unix/Linux server, because I found myself constantly having to stop and explain/qualify my statements about how to install my scripts due to the differences between these platforms.



The Very Basics

When you talk about "your server" for your website, it's usually a computer on the internet owned by some company, called your "hosting company" or just your "host."  (It could also be your school, employer, etc.)  But, you could also use your own computer as your server for your website.

If you are using a hosting company for your website, then you typically create/edit your webpages and scripts on your own computer, then upload them to your webserver.  To upload them, you usually use an FTP client such as SmartFTP for Windows, or gFTP for Unix/Linux.  FTP clients are simple to use; you just enter your server's name (which is probably just your website address), enter your username and password for the server, and that logs you in.  Once logged in, you can upload files from your computer to the server, or download files from the server to your computer.  This is as simple as "drag and drop" with these two particular FTP clients (and many others, too).

If you are using your own computer as your server, then you don't have to do any uploading, so you don't need an FTP client.  You just edit your webpages/scripts right on your computer.  Your webserver program (which is probably Apache) simply uses a certain directory on your computer as your website.



If Your Server is a Unix/Linux Computer...

(and note that it usually is, even if your own computer is a Windows one... unless of course you are using your own computer as the server, as described above)

...then you'll have to chmod files sometimes.  This just changes the permissions of the file.  For example, if you put a file on your server, but its permissions say that only the owner (you) can read the file, then people visiting your website won't be able to view the file.  But if you chmod the file as a+r ("all+read"), then everyone can read/view it.  And when you put scripts on your server (usually in the /cgi-bin/ directory), they need to be chmodded as executable in order to work.  So you chmod your script as a+x ("all+execute").

Note: here's what the chmod permissions mean:
0644 or a+r: world readable, owner writable, not executable.
0666 or a+rw: world readable and writable, not executable.
0755 or a+rx: world readable and executable, owner-writable.
0777 or a+rwx: world readable, writable, and executable.

And note that FTP clients usually have a chmod feature built in to them, so you do the chmodding with the FTP client after you upload the file onto the server.

To run perl CGI scripts, you need to put the path to the perl binary as the first line of each script, like this:

#!/usr/bin/perl

Note that /usr/bin/perl is where perl is usually installed; run the command which perl to find out for sure.



If Your Server is a Windows Computer...

...then it has no concept of file permissions.  (Or at least, not any significant/useful concept of them.)  So if you're reading instructions about installing a script on your server, and they tell you to chmod the script, you can ignore that instruction, because Windows has no chmod command.

To run perl CGI scripts, you'll need to install ActivePerl, which is a verion of perl for Windows, distributed for free by the company ActiveState.  Once it's installed, you'll need to find out where the perl binary (perl.exe) is at.  This is probably somewhere like c:\perl\bin\perl.exe or possibly c:\program files\activestate\perl\bin\perl.exe.  Use the Search/Find function on the Start menu to search for perl.exe if you can't find it.  Once you've located it, you need to use its path as the first line in all your perl CGI scripts, like this:

#!c:\perl\bin\perl.exe



One Extra (Important) Windows Note

If you ever happen to open a text file on your Windows computer, and it looks like all the text is smooshed onto the first few lines, and there's little if any whitespace or blank lines, try this: open the file in Wordpad (NOT Word), and click File, Save.  That should fix the problem.  (This problem can happen when transferring files from a Unix/Linux system to a Windows system, because the different platforms have different kinds of line-endings.)