iMarc | Interactive Media Architects
  • Portfolio
  • Process
  • About
  • Communiqué
  • Contact
  • Support
  • Search

Run Your Own Unix Web Server (part 3 of 3)

by Dave Tufts - May 12, 2006 / 10:49am View more articles

Part 3 of 3 / Configuration

I know it's been a while since Part 1 and Part 2 of this series. Sorry for the long delay. I imagine thousands, if not millions, of inquisitive geeks out there with their FreeBSD servers ready to go. Apache, PHP, and MySQL are installed, and they're just waiting, reloading the iMarc blog every couple hour, wondering..."Now What?"

Well the wait is over, my furry little geek friends. Cancel your World of Warcraft membership and do what real men do - run a UNIX web server.

In this lesson, we configure Apache and serve up a PHP page.

This document assumes:
  • FreeBSD is installed, and you followed the instructions from part 1 of this series
  • Apache 2.x and PHP 5.x are installed, and you followed the instructions from part 2 of this series.
This document also assumes that:
  • at least one domain name points to your server
    The one I'm using is example.com. Replace that with your domain in the references below.
  • your server has at least one static IP address
    The one I'm using is 10.20.111.2. Again, replace my example IP with your real IP below.
Let's go...I promise this will be quick.

Make a home for your website


SSH to your server as the user 'web' and create the website root directory:
mkdir ~/www/example.com

Make a homepage for your site


You can later go back and upload a better site, but for now, we'll just make a quick PHP-driven index page in the website root directory.

Use vi to create and open the index file:
vi ~/www/example.com/index.php
Add the following content:
<?php for ($i = 0; $i < 10; ++$i) { echo "I'm a new website
"; } ?>
Save and quit vi. Good. We have a web directory and a home page.

Edit Apache's configuration file


We need to tell Apache where the new site is. I prefer using name-based Virtual Hosts

Use vi to create and open Apache's config file, called httpd.conf:
vi ~/apache/conf/httpd.conf
Scroll to the bottom and add the following. (Remember, replace my example domain and IP with your real ones)
NameVirtualHost 10.20.111.2:80 # ------------------------------------------------------------------- # # example.com # ------------------------------------------------------------------- # <VirtualHost 10.20.111.2:80> DocumentRoot /home/www/example.com ServerName www.example.com CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/example.com.log 604800" combined DirectoryIndex index.php index.html index.htm <VirtualHost 10.20.111.2:80> ServerName example.com Redirect / http://www.example.com/

Start Apache


Starting and stopping apache requires SuperUser (root) privileges, so type su, and enter root's password.

In case the web server was already running, we'll try and stop it first. If you get an error about apache not running, don't worry...
apachectl stop
Before starting or restarting Apache, I test any configuration edit's I've made.
apachectl configtest
You should get, Syntax OK.

Finally, start the server:
apachectl start
In the future, after making Apache configuration changes, restart the server like this:
apachectl configtest apachectl graceful
That gracefully stops the server, re-reads the configuration, and starts up again.

Launch Party


Open up your favorite browser and go to the site!

If it worked, pour the Andre Cold Duck, submit your site to Google, jump out of the nest, and flap your wings. You're on your own now!

See Also
Run Your Own Unix Web Server (part 1 of 3) - FreeBSD Installation
Run Your Own Unix Web Server (part 2 of 3) - Software
Run Your Own Unix Web Server (part 3 of 3) - Configuration
More Articles Get the RSS Feed Post A Comment

5 Comments

by anonymous coward   #
on May 13, 2006 / 12:18pm
What about DNS? Totally left out, yet you can't have a site without it!
by Greg   #
on May 13, 2006 / 12:39pm
Your mileage may vary, of course, but for DNS I use djbdns, which is in the ports tree. Anyone who's suffered the slings and arrows of learning how to use BIND will find djbdns a lot easier to use.It's actually two programs - one is a caching DNS server and the other is the BIND-y DNS server. Personally, I only use it as a backup and instead rely on a third party like easydns.com for my DNS services... if your box goes down for a little while, you don't necessarily want your authoritative nameserver to go down with it.
by Robert Mohns   #
on May 13, 2006 / 6:06pm
I concur with Greg about using an external DNS service -- ideally, you want at least two DNS servers, widely separated geographically and in network topology, to ensure at least one is available at all times. This also facilitates having backup MX records so if your primary mail server goes down, another server (perhaps run by a friend) can store the mail until your mail server becomes available again.
by zean   #
on May 14, 2006 / 1:31am
thanks you Dave. I have build Apache, mysql and php from Ports, but this is a excellent Article.
by Josh   #
on May 1, 2007 / 3:21pm
Great tutorial. This is definitely the most concise process I have come across, for getting a Unix web server up and running. Thanks a lot, Dave.

Comments have been turned off on this blog.
Read something more recent.

Statements and opinions expressed in this blog and any comments made are the private opinions of the respective poster, and, as such, iMarc LLC is neither responsible nor liable for such content.

iMarc

iMarc is a web development company in Newburyport, MA. This is our blog.
View all blogs or learn more about iMarc.

About the Author

Dave's Head Dave Tufts, Vice President of Technology
I help people build websites.
I have two daughters.
I'd rather be gardening.
More blogs by Dave

Search Our Blog

Recent Communiqués

  • Inc. 5000
  • Say Hello to our new Sys Admin
  • "Not Invented Here" for a Triple Word Score
  • ca·coph·o·ny
  • Clank
  • Year in Quotes (volume 2)
  • Gunslinging Rockstar Ninjas
  • Now Hiring: Junior Interactive/Web Designer
  • Photoshop: Create Your Own Glossy Icons
  • They only come out at night
  • Context switches are expensive
  • <i> is not evil.
  • Schooled.
  • Full-screen branding
  • Summer Job, iMarc Style

Popular Communiqués

  • Now Hiring: Junior Interactive/Web Designer
  • Photoshop: Create Your Own Glossy Icons
  • Say Hello to our new Sys Admin
  • "Not Invented Here" for a Triple Word Score
  • ca·coph·o·ny
  • Custom Away Messages are Overrated
  • Schooled.
  • Summer Job, iMarc Style
  • Year in Quotes (volume 2)

Recent Comments

  • Inc. 5000

    By Nick: Congrats.

  • Inc. 5000

    By Craig Henry: WOOWOOOO

  • Inc. 5000

    By Jeff Turcotte: wow!!

  • Photoshop: Create Your Own Glossy Icons

    By nicole: thats cool ,but can u make it a little easyer . =/…

  • Say Hello to our new Sys Admin

    By Nick: 14 days and no love. Congrats Mike.

RSS

RSS Icon Learn about RSS and get the feed for our blog.

About iMarc

  • We build custom web sites
  • In-house strategy, design, programming, hosting
  • In business since 1997
  • We’re located in Newburyport, MA
  • Call us at (978) 462-8848

© 2008 iMarc LLC, Contact Us

Links

  • Home
  • Portfolio
  • Client Support
  • Log In
  • (icon)RSS

Meet the Team

Mike's Head Mike Denning, Systems Administrator

systems and network guy.

Learn More | Meet the Others