## Setting up an Apache web server ## Jim Mock Okay, so you've got a system, and you've installed FreeBSD on it, and now you want to make it a web server. The most common web server is Apache, which is the server I'll be discussing in this article. The easiest way to install the Apache server is from the ports collection. If you haven't got the ports collection installed, run /stand/sysinstall (as root) from the prompt, choose Configure, then Distributions, and scroll down through the distributions until you get to ports, and click the space bar to check it. Scroll down to Exit this menu (returning to previous). You'll then be asked to choose the installation media. If you have the cd's from Walnut Creek, put the proper disk in your cd-rom drive and choose the cd-rom install. If you don't have a FreeBSD cd, choose one of the other options, FTP would probably be the most common choice. Next you'll be asked to choose an FTP distribution site. Choose the one closest to you. If your machine is already set up and you just didn't install the ports collection during the FreeBSD install, you'll get a message saying "Running multi-user, assume that the network is already configured", choose yes, and you should be well on your way. If you have problems, see the FreeBSD Handbook. After the ports collection is installed, or if you already had it installed previously, it's time to install Apache. The first thing you'll want to do is go to the /usr/ports/www directory.. [root@hendrix:~]# cd /usr/ports/www Next you'll want to "make" Apache.. [root@hendrix:/usr/ports/www]# make apache13 Once the port is done compiling and you're sent back to the prompt, it's time to install it.. [root@hendrix:/usr/ports/www]# cd apache13 [root@hendrix:/usr/ports/www/apache13]# make install Okay, Apache is now installed. The next thing you'll need to do is configure it. To start the configuration, you'll need to be in the directory where Apache was installed. With the version I have installed, it's /usr/local/etc/apache. If that directory doesn't exist, you can do a find for the conf files. From the prompt, type the following.. [root@hendrix:~]# find / -name httpd.conf -print /usr/local/etc/httpd.conf [root@hendrix:~]# That'll give you the directory where httpd.conf is located. Change to that directory and once you're in it, type ls to see if the other Apache configuration files are there as they should be.. [root@hendrix:/usr/local/etc/apache]# ls access.conf-dist httpd.conf-dist srm.conf-dist mime.types-dist [root@hendrix:/usr/local/etc/apache]# A good idea would be to keep a copy of the dist-files even though it's not necessary. I usually make a dist_files directory and copy all of them there.. [root@hendrix:/usr/local/etc/apache]# mkdir dist_files [root@hendrix:/usr/local/etc/apache]# cp *-dist dist_files [root@hendrix:/usr/local/etc/apache]# The next thing you'll want to do is rename all of the *-dist files to access.conf, httpd.conf, srm.conf, and mime-types.. [root@hendrix:/usr/local/etc/apache]# mv access.conf-dist access.conf Do the same with the remaining three files. Now it's time to edit the conf files, in this case, I'll only show httpd.conf (the main configuration file) for space reasons. See The Apache Project web site for more info. Open up httpd.conf with your favorite editor. I use pico, so at the prompt I'd type.. [root@hendrix:/usr/local/etc/apache]# pico httpd.conf Once you have it opened up, scroll down until you find the following.. # ServerType is either inetd, or standalone. ServerType standalone You'll most likely want to keep that as is, unless you want to run Apache from inetd for some reason. Let's assume that we keep it set to standalone. Underneath those lines, you'll be able to set the port number you wish Apache to listen on. The default is 80. We'll leave that as is too. The next part you'll see is HostnameLookups. This is set to off by default. If you want Apache to log the names of clients instead of their ip numbers, turn this on. For example, phrantic.phear.net (on), or 206.58.96.18 (off). After the HostnameLookups are the User and Group. The defaults are.. User nobody Group nogroup We'll leave those as is for the example. You can also create a separate user and group that you'd like Apache to run as. For example, www. If you do decide to run it as a different user and group, you'll have to initially start httpd as root and then it'll switch. Next is ServerAdmin. Set this to the address where problems with the server should be mailed. Example, webmaster@foo.bar.com, where foo.bar.com is your domain. After setting the ServerAdmin, the next question is the ServerRoot. The default should be /usr/local. We'll leave it as that. The next few sections deal with logging. The comments in the httpd.conf file are self-explanatory and the default values for each should be fine. If you'd like more detailed logs, visit http://www.apache.org/ for more logging configuration options. After logging, the next few sections should be ok set to the defaults. They are PidFile, ScoreBoardFile, and LockFile. The next section is important. It is where you'll specify the name you want your web server to run as. For example, on one of my machines, the hostname is phrantic.phear.net, but I want to run Apache so when people go to my web site they can go to www.phear.net instead of phrantic.phear.net. I'd specify this in the ServerName section.. ServerName www.foo.com (where foo is your domain) You cannot just invent hostnames! The name that you specify must be a valid DNS entry for your host. If you're confused about this, talk to the person who handles your name server. The section after ServerName is UseCanonicalName, which is new in Apache version 1.3 and higher. If this is turned on, whenever Apache needs to construct a self-referencing URL, it will use ServerName and Port to form a canonical name. With this setting off, Apache will use the hostname:port that the client supplied if possible. It also explains this in the comments in httpd.conf. CacheNegotiatedDocs is the next section. By default, it is commented out, and Apache asks proxy servers not to cache the document. If you uncomment the line, it will disable this, and proxies will be able to cache the documents. All of the following sections from Timeout down to VirtualHost should be ok set to the defaults. I'll cover Virtual Hosts (Virtual Servers) in next month's article (unless someone else decides to write an article on it). Well, that was the bulk of configuring Apache. You'll still need to go through access.conf and srm.conf to see if you need to make any changes specific to your server, but those shouldn't be much for a basic Apache install. See The Apache Project web site for configuration details with access.conf and srm.conf. Now it's time to start httpd. The installation should've put the httpd binary into /usr/local/sbin. You can start httpd manually a few different ways. The first is using apachectl (1.3 and up).. [root@hendrix:~]# /usr/local/sbin/apachectl start And the second is starting it directly from /usr/local/sbin like so.. [root@hendrix:~]# cd /usr/local/sbin [root@hendrix:/usr/local/sbin]# ./httpd [root@hendrix:/usr/local/sbin]# Either will work if everything is configured correctly. If you'd like to start Apache on boot up, there are a few ways to do it, but the way I've always done it is by adding a line to /etc/rc.local. Change directories to /etc and open up rc.local with your favorite text editor (again, I use pico).. [root@hendrix:/usr/local/sbin]# cd /etc [root@hendrix:/etc]# pico rc.local When rc.local opens, look for this line.. # put your local stuff here And underneath it enter the following.. # put your local stuff here /usr/local/sbin/httpd This will tell Apache to start when rc.local is read on boot up. Now check to see if Apache is running by typing ps auxw |grep httpd from the prompt. You should see a few different httpd processes running. If you do, good, you're done! If you don't, go back over the steps to make sure everything is configured correctly and try restarting it again. If you find any errors in this document, please email them to me at so I can post the changes. Good luck, - Jim $Id: apache.txt,v 1.1 2000/02/16 08:07:40 jim Exp $