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

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: 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

Comments

Saturday, May 13, 2006 / 12:18pm anonymous coward said…

What about DNS? Totally left out, yet you can't have a site without it!

Saturday, May 13, 2006 / 12:39pm Greg said…

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.

Saturday, May 13, 2006 / 6:06pm Robert Mohns said…

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.

Sunday, May 14, 2006 / 1:31am zean said…

thanks you Dave. I have build Apache, mysql and php from Ports, but this is a excellent Article.

Tuesday, May 1, 2007 / 3:21pm Josh said…

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.

Meet The Author

Dave Tufts

Vice President, Director of Technology

Search

Recent Blog Posts

Recent Comments

  • A better tool

    Dave Tufts commented: Just downloaded Soulver - it's great. I also like using the search box in my browser or Google. Similar, linear layout to Soulver. (for the record, that giant calculator on my desk looked like a small regular-sized calculator in the picture on Amazon)

  • Lunchroom Banter (Volume XX)

    Nick commented: Since Bill didn't do it, I will. "Oh snap!"

  • iMarcians with staying power

    Nick commented: Congratulations on the anniversaries. I had a professor tell me early on at the Art Institute that "you can expect to change web jobs every 2-3 years until you settle somewhere". I love proving this guy wrong every day. Congrats again.

  • Twitter, Alone, Is Not Customer Service

    Jay G commented: Same here, and my story is with Alaska Air, too. Their website said the customer service phone number was open something like 8am-8pm PST, but this was after hours, so I tweeted. Lo, and behold, I got a tweet response in 10 minutes with the 24/7 phone number. But this didn't change the confusion from their website…

  • Mobile browsers: Here's the data

    Robert Mohns commented: The data comes from visitors to iMarc.net — an important detail I forgot to include! — not the web as a whole. As for why so little Flash on mobile devices… I'd say this is because even Flash Lite is pretty resource intensive, and it's just not essential to the core content most people need to access. I don't think it has a lot to do…

We heart Visitors

  • iMarc
  • 14 Inn Street
  • Newburyport, MA 01950
  • Phone: (978) 462-8848
  • Fax: (978) 462-8807
  • Directions

Contact Us

Whether you have a huge project specification or just want to talk about updating your site, we’re here to help. Fill out the form, and we’ll get right back to you.

Contact Us
  • All Fields Required

Close