FreeBSD Install and Configure Apache Web Server

Q. How do I install and configure Apache web server under FreeBSD 7.x operating systems?

ADVERTISEMENTS

A. FreeBSD comes with various versions of Apache web servers:

=> Apache 1.3
=> Apache 2.0
=> Apache 2.1
=> Apache 2.2

Step # 1: Update FreeBSD ports collection

Type the following command to update FreeBSD ports collection:
# portsnap fetch update

Step # 2: Install Apache Web Server

Type the following commands:
# cd /usr/ports/www/apache22/
# make install clean

Select required options:

Fig.01: FreeBSD Apache v2.2 Config Options

Fig.01: FreeBSD Apache v2.2 Config Options

Step 3: FreeBSD Configure Apache

Quick facts about Apache version 2.2 under FreeBSD:

  1. Default HTTP port: 80
  2. Default HTTPS (SSL) port: 443
  3. Default DocumentRoot directory: /usr/local/www/apache22/data/
  4. Default cgi-bin directory: /usr/local/www/apache22/cgi-bin/
  5. Default Error Log File: /var/log/httpd-error.log
  6. Default Access Log File: /var/log/httpd-access.log
  7. Default suexec log (if compiled with suexec): /var/log/httpd-suexec.log
  8. Default configuration file directory:/usr/local/etc/apache22/ and /usr/local/etc/apache22/extra/
  9. Default configuration file: /usr/local/etc/apache22/httpd.conf

Turn on Apache service

Type the following command to turn on Apache22 service:
echo 'apache22_enable="YES"' >> /etc/rc.conf

Configure httpd.conf

Open httpd.conf file:
# cp /usr/local/etc/apache22/httpd.conf /root/httpd.conf.bak
# vi /usr/local/etc/apache22/httpd.conf

Bind Apache to specific IP addresses and/or ports, instead of the default. Let us bind to IP address called 202.4.2.1 and port 80:
Listen 202.4.2.1:80
Set your email address:
ServerAdmin vivek@nixcraft.com
Set servername (FQDN) such as www.nixcraft.com:
ServerName www.nixcraft.com
Save and close the file.

Start Apache server

To start Apache server v2.2, enter:
# /usr/local/etc/rc.d/apache22 start
Verify that port 80 is opened:
# sockstat -4 | grep :80

Open port 80 using PF firewall

WARNING! These examples may block access to your computer if not executed properly. If you are configuring FreeBSD and Apache first time, I strongly recommend skipping this step.

PF is OpenBSD firewall and available under FreeBSD. You need to configure pf using /etc/pf.conf file. Add following line to your /etc/pf.conf file:
pass in on $ext_if proto tcp from any to 202.4.2.1 port 80 flags S/SA synproxy state
Save and close the file. Reload pf firewall:
# /etc/rc.d/pf reload

Test your new setup

Fire a webbrowser and type your domain name such as www.nixcraft.com.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
7 comments… add one
  • grinder Feb 1, 2009 @ 14:35

    Thanks for manual. It look very easy.

  • opik Jan 3, 2010 @ 2:39

    apachectl couldn’t start and port 80 isn’t opened, i’am not using or installed any firewall. how to open port 80 and running apache ?
    thanks.

  • Fil Delmonte Jul 5, 2011 @ 3:56

    It Works!

  • Robert Dailey Oct 21, 2011 @ 21:56

    Please correctly use provided utilities:

    sockstat -4lp 80
    • Gustavo Jul 30, 2013 @ 12:04

      # sockstat -4lp 80
      USER COMMAND PID FD PROTO LOCAL ADDRESS FOREING ADDRESS

      • Robert Dailey Aug 20, 2013 @ 17:56

        Then you don’t have a web server listening on ipv4 port 80. As you can see below, I have a web server listening on ipv4 port 80 as well as ipv6 port 80.

        [root@midas ~]# sockstat -4lp 80
        USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
        www httpd 94026 3 tcp46 *:80 *:*
        www httpd 93984 3 tcp46 *:80 *:*
        www httpd 93979 3 tcp46 *:80 *:*
        www httpd 93978 3 tcp46 *:80 *:*
        www httpd 93974 3 tcp46 *:80 *:*
        www httpd 93960 3 tcp46 *:80 *:*
        www httpd 93959 3 tcp46 *:80 *:*
        www httpd 93944 3 tcp46 *:80 *:*
        www httpd 93942 3 tcp46 *:80 *:*
        www httpd 92633 3 tcp46 *:80 *:*
        root httpd 1856 3 tcp46 *:80 *:*
        [root@midas ~]#

  • Sundeep Mar 17, 2013 @ 13:10

    Hi,
    Would it be a good idea to change the below directories
    Default DocumentRoot directory: /usr/local/www/apache22/data/
    Default cgi-bin directory: /usr/local/www/apache22/cgi-bin/

    to my own directory or partition

    or would it be good to make symlink –

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.