It might be useful to back up to the basics before fiddling with virtual hosts (if the basics don't work, neither will the virtual).
In
/etc/httpd/httpd.conf you should have things like this:
Code:
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
#Listen 80
Listen 192.168.1.10:80
That is, listen on the fixed-IP address of "this" system; otherwise, that address would be your assigned address (such as 12.34.56.78:80). Note that, as shown here, this server is listening on a LAN. With the addition of, say,
DynDNS (see
http://www.dyndns.com/) the outside world can get to this server via the modem and router, useful if your ISP changes your IP address periodically.
Code:
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache
That's kind of a standard for a Slackware installation and assigning user apache and group apache (the default) is a good idea.
Code:
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin you@where.what
Code:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName fubar.com:80
If you have a registered DNS name, use that (the
www.example.com:80 address). If you're running on a LAN, don't include the
www. Keep in mind that you can't simply make up an IP address -- use 192.168.x.x for your LAN, that's what those addresses are for.
Code:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Adding
index.php lets things happen as you'd like them to; if your web page is named
index.php, Apache will open it with this addition.
Code:
# Uncomment the following line to enable PHP:
#
Include /etc/httpd/mod_php.conf
If you don't, it ain't: you need to include the configuration file (and you really don't need to fiddle with it in
most cases). Like many things, if it works it's probably better to leave it alone unless you have a really good reason to change it (and that takes some study of the documentation).
You may also want to permit access in user home directories (so you can fiddle with a web page in you home directory rather than in the system directory):
Code:
# User home directories
Include /etc/httpd/extra/httpd-userdir.conf
You would create an
public_html directory in your home directory then address it in the browser with
http://fubar.com/~your_user_name (here,
fubar.com is simply an example). The name of the directory must be
public_html, put
phpinfo.php in that directory and see it with
http://fubar.com/~your_user_name/phpinfo.php. You can do all your development work essentially off-line in your home directory before moving your page to the system directory; kinda handy, that. You probably already know that the default location for the web page is
/var/www/htdocs/index.html.
Note that all of the above are found in
/etc/httpd.conf on a standard Slackware installation -- just edit your name and address information.
With the above configuration edits -- and sending the browser to the machine name/address, not to
localhost -- PHP should do its thing for you.
Something you can do is add an entry in
/etc/hosts of the form
Code:
# For loopbacking.
127.0.0.1 localhost
192.168.1.10 fubar.com fubar
so you can easily refer to the system by name (this is fixed-IP, DHCP is, of course, different). Other servers on your LAN should have similar entries in their
/etc/hosts files so they can quickly and easily get to this system web page; the URL would be, in this case,
http://fubar.com (or the IP address).
If you're placing web-based software in
/var/www/htdocs you will need to do a couple of things with group assignment and permission masks.
For example, I have
Bugzilla installed for user and developer bug reporting and tracking.
/var/www/htdocs is owned and group root,
/var/www/htdocs/bugzilla is
Code:
drwxr-x--- 16 root apache 4096 May 17 2011 bugzilla/
The entire content of the
bugzilla directory is owner root and group
apache.
I have other web applications that are similarly owner root, group apache.
So Apache will server Bugzilla (and one other application), I add these lines to
/etc/httpd.conf:
Code:
# Uncomment the following line to enable Bugzilla
Include /etc/httpd/extra/httpd-bugzilla.conf
# Uncomment the following line to enable colplot
Include /etc/httpd/extra/httpd-colplot.conf
And this to
/etc/httpd/extra/httpd-bugzilla.conf:
Code:
cat /etc/httpd/extra/httpd-bugzilla.conf
# Bugzilla
<Directory "/srv/httpd/htdocs/bugzilla">
AddHandler cgi-script .cgi
Options +Indexes +ExecCGI
DirectoryIndex index.cgi
AllowOverride Limit
</Directory>
The other application,
colpat, looks like this
Code:
cat /etc/httpd/extra/httpd-colplot.conf
# The following stanza enables colplot
<Directory "/srv/httpd/htdocs/colplot">
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
AllowOverride None
Options None
Options +followsymlinks +execcgi
Order allow,deny
Allow from all
</Directory>
It's handy that you don't need to directly edit
/etc/httpd/httpd.conf to add additional applications (at least in Slackware) with the addition of the
extra directory -- there are some useful things found there that you may be interested in.
And, of course, if you make any changes you must stop and restart the
httpd daemon:
Code:
/etc/rc.d/rc.httpd stop
/etc/rc.d/rc.httpd start
You can also use
/etc/rc.d/rc.httpd restart.
One other thing -- if you've been whacking away for some time it might be a good idea to clear the browser cache when you've made changes to make sure you get the current change. Won't hurt, might help.
Once you see the PHP display, you're good to go and
then you can fiddle with the virtual stuff.
Hope this helps some.