Posted in PHP, Apache, FreeBSD/Unix服务器 at 13:15 Author:仲远



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


# ——————————————————————- #
# example.com
# ——————————————————————- #

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

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.

转载自仲子说 [ http://www.wangzhongyuan.com/ ]

Leave a Comment

To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word