Apache Setup

His Website Will Outfrown Yours

Apache is remarkably easy to get running.  It is all governed by the service daemon “httpd” and can be installed easily with a yum or apt-get install command if it didn’t come packaged with your distribution.  Any repository that was preinstalled should have it easily available.  The yum command in CentOS would be:

yum install httpd

The configuration file is easy to edit with the command:

vim /etc/httpd/conf/httpd.conf

Almost everything you could need for a simple webserver is already set up for you, and already configured.  The two simplest edits you can change would be the port(s) Apache listens on and the DocumentRoot setting that tells the service what local directory on the server itself will act as the root directory for web pages.

You can change it from listening from port 80 to any other valid TCP port by finding the line that says “Listen 80″  and changing it to “Listen <xxx>” where <xxx> would just be whatever port you want to try.  If you wanted port 3005 you would change the line to say, “Listen 3005″ and save the file.
Just as a side note for alternate ports, the assumed port for http url browsing is port 80.  It’s implied in all standard browsers that when you access a url or an ip of a webserver that it is to be done over port 80, unless directly told otherwise.  The method for accessing a url or ip over a specific port is to enter the url/ip like so http://<ip_or_url>:<port>

For example, accessing your loopback ip over port 3005 would work as such in a browser:

http://127.0.0.1:3005

This will access your DocumentRoot folder on the webserver, and will normally allow you to access any file inside that directory that the Apache service has access to.  The browser used to access the file will in large measure determine how that file is accessed.

DocumentRoot configuration is just as simple.  The default directory for CentOS is /var/www/html but you may want to change that for whatever reason.  It’s easy to change that by doing the same vim command as above and changing the line that starts with DocumentRoot “/var/www/html” to use whatever directory you prefer that Apache has access to.

For example, if you wanted Apache to access /home/myuser/webfiles you would change the line to look like so:

DocumentRoot “/home/myuser/webfiles”

Any time you make a change to the http.conf file and you want to see its effects, you’ll need to restart the httpd service like so:

service httpd restart

Once the service is restarted, you should see any changes immediately when you access it from a browser.