Apache Installation Tips for PHP, SQL Server, MySQL on FreeBSD, Linux, OpenBSD, NetBSD Logo Tuesday, December 05, 2023
By The Voodooman what's new | faq | about


We're almost at the end of the process. All that remains to be done is to configure Apache to run properly and then your web-site should be up and running.


The first thing to do is to make sure that the httpd daemon is not already running. You can check this by typing:

ps -xaf

If you see any httpd processes running, then note down the number under the PID column for the first httpd process and type the following at the prompt:

kill PID

where PID is the number that you noted earlier. This will stop the running httpd processes. You can verify that the processes are not running any more by typing 'ps -xaf' again.

Security Tip
In the interests of security, you should add an account called www for running apache alone. Older versions of FreeBSD and all versions of RedHat Linux do not come with this account installed by default. If this account is not already present on your system, add it now. To add this account, type:
  • adduser www

  • Now make sure that this account cannot log into the system. To do this, use the utility vipw if necessary and change www's default shell from /bin/sh or whatever to /sbin/nologin.


    1. Configuring Apache

    The next step is to configure the Apache Web Server. To do this, follow the steps in sequence.

  • cd /usr/local/etc/httpd
  • cp httpd.conf httpd.conf.bak
    This backs up the old file, in case you screw things up.
  • Open httpd.conf with your favourite text editor and edit the config files to your requirements. The httpd.conf file is pretty well commented, so it is not too hard to figure out what the various options do. If you want an example, the author's httpd.conf file looks something like this:
    ServerType standalone
    ServerRoot "/usr/local"

    Timeout 30
    KeepAlive Off
    MaxKeepAliveRequests 100
    KeepAliveTimeout 15

    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    MaxClients 150
    MaxRequestsPerChild 0

    ResourceConfig /dev/null
    AccessConfig /dev/null

    Port 80
    User www
    Group www

    ServerAdmin webmaster@yourdomain.com
    ServerName yourwebserver
    DocumentRoot "/var/www/htdocs"

    <Directory />
    Options FollowSymLinks
    AllowOverride None

    DirectoryIndex index.php
    UseCanonicalName On

    HostnameLookups Off
    PidFile /var/run/httpd.pid
    ScoreBoardFile /var/log/httpd.scoreboard

    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    CustomLog /var/log/access_log common
    ErrorLog /var/log/error_log

    ServerSignature Off

    AddType application/x-httpd-php php php3
    #AddHandler imap-file map
    #AddHandler cgi-script pl

    ErrorDocument 403 /error.php
    ErrorDocument 404 /error.php
    ErrorDocument 500 /error.php

    #mod_gzip directives
    mod_gzip_on yes
    mod_gzip_dechunk yes
    mod_gzip_keep_workfiles no
    # File types that mod_gzip should work on.
    # Add more file types as needed.
    mod_gzip_item_include file \.htm$
    mod_gzip_item_include file \.html$
    mod_gzip_item_include mime text/.*
    # Directory for mod_gzip to do its work in
    mod_gzip_temp_dir /var/tmp


    # Domain 1
    ServerAdmin webmaster@yourdomain.com
    DocumentRoot "/var/www/htdocs"
    ServerName yourdomain.com
    ServerAlias *.yourdomain.com
    ErrorLog /var/log/yourdomain.com-error_log

    # Domain 2
    DocumentRoot "/var/www/apache-install"
    DirectoryIndex mainpage.php
    ErrorDocument 404 /404page.php
    ErrorDocument 403 /404page.php
    ServerName www.mayukhbose.com

    Note that if you use the above example, you'll need to adjust the parameters for your own configuration. Pay particular attention to the places that are coloured like this -- you may need to change those values for your setup. The code above is for two domains that are set up on a single IP address. Note the IP address set up in NameVirtualHosts and VirtualHost directives is You should change this to your own IP address, or better yet, change it to * (i.e. NameVirtualHost * and <VirtualHost *> ) for all your IP addresses. You can adjust the other parameters as well, such as the logging options, log formats, MinSpareServers etc. to your own requirements. Feel free to experiment!

  • The next step is to stop and start the apache server. To do this, type:

    rehash Only type this, if you're using tcsh or a similar shell.
    apachectl stop
    apachectl start

    Every time you make changes to httpd.conf, you'll need to stop and start the apache server for the changes to take effect.

  • TOP

    2. Removing Junk Files

    This is an optional step, but the author usually does it anyway, just to reduce the number of files in the default document directory (/var/www/htdocs/). There are a large number of files installed by default in this directory, which are all in different languages. The author usually removes all of them except for index.html.

    The author also removes all the files in /usr/local/etc/httpd/ except for httpd.conf, magic and mime.types. You can do this also, if you wish.

    The author also normally empties out the default icons directory (/var/www/icons) as he normally has no use for all these icons.


    3. Testing

    The following instructions assume that you've actually created the home directories for the domains and put files in there. For example, in httpd.conf, I've specified that the base directory for yourdomain.com is /var/www/htdocs and that the default document (specified by the DirectoryIndex directive above) is index.html. For the www.mayukhbose.com domain, I've overridden some default values (the 403, 404 and default documents) and also specified a different base directory. Make sure that you have files in the proper locations as per your own settings. All you have to do is:
  • Make sure apache is running (you did this at the end of step 1.)
  • Use a web browser to hit your domain. If you see the page come up then you've done it all correctly! Congratulations!!!

  • TOP

    <<Previous: Installation ^Up to Mayukh's World^ Next: Credits N Stuff >>

    Apache Installation Walkthrough
    Last updated 08/01/2003