Apache Web Server Information
Since the beginning of 1996 (at least), Apache
has been the web server of choice for the planet. It has enjoyed as high as 80% of the market share
for publicly accessible webservers.
Note: This area is for Apache version 2. (AKA: Apache2)
Let's start by installing apache2 on an Ubuntu machine. In a terminal type:
sudo apt-get install apache2-mpm-prefork apache2-doc
The dependencies apache2-utils apache2.2-common should be picked up and will
ask for conformation to be installed also. It should look something like:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-utils apache2.2-common
The following NEW packages will be installed:
apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 3051kB of archives.
After this operation, 14.7MB of additional disk space will be used.
Do you want to continue [Y/n]?
Type "y", then enter.
When it's finished, you should be able to go to http://localhost on that machine or
http://theipaddress of that machine from another machine. You should get a
web page the says It works!
The file you are seeing is index.html and the default location is in /var/www/
More
Howto install “Webmin” on Ubuntu or a Debian based server.
One of the first things to do on your new web server (IMHO, of course), is to set up
Webmin.
Webmin is a web based application for the server and domain administration of a Linux machine
and/or cluster.
First:
Go to the Webmin site and download the .Deb file
listed on the top of the home page. (As of this writing, it was top right.)
Second:
If you have some form of display manager (ie, Gnome, KDE, etc.) running on the server,
open a web browser and type in https://localhost:10000
Note: https and note the :10000. This is a secure (ssl) connection and is negotiating through
port 10000.
If you cannot use a browser on the server, go to a computer on the same network and open a
browser with https://yourservername:10000
Third:
This should bring up a login page. You will need to have root access or use an account that
can get root access. (Be one of the admin group on the server) Once logged in, go to the Webmin
configuration settings page.
Forth:
Do this step as soon as possible. We need to
change the port on which webmin is accessed. Change the port Webmin listens on to 10002.
You can change it to whatever you want later. We want the webmin service
to run on a port that will not conflict with something else. You may want to consult an authoritative
port list, if you are unsure. I like to use the official one on
IANA port list. When a change of the list happens,
(once or twice a year) this is where it will be posted.
Note: IANA seems to be going throught (xml) growing pains and the above link outputs
a very slow xml file. You may want to go to the
text version
instead.
If you had previously installed whitelister (for postfix) which uses port 10000, you will start
getting a couple of different errors, all dealing with conflicts with port 10000. Trying to reinstall
webmin and you may get errors like “port 10000 already in use”
If you are having this problem right now and need answers fast; try running
this command in a terminal:
sudo netstat -antupl | grep :10000
If you get an output that looks like:
tcp 0 0 127.0.0.1:10000 0.0.0.0:* LISTEN 4948/whitelister
you can stop whitelister an any conflicting service with:
sudo /etc/init.d/whitelister stop
Fifth:
For the purpose of this instruction, we'll assume port 10002.
Once changed you will have to re-login to your server using the new port number.
So, it should now look like: https://yourservername:10002 If you are on that machine you can also
use https://localhost:10002
This should give a basic webmin running. I'll cover how to work with Apache within
(and outside of) Webmin next. As always; if you need help with something, there's an email link
on the bottom of this page. Send me an email and I'll put together what I know and send it
out right away.
Module mod_evasive
This module is designed to assist in limiting concurrent conections from the same address.
If you are wondering why. Watch your apache log sometime with a command like:
tail -f /var/log/apache2/access.log
Every once in awhile, there will be some annoying bot hit your server a baggazillion times.
This will help.
Install the package libapache2-mod-evasive in either synaptics or in a terminal
sudo apt-get install libapache2-mod-evasive
You'll need to edit your apache2.conf file
Put the following towards the end and restart or reload apache:
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 22
#optional
#DOSEmailNotify youremail@yourdomain.tld
#DOSSystemCommand "run some command"
#DOSLogDir "/var/log/mod_evasive/evasive.log"
#If you use the last one, don't forget to make the directory and file
</IfModule>
Error and Access Logs
One of the nicer things about Linux/BSD operating systems is the ability to
look at the files of everything installed. One of the utilities that
come pre-installed in most distributions is “tail”.
Tail prints out the last ten lines of a file. With the “-f”
switch it follows the changes as it happens. The “-v”
switch makes the output more verbose.
So you got your pretty web site up and running and you want to see what
or who is viewing your site.
Open your favorite terminal either connected via ssh or directly on the web server and put in
tail -fv /var/log/apache2/access.log
You should get something like:
msnbot-157-55-33-111.search.msn.com - - [16/Mar/2013:07:45:59 -0700] "GET /mypage.php HTTP/1.1" 200 58 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
crawl-66-249-73-90.googlebot.com - - [16/Mar/2013:07:58:26 -0700] "GET / HTTP/1.1" 200 7393 "-" "DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)"
119.63.193.130 - - [16/Mar/2013:08:08:18 -0700] "GET / HTTP/1.1" 200 21415 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
The first two are search engines. The last one is a machine in Japan.
“Get /” is requesting the root page (http://www.cruzit.com/).
The “200” is the “OK” code back to the browser.
They were served up the index page.
An invaluable tool when writing php code is to use the same command with
the error log.
tail -fv /var/log/apache2/error.log
Note: Logging errors needs to be turned on in your php.ini file. For
Ubuntu it should be in /etc/php5/apache2/php.ini
Look for the section under “Error handling and logging
“
and turn on logging with “log_errors = On”
With newer distributions, you can now tail more than one file at the same time.
Try this and enjoy!
tail -fv /var/log/apache2/access.log -fv /var/log/apache2/error.log
Note: Your apache logs may be somewhere else. If you are not running
your own server, it may be in your /home directory somewhere.
There have been
6736
Unique Visitors (IP Addresses) to this site.