Ubuntu Linux + Apache2 + Virtual Hosts + Syslog Server

Sponsored Link
This tutorial will explain How to install syslog server in ubuntu using apache. Steps Involved in this tutorial
1) Install Apache2 and change the ports
2) Virtual Hosts: an example
3) Syslog Server with php and Virtual Hosts
4) Only me wants to see the log files (by using a .htacces file)

Local static ip address

Imagine yourself that eth0 is your internet interface and you want 192.168.0.102 as your local ip address. Change the /etc/network/interface file and save it. This is an excellent example then:

auto eth0
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
gateway 192.168.0.1
broadcast 192.168.0.255

Ofcourse you'll have to modify it for your own needs, the above file is just an example file ofcourse.

Preparing syslog

mkdir /logs (let's make a directory for our logs) Modify /etc/syslog.conf and add the next rule if you really would like to log everything: (don't forget to save it) *.* /logs/logger.log

It's possible you're only interessed in a few things, here is the list:

auth -- authentication (login) messages
cron -- messages from the memory-resident scheduler
daemon -- messages from resident daemons
kern -- kernel messages
lpr -- printer messages (used by JetDirect cards)
mail -- messages from Sendmail
user -- messages from user-initiated processes/apps
local0-local7 -- user-defined (see below)
syslog -- messages from the syslog process itself

0 -- Emergency (emerg)
1 -- Alerts (alert)
2 -- Critical (crit)
3 -- Errors (err)
4 -- Warnings (warn)
5 -- Notification (notice)
6 -- Information (info)
7 -- Debug (debug)

Would you like to log everything from auth, cron, lpr error and only syslogs warnings then you have to add next lines to /etc/syslog.conf

auth.* /logs/logger.log
cron.* /logs/logger.log
kern.* /logs/logger.log
lpr.3 /logs/logger.log
syslog.4 /logs/logger.log

Now modify /etc/init.d/ksyslogd with your favourite editor and do the next:

SYSLOGD=”” Change this line by the next line and save:
SYSLOGD=”-r -m0”

restart networking again: /etc/init.d/networking restart

Install Apache2 and stuff:

apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client

php5-mysql

Check cat /etc/hostname, and the hostname that you are seeing here you have to

place in your /etc/hosts file, together with your local static ip address. /etc/hosts:
192.168.0.102 myhostname Don't forget to change the above to your own needs! I decided to host on Port 8070, my ISP (Telenet Belgium) has blocked all ports under 1024. Modify /etc/apache2/ports.conf: (Listen 80 must be replaced by Listen 8070)
Listen 8070

If you are behind a NAT, don't forget to open this port on your router.

Now we're going to install our virtual hosts. cd /etc/apache2/sites-available
touch myname.homelinux.com (we create our name)
Now edit your myname.homelinux.com file with your favorite editor and make sure it looks like this:

ServerAdmin [email protected]
ServerName myname.homelinux.com
ServerAlias myname.homelinux.com
DirectoryIndex index.php
DocumentRoot /logs

Ok, now we're going to etc/apache2/sites-enabled

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/myname.homelinux.com myname.homelinux.com This symbolic link (ln -s) is absolutely necessary. Ok, now we're going to our logs directory and we place there an index.php file cd /logs
touch index.php
Modify index.php now with your favorite editor. This is how it should look like:

Restart apache: /etc/init.d/apache2 force-reload

Ok, go to www.dyndns.com and www.whatsmyip.org (memorize your ip)
And on dyndns you registrate yourself, you log in, then click DNS services ->

dynamic DNS -> Add Host -> and you registrate myname.homelinux.com.

Mention your remote IP (what you saw at whatsmyip.org at the ip line)

If you visit now your myname.homelinux.com/:8070 webpage you will be able to see your syslogs!

4) Only me wants to see the log files (by using a .htacces file)

Now we take measures: Only you will have the possibility to see your syslogs.

cd /logs (Yes we go again to the /logs directory)
touch .htaccess (We'll make an .htaccess file)
Modify .htaccess with your favorite editor. This is how your .htaccess file should look like:

AuthUserFile /root/.htpasswd
AuthName ‘Access is limited here'
AuthType basic
require valid-user

cd /root (go to the /root directory)
htpasswd -c .htpasswd webmaster (let's make a valid account)

Now modify the /etc/apache2/sites-available/default file with your favorite editor:

DocumentRoot /var/www

Options FollowSymLinks
AllowOverride None

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/

This AllowOverride all tells apache2 it has to deal with a .htaccess file.
Restart apache2 again: /etc/init.d/apache2 force-reload

Go to your site now, you'll have to give a password that you've specified.

Conclusion

Now you have a syslog server that's using the virtual host technique on apache2. And only you is able to read the information, caused by the .htaccess file.

By phar0z | [email protected]

Sponsored Link

You may also like...

11 Responses

  1. Beta3 says:

    It would have been much more helpful if the text was bit larger. Thanx a lot anyways 😀

  2. phar0z says:

    no problem! sorry for the little font, I was a little bit absent-minded. I hope the admin can enlarge the font 🙂

  3. Ronny says:

    i use the logs “/var/logs”

    /etc/init.d/ksyslogd is wrong. the name of the daemon is “sysklogd”
    and I didn’t modify anything, because ‘SYSLOGD=”-u syslog”‘ logs already what i need to know.

  4. Pneaveill says:

    Must have missed something above, as I have done it 3x now from start to finish and still don’t have the server seeing the outside world yet.

    VirtualHost *:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
    [Fri Dec 07 21:48:37 2007] [warn] NameVirtualHost xxx.xxx.xxx.xxx has no VirtualHosts
    [Fri Dec 07 21:48:37 2007] [warn] NameVirtualHost neaveillmin.org:0 has no VirtualHosts
    [Fri Dec 07 21:48:37 2007] [warn] NameVirtualHost localhost:0 has no VirtualHosts
    [Fri Dec 07 21:48:37 2007] [warn] NameVirtualHost localhost:0 has no VirtualHosts

  5. gary says:

    PLease assist

    On Localhost i can see my webpage following your procedure. I can FTP into this via http://www.myname.homelinux.com, dir meanining that dynamic dns is working. I have open port 80 for port forwarding as well as port 21. But i can not open my webpage via wwww. Any ideas or next thing to check. Your help would be appreciated.

  6. james says:

    larger font: hold the “Cntrl” key and use your middle scroll wheel on your mouse… no middle scroll wheel? Time to upgrade a bit… 😉

  7. rod hart says:

    I believe I have followed all instructions to the letter but I get an Alert “The URL is not valid and cannot be loaded” a few seconds after my test index.html is displayed. This is really strange because everything seems to work OK until that alert pops up. I am setting up ubutu 8.10 with apache2 using vhost.

  8. Sean says:

    ServerAdmin [email protected]
    ServerName myname.homelinux.com
    ServerAlias myname.homelinux.com
    DirectoryIndex index.php
    DocumentRoot /logs

    Are you for real? apache2 doesn’t like that idea.
    Sure there aren’t any tags missing there?

  9. Tom says:

    I’ve followed the steps to the letter (I believe) and when I go to the newly created web page I get this:

    Warning: fopen(logger.log) [function.fopen]: failed to open stream: Permission denied in /var/log/index.php on line 8
    Error while reading log file 🙁

    Did I miss something?

  10. Tom says:

    Actually I did. I had to run “sudo chmod o=r logger.log” to give the “Other” group read permission to the log file itself. Once that was done, I had no problems seeing the webpage.

    Hope this helps others in the future.

  11. Ashvin says:

    I had also the same problem while I was executing the following code.

    $fp=fopen(“userpoll.txt”,”w”);

    Another problem is that, the solution given by you works only with the existing file.
    Now, what if I want to open a file which is not exist, than what about the permission of that file.

Leave a Reply

Your email address will not be published. Required fields are marked *