FreeBSD Server Administration

« March 2005 | Main | May 2005 »

April 19, 2005

Using Perl and MySQL

I moved this Blog to my FreeBSD server, this Blog uses MovableType Blog system which requires perl (as cgi file) and MySQL. To make the posting working, I did the following things:

1. Uncomment the following line in the Apache configuration file /usr/local/etc/apache/httpd.conf.
AddHandler cgi-script .cgi .pl

2. Install perl-mysql module
# cd /usr/ports/databases/p5-Mysql
# make install


Category : MySQL

Posted by FreeBSD Newbie at 12:54 AM | Comments (0)

Change Hostname

It seems to be important to have a hostname which can be queried(nslookup or ping), especially for MTA. My ISP used something like myname.ispdomain.com by default, which I can't add A record on my DNS server.

To change a hostname, do:
1. # hostname newname
2. Edit /etc/hosts
3. Edit /etc/rc.conf

After I changed it to hostname.mydomain.com, I added an A record in the zone file of mydomain.com.


Category : FreeBSD General

Posted by FreeBSD Newbie at 12:40 AM | Comments (0)

April 13, 2005

System Logs

Several important logs:

1. /var/log/messages
2. /var/log/auth.log
3. # dmesg -a
4. /var/log/maillog


Category : FreeBSD General

Posted by FreeBSD Newbie at 11:59 PM | Comments (0)

April 12, 2005

Tar Command

Tar can detect an archive with gz compression and extract the files properly, I used to call gunzip first :-(.

Example
# tar czvf backup.tar.gz *

Extract the archive:
# tar xvf backup.tar.gz

How I did before:
# gunzip dv backup.tar.gz
# tar xvf backup.tar


Category : Command & Utility

Posted by FreeBSD Newbie at 11:56 PM | Comments (0)

April 09, 2005

Protect Directory

How to protect a directory under Apache?

This can be done with .htaccess, visitors must input username and password before they can access the protected directory.

Step 1.
Create the file ".htaccess" with the following content under the directory you want to protect, you can specify the password in any place as long as Apache can access it.

AuthUserFile /home/account/passwd/.htpasswd
AuthGroupFile /dev/null
AuthName "Title"
AuthType Basic

<Limit GET POST>
require valid-user
</Limit>

Step 2.
Generate the password file ".htpasswd" under the directory /home/account/passwd/ with the following command:
# htpasswd -c .htpasswd user_name

You will be reminded to input password for the user "user_name", this command can be called multi times to generate multi users.

Step 3.
This step may not be necessary. If there is an entry about the directory you want to protect in Apache configuration file, make sure AllowOverride has the option authconfig.

For example, when protecting Awstats pages, the Apache configuration file should be modified as following:

<Directory "/usr/local/etc/awstats/wwwroot">
Options None
AllowOverride authconfig
Order allow,deny
Allow from all
</Directory>

Restart Apache
# /usr/local/sbin/apachectl restart


Category : Apache

Posted by FreeBSD Newbie at 11:54 PM | Comments (1)

April 07, 2005

How to Transfer a Website Effectively

Tar command is the most effective way to transfer a website between servers:

1. On old server
Package DB data
# cd /var/db/mysql/db_name/
# tar cvzf /home/account_name/accountdb.tar.gz *

Package all files under the account's home directory.
% cd /home/account_name
% tar cvzf account.tar.gz *

2. On new server
Add a new user with the same account name, also create a database for it.

Get the gz file with ftp from the old server and unpack it.
% cd /home/account_name
% tar xvf account.tar.gz

Unpack DB data.
# cd /var/db/mysql/db_name/
# tar xvf /home/account_name/accountdb.tar.gz

The website should be ready after updating named and Apache configuration file.


Category : Tips

Posted by FreeBSD Newbie at 08:11 PM | Comments (0)

April 02, 2005

A Silly Story

In a previous post, I said pop3 server's installation was very easy. Now, I try to install it on my second FreeBSD server, guess what? I couldn't make it work and looked for help on the mailing list.

Kris helped me very fast, the conversation went on like this:

Me: I installed qpopper and uncommented
pop3 stream tcp nowait root /usr/local/libexec/qpopper popper in inetd.conf, blah, blah... lots of background I thought useful.
But why doesn't it work?

Chris: What is logged on the server?

Me: The error message is "inetd[32476]: cannot execute /usr/local/libexec/popper: No such file or directory". But I checked the file, it does exist. I can execute it manually:
./qpopper

Chris: qpopper, not popper

Me: !$#%@$^

A FreeBSD newbie ignores the log information, a computer newbie fails to compare words.


Category : Email

Posted by FreeBSD Newbie at 08:56 AM | Comments (0)

Two PHP Problems

This is probably very simple, but I could spend hours on it if I'm not lucky.

1. PHPbb displays a blank page if register_globals is disabled.
2. If a crob job executes PHP pages, the working directory is important.
For example:
59 23 * * * /home/account_name/www/sample.php
If get problems, try
cd /home/account_name/www/
59 23 * * * ./sample.php


Category : PHP

Posted by FreeBSD Newbie at 07:45 AM | Comments (0)