The open source Apache HTTP Server is the most widely used web server. FreeBSD does not install this web server by default, but it can be installed from the www/apache24 package or port.
This section summarizes how to configure and start version
x of the Apache HTTP
Server on FreeBSD. For more detailed information
about Apache2.X and its
configuration directives, refer to httpd.apache.org.
In FreeBSD, the main Apache HTTP
Server configuration file is installed as
x represents the version
number. This ASCII text file begins
comment lines with a
#. The most
frequently modified directives are:
Specifies the default directory hierarchy for the Apache installation. Binaries are stored in the
sbinsubdirectories of the server root and configuration files are stored in the
Change this to the email address to receive problems with the server. This address also appears on some server-generated pages, such as error documents.
Allows an administrator to set a hostname which is sent back to clients for the server. For example,
wwwcan be used instead of the actual hostname. If the system does not have a registered DNS name, enter its IP address instead. If the server will listen on an alternate report, change
80to the alternate port number.
The directory where documents will be served from. By default, all requests are taken from this directory, but symbolic links and aliases may be used to point to other locations.
It is always a good idea to make a backup copy of the
default Apache configuration file
before making changes. When the configuration of
Apache is complete, save the file
and verify the configuration using
configtest should return
To launch Apache at system
startup, add the following line to
If Apache should be started
with non-default options, the following line may be added to
/etc/rc.conf to specify the needed
If apachectl does not report
configuration errors, start
httpd service can be tested by
in a web browser, replacing
localhost with the fully-qualified
domain name of the machine running
The default web page that is displayed is
The Apache configuration can be
tested for errors after making subsequent configuration
httpd is running using the
It is important to note that
configtest is not an rc(8) standard,
and should not be expected to work for all startup
Virtual hosting allows multiple websites to run on one Apache server. The virtual hosts can be IP-based or name-based. IP-based virtual hosting uses a different IP address for each website. Name-based virtual hosting uses the clients HTTP/1.1 headers to figure out the hostname, which allows the websites to share the same IP address.
To setup Apache to use
name-based virtual hosting, add a
VirtualHost block for each website. For
example, for the webserver named
www.domain.tld with a
virtual domain of
add the following entries to
<VirtualHost *> ServerName
/www/domain.tld</VirtualHost> <VirtualHost *> ServerName
For each virtual host, replace the values for
DocumentRoot with the values to be
For more information about setting up virtual hosts,
consult the official Apache
Apache uses modules to augment
the functionality provided by the basic server. Refer to
for a complete listing of and the configuration details for
the available modules.
In FreeBSD, some modules can be compiled with the
www/apache24 port. Type
/usr/ports/www/apache24 to see which
modules are available and which are enabled by default. If
the module is not compiled with the port, the FreeBSD Ports
Collection provides an easy way to install many modules. This
section describes three of the most commonly used
mod_ssl module uses the
OpenSSL library to provide strong
cryptography via the Secure Sockets Layer
(SSLv3) and Transport Layer Security
(TLSv1) protocols. This module provides
everything necessary to request a signed certificate from a
trusted certificate signing authority to run a secure web
server on FreeBSD.
mod_ssl module is enabled
by default in both the package and the port. The available
configuration directives are explained at
mod_perl module makes it possible to
write Apache modules in
Perl. In addition, the
persistent interpreter embedded in the server avoids the
overhead of starting an external interpreter and the penalty
of Perl start-up time.
PHP: Hypertext Preprocessor (PHP) is a general-purpose scripting language that is especially suited for web development. Capable of being embedded into HTML, its syntax draws upon C, Java™, and Perl with the intention of allowing web developers to write dynamically generated webpages quickly.
To gain support for PHP5 for the
Apache web server, install the
www/mod_php56 package or port. This will
install and configure the modules required to support
dynamic PHP applications. The
installation will automatically add this line to
LoadModule php5_module libexec/apache24/libphp5.so
Then, perform a graceful restart to load the PHP module:
Alternatively, individual extensions can be installed using the appropriate port. For instance, to add PHP support for the MySQL database server, install databases/php56-mysql.
After installing an extension, the Apache server must be reloaded to pick up the new configuration changes:
In addition to mod_perl and mod_php, other languages are available for creating dynamic web content. These include Django and Ruby on Rails.
Django is a BSD-licensed framework designed to allow developers to write high performance, elegant web applications quickly. It provides an object-relational mapper so that data types are developed as Python objects. A rich dynamic database-access API is provided for those objects without the developer ever having to write SQL. It also provides an extensible template system so that the logic of the application is separated from the HTML presentation.
Django depends on
an SQL database engine. In FreeBSD, the
www/py-django port automatically installs
mod_python and supports the
SQLite databases, with the
default being SQLite. To change
the database engine, type
install the port.
Once Django is installed, the application will need a project directory along with the Apache configuration in order to use the embedded Python interpreter. This interpreter is used to call the application for specific URLs on the site.
To configure Apache to pass
requests for certain URLs to the web
application, add the following to
httpd.conf, specifying the full path to
the project directory:
<Location "/"> SetHandler python-program PythonPath "['
/dir/to/the/django/packages/'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonAutoReload On PythonDebug On </Location>
for more information on how to use
Ruby on Rails is another open source web framework that provides a full development stack. It is optimized to make web developers more productive and capable of writing powerful applications quickly. On FreeBSD, it can be installed using the www/rubygem-rails package or port.
for more information on how to use Ruby on