How to set up a Virtual Host in Apache on FreeBSD

To configure Virtual Hosts on Apache web server under FreeBSD you first need to create a folder where your websites data will store:

mkdir -p /data/www/

Here we create a directory for our site and 3 more directories:

cd /data/www/
mkdir {htdocs,log,tmp}

htdocs directory is your main website directory;
log directory contains logs;
tmp directory is for temporary files. Chown them for www user

Now we proceed to creating Virtual Hosts. Change directory:

cd /usr/local/etc/apache22/

Create two more directories:

mkdir -p sites-available
mkdir -p sites-enabled
sites-available directory is for all available Virtual Hosts;
sites-enabled is for hosts enabled by web server.

In sites-available directory we create our Virtual Host

#Virtual Hosts
NameVirtualHost *:80

#VirtualHost example:
#Almost any Apache directive may go into a VirtualHost container.
#The first VirtualHost section is used for all requests that do not
#match a ServerName or ServerAlias in any block.
<VirtualHost *:80>
DocumentRoot "/data/www/"
ServerAlias *
ErrorLog "/data/www/"
CustomLog "/data/www/" common
php_admin_value open_basedir "/data/www/"
php_admin_value upload_tmp_dir "/data/www/"
php_admin_value session.save_path "/data/www/"
AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
AddType application/x-httpd-php-source .phps
<Directory "/data/www/">
AllowOverride All
DirectoryIndex index.php index.html index.htm
Order Allow,Deny
Allow from All

Add to the end of http.conf file:

Include etc/apache22/sites-enabled/*.conf
Include etc/apache22/sites-other/*

Enable Virtual Host:

cd /usr/local/etc/apache22/
ln -s sites-available/ sites-enabled/

Restart Apache:

/usr/local/etc/rc.d/apache22 forcerestart

  1. 2015-08-25 18:19:57
    You spelt 'available' incorrectly here:
    mkdir -p sites-avaliable
    Should be:
    mkdir -p sites-available
  1. Sergey
    2015-08-25 18:21:44
    Thanks, fixed

Got a comment?

captcha =


  1. System (20)
    1. FreeBSD (5)
    2. Linux (9)
  2. Email (2)
  3. DNS (2)
  4. Databases (1)
  5. WebServer (27)
Copyright © 2012-2015 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.