By now, I'm sure you're chompin' at the bit to get that webserver working. It's so easy to do that you really only need to worry about what you are gonna put on your website. I'm gonna start with the assumption that you already set up your account at http://dyndns.org. If you haven't, you really should go back and do that now. What good is a web site that no one can see?
First, we need to check and see if you already have your web server running. Open up a browser, and in the address bar type:
http://localhost
If you're too lazy to type that in, feel free to use this link: http://localhost. If your web server is already running, you should see an Apache screen saying:
If you didn't see that, you need to start your web server. Type:
apachectl start
If Apache wasn't running, you'll also want to get it to start up at boot in the future, so type:
chmod +x /etc/rc.d/rc.httpd
Now that everyone has Apache running and set to run at boot time, we need to learn a little about it and configure it to our liking. The first thing to note is that the files that are getting served up are located in /var/www/htdocs . You can add files and directories all day to /var/www/htdocs , but you'll want to be careful about permissions. All of the files need to at least be world readable.
The only other thing left to do, before you start autoring all of your super-cool webpages, is to configure Apache, The configuration file is located at /etc/apache/httpd.conf. Go ahead and open that up in your favorite text editor. The first section we're gonna change looks like this:
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents.
#
ServerAdmin SomeUser@WhateverItUsedToSayHere.com
And we are gonna make it look like this:
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents.
#
ServerAdmin root@username.dyndns.org
Now remember, I only chose root@username.dyndns.org because that is the example host and domain that I used in the section on getting a net presence. You will need to adjust that line for yourself accordingly.
Next, we are going to find the section that looks like this:
# 127.0.0.1 is the TCP/IP local loop-back address, often named localhost. Your
# machine always knows itself by this address. If you use Apache strictly for
# local testing and development, you may use 127.0.0.1 as the server name.
#
#ServerName midas.slackware.lan
And we're gonna make it look like this:
# 127.0.0.1 is the TCP/IP local loop-back address, often named localhost. Your
# machine always knows itself by this address. If you use Apache strictly for
# local testing and development, you may use 127.0.0.1 as the server name.
#
ServerName username.dyndns.org
Now sometimes your web pages are gonna end with .htm or .html. Other times, you may want to use web pages that end in .php. Trust me on this. So next up, we're gonna find a section that looks like this:
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
DirectoryIndex index.html index.htm
</IfModule>
And we're gonna make it look like this:
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
DirectoryIndex index.html index.htm index.shtml index.shtm index.php
</IfModule>
Later, we're gonna learn about logging access to our new web server. For right now, it's safe to say we'd like to know who is viewing our website. What we're gonna do to help us out with that is find a section that looks like this:
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
And we're gonna make it look like this:
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups On
Following along the same lines, we probably would like to know a little bit about the people surfing our little slice of the internet. We are gonna find a section that looks like this:
# If you prefer a single logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog /var/log/apache/access_log combined
And we're gonna make it look like this:
# If you prefer a single logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
CustomLog /var/log/apache/access_log combined
Next up is a little security measure. It really is little, since it won't really help too much against anyone but the clueless. We are gonna tell Apache not to identify itself so easily. I'm not 100% sure that this is helpful, but it's what I do. Find a section that looks like this:
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (error documents, FTP directory listings,
# mod_status and mod_info output etc., but not CGI generated documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature On
And we're gonna make it look like this:
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (error documents, FTP directory listings,
# mod_status and mod_info output etc., but not CGI generated documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
ServerSignature Off
The last thing that we are going to do is allow are web server to run php scripts. Why? I like this little program called squirrelmail. It uses php. This is something I had to do to get it to work. Find a section that looks like this:
# ==> mod_php configuration settings <==
#
# PACKAGES REQUIRED: openssl-solibs (A series) and/or openssl (N series),
# mysql (AP series), gmp (L series), and apache (N series)
#
#Include /etc/apache/mod_php.conf
And we're gonna make it look like this:
# ==> mod_php configuration settings <==
#
# PACKAGES REQUIRED: openssl-solibs (A series) and/or openssl (N series),
# mysql (AP series), gmp (L series), and apache (N series)
#
Include /etc/apache/mod_php.conf
That wraps up the configuration in the /etc/apache/httpd.conf file. We still have one more step to do (At least I did before things started working). You need to open up the file named /etc/apache/mod_php.conf. Here's what mine used to look like:
#
# mod_php - PHP Hypertext Preprocessor module
#
# Load the PHP module:
LoadModule php4_module libexec/apache/libphp4.so
# Tell Apache to feed all *.php files through the PHP module:
AddType application/x-httpd-php .php
# This will display PHP files in colored syntax form. Use with caution.
#AddType application/x-httpd-php-source .phps
This didn't work for me. I had to change mine to look like this:
#
# mod_php - PHP Hypertext Preprocessor module
#
#LoadModule php4_module libexec/libphp4.so
LoadModule php4_module libexec/apache/libphp4.so
#AddModule mod_php4.c
# Tell Apache to feed all *.php files through the PHP module
AddType application/x-httpd-php .php
# This will display PHP files in colored syntax form. Use with caution.
#AddType application/x-httpd-php-source .phps
Now, we're gonna restart our web server and check for any error messages. Type:
/etc/rc.d/rc.httpd restart
And look for any error messages. I don't get any, so it looks like we're good to go.
Now your web server should be running smoothly. We'd like to check on our php, though, to make sure it is running like it should. We are gonna make a file with our favorite text editor and call it /var/www/htdocs/info.php . In your new file, type:
<?php
phpinfo();
?>
Save your file. Now, fire up you web browser and type in:
http://localhost/info.php
If you're lazy, just use this link: http://localhost/info.php. You should see a pretty screen with all kinds of information about your web server. What you should not see is a blank window or a window with three lines of code. All set? Great. You might want to delete that info.php file from your sever at this point. No need advertising your setup to the whole world. Now you've just gotta come up with some web pages to serve! I'll have to help you out with that in the future.