1. Skip to Menu
  2. Skip to Content
  3. Skip to Footer>
Thursday May 2nd     1:28 PM PDT                                  

Apache Part 3 - Vhost and first website

Written by Greg King Friday, 27 November 2009 00:00

The Apache Webserver is one of the most popular applications being run under the FreeBSD operating system. Setting it up is not to complicated.  Getting it to work the way you want it to work can be a trick though as this software package is very configurable and the documentation does not always have the novice administrator in mind.


In part 1, we installed and did basic configuration of the Apache Web Server v2.2.x.   In Part 2, we learned about  vhosts.  In this article, we will set up 2 basic websites and put http authentication on one of them.
NOTE:The directory structure seems to change from release to release, so some research may be necessary to completely configure the system inspite of this documentation. In our example, our freebsd system is server.ourdomain.com.  Our IP is 192.168.1.100. Our new website will be called www.ourdomain.com which we should have configured in the dns how-to.
 

In the last section, we learned more about the Virtual Host entry.  Earlier, when we set up dns, we set up a website address for www and www2.ourdomain.com.  We will use both of them now.  First, we want to create a simple web site.  

Open the config file for edit:

# nano /usr/local/etc/apache22/extra/httpd-vhosts.conf

copy and paste the following into that file, then edit for your site. Note: the This e-mail address is being protected from spambots. You need JavaScript enabled to view it should be on the same line as the ServerAdmin line.  

<VirtualHost *:80>
<Directory /home/my_login_name/www/>
Order allow,deny
allow from all
</Directory>
ServerAdmin This e-mail address is being protected from spambots. You need JavaScript enabled to view it

DocumentRoot /home/my_login_name/www/
ServerName www.ourdomain.com
ServerAlias ourdomain.com
CustomLog /var/log/ourdomain-access.log common
ErrorLog /var/log/ourdomain-error.log
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</VirtualHost>

Now, go to the home directory you specified above.

# cd /home/my_login_name

make the www directory

# mkdir www

set it readable and executable to the world (needed because the webserver runs as user 'www'.

# chmod 755 www

 go into that directory

# cd www

create a simple website to test everything and make sure php and mysql are working through apache's webserver.  To do this, open the index file...

# nano index.php

and paste the following into it and save it afterwards:

<?php phpinfo(); ?>

restart apache so it will re-read it's configuration file and pick up our new vhost:

# apachectl -k restart 

Now if you point your webbrowser to the http://www.ourdomain.com, you should see a display for php.  Scan down and make sure it shows that the mysql module is installed (the modules are shown in alphabetical order).   Assuming everything went well, you have created a vhost and have a website attached to it.

If the php page did not display, or if the mysql block did not show in the php page, you didn't compile/configure php correctly so you will have to revisit that section.

This concludes our FreeBSD FAMP setup guide.  We invite you to visit other sections on our site to learn more about configuring the kernel and other post installation items.

  FreeBSD Configuration
eXTReMe Tracker
Content View Hits : 404991