Apache is the most popular web server software in the world according to the NetCraft Web Server Survey. So, what is web server software? A web server is nothing but a program that serves the documents, images, and all other stuff you have at your web site to the outside world. It is basically a file transfer program. It accepts requests and fulfills them if it can (e.g. it can't send a web page that is not found on your site).
When it comes to develop dynamic web pages with a server-side scripting language like PHP, you will need a web server running on your computer. Otherwise PHP cannot run your code because it works as a module of the web server software. On the other hand, you can of course directly write your applications on your web hosting company's server on a telnet or SSH connection. However this is not feasible for two reasons:
It almost never feels like you are typing at your own computer because there is lag between your computer and remote server.
It is much easier to keep an identical copy of your web site on your computer thus using it as a production server, and copy your documents to the web server via FTP after everything is working properly on your computer.
If you want to install Apache under Windows, you can download the latest version directly from Wow Web Designs. If you are going to install it under anything other than Windows you can find several different versions for various platforms at http://httpd.apache.org/dist/. You can download binaries (already compiled, executable versions) for faster installation. However I prefer to download source distributions and compile them on my own system for best performance and full control over the installation process. Also you may not always find the latest release in already compiled form for your system. Meanwhile, compiling may take a long time on slow systems though Apache compiles pretty fast in comparison to MySQL or PHP. If you decide to compile Apache, download the file apache_1.3.xx.tar.gz at the above location where xx is the latest release (the bigger the better). I will explain the installation process step by step in the next section.
If you are using Windows 9x or ME, you may need to download the new Windows installer first to install Apache.
I'd like to thank Horacio Bermudez for bringing this matter to my attention.
For Windows
Double click on the apache_1.13.xx-win32-src.msi file. When your server information is asked type localhost in the first two fields and admin@localhost in the last field. Next, you can choose a complete install or a custom install. If you choose custom install you will have the option of not installing the source code. You will not need it unless you are a C programmer and want to examine the source code, so you can safely choose not to install it. That will save you about 12 MB of disk space.
When your server information is asked type localhost in the first two fields and admin@localhost in the last field.
For Unix (including Linux)
Download Apache in a directory of your choice, if you already didn't. The command bellow will download it for you where xx is the version number. You can of course download it with your web browser too:
Assuming that the Apache archive is in the current directory decompress it with
gunzip -c apache_1.3.xx.tar.gz | tar -xvf -
This will create a directory called apache_1.3.xx in the current directory. Change to it by typing
cd apache_1.3.xx
If you want to install Apache to another location add the --prefix option (e.g. --prefix= /var/lib/apache) to the command line.
Run the configuration program with the most common options. This will configure Apache for to be installed to the default location (/usr/local/apache). The --enable-module=most option will install all dynamic modules with the exception of the problematic ones, and --enable-shared=max enables Apache to load modules into memory only when needed.
For Windows
Apache normally runs automatically at startup. So there is no need to run it manually.
For Unix (including Linux)
To start Apache change to the directory where you installed it, and type the following:
./bin/apachectl start
Once Apache started, you can launch your browser and type localhost in the address line. If you see the (in)famous "Seeing this instead of the website you expected" page, it means Apache is running. But if you get an error try typing 127.0.0.1 in the address line. If this too doesn't help then something went wrong.
If you see the (in)famous "Seeing this instead of the website you expected" page, it means Apache is running.
Although there is no official GUI (Graphical User Interface) for configuring Apache, you only have to edit one text file, and it is pretty self explanatory.
The configuration file is called httpd.conf, and it is found in the conf directory of Apache. The path is normally C:\Program Files\Apache Group\Apache\conf under Windows, and /usr/local/apache/conf under Unix.
Open httpd.conf with your favorite text editor (if you open it with a word processor such as MS Word make sure that when you save the file it will be stored as a text file). You have to change only two lines. You can leave all others untouched; default values would be ok for most purposes.
If you want Apache to store agent (browser information) and referer (sites that send your site visitors) information in the server log file uncomment (remove #) the following line
CustomLog logs/access.log combined
and comment (add a # to the beginning) this line, which is just a few lines above:
CustomLog logs/access.log common
A log file is a detailed record of all requests made to your server and your server's responses. You can find various log analyzers on the Internet. A popular free log analyzer for Unix based systems is Webalizer.
Find the ServerName field. You can find it by searching it (e.g. Ctrl+F). Uncomment it by removing the pound sign (#), and type your server's name. If you don't have a server name you can write localhost. On our web server the field's value is www.wowwebdesigns.com, and on our production server it is localhost.
ServerName localhost
Find the DocumentRoot field. It should come right after ServerName. This field must point to the directory where you will serve your HTML files. This directory will be your root directory of your web server. For instance on our Windows production computer DocumentRoot is set to "D:/WowWebDesigns/htdocs". Note that no matter which platform you use (Unix or Windows) a slash (/) is used to seperate directories instead of a backslash (\). Here is another directory example:
DocumentRoot "/home/someuser/my_web_site"
Let's assume that you put example.html into the directory /home/someuser/my_web_site. You can access this file by typing localhost/example.html in the address field of your browser. If you create a directory, say reviews under /home/someuser/my_web_site, you can access it by typing localhost/reviews/. That's all simple.
Now restart the server, and the changes you have made will immediately take effect. You can restart Apache by typing ./bin/apachectl restart (assuming that you are in the Apache root directory) under Unix. If you are using Windows, you can either restart Windows, or enter C:\Program Files\Apache Group\Apache\apache -k restart from Start Menu > Run. If you prefer the latter, it might be easier to create a shortcut since you may need restarting the server more than once.
Fantastic site - just what I need to get PHP-Apache-Linux-mySQL up and running. I am an amateur programmer from India, and I have developed both internet and intranet sites on the Windows platform. Now, out of curiosity and necessity, I am changing to Linux. Here's wishing myself all the best and hey, you too. Keep up the good work !!!!
I've searched TONS of web pages over the past 4 days looking for information on how to set up my server after messing it up. The information contained in this article helped me get my web pages back online.
The only thing I wish it did more of was went into greater detail on the httpd.conf file settings such as creating additional virtual hosts.
good article. But is it true that it is only possible to run on apache and maybe not personal web server? If it is possible, I hope you can give me the correct way to do it.
Great!!! thank u very much, i spent more than one day looking for a tutorial like this one, nothing was working! finally i got it!!!, im going to add a link to u on my website thanx again! from Tepatitlan Jalisco Mexico, your friend Gera!
Wow. What a great article. Previously I was running VMWare on top of Win2k so I can run apache+php+mysql. That was a pain in the ass and vmware decided to fail me this morning. I just couldn't get it running again. I much prefer running everything natively like this.
This article made all the configuring a breeze, not to mention the binaries you guys made available for us.