//

2010/09/22

Enable apache file and directory indexing under Linux or UNIX

If a URL which maps to a directory is requested, and there is no DirectoryIndex (e.g., index.html) in that directory, then mod_autoindex will return a formatted listing of the directory.

Option # 1: Using Apache config file

Add directory option to Apache configuration file /etc/httpd/httpd.conf or /etc/apache2/apache2.conf:
# vi /etc/apache2/apache2.conf
Add following code:

Options Indexes FollowSymLinks

Save and close the file. Restart Apache:
# /etc/init.d/httpd restart
OR
# /etc/init.d/apache2 restart

Option #2: Using .htaccess Files with Apache

You can place config line Options Indexes in .htaccess file. Make sure .htaccess file support is enabled.
Change directory to pdfs
$ cd pdfs
Open .htaccess file
$ vi .htaccess
Append following apache directive:
Options Indexes
Save and close the file.

2010/09/07

Reset Webmin Root password


Webmin Password ResetAt times we often forget the webmin password for a given user say root or after repeated failed login attempts webmin locks the account and one cannot login anymore. In order to change/reset the password we need to run a changepass.pl  that is provided with webmin by running it from the shell terminal on the server it self.
So logon to the server via ssh and sudo as root user.
If you execute the script the following out is displayed.
[root@livrona webmin]# /usr/libexec/webmin/changepass.pl
usage: changepass.pl

This program allows you to change the password of a user in the Webmin
password file. For example, to change the password of the admin user
to foo, you would run:
        changepass.pl /etc/webmin admin foo
This assumes that /etc/webmin is the Webmin configuration directory.

So let's say that in order to change the password of user root to changeme we would execute the following.
 [root@livrona webmin]# /usr/libexec/webmin/changepass.pl /etc/webmin root changeme
Updated password of Webmin user root
[root@livrona webmin]#
exit
exit
-sh-3.1$

Now go back to browser and try to login with the new password, it should work.
If the given user does not exist in webmin, it would say that the user does not exist and list out all the users in the webmin system.
[root@livrona webmin]# /usr/libexec/webmin/changepass.pl /etc/webmin admin password
The Webmin user admin does not exist
The users on your system are: root

2010/09/03

Use MYSQLDUMP and CRON to backup Databases (MySql)

"The mysqldump client can be used to dump a database or a collection of databases for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump contains SQL statements to create the table and/or populate the table."-- from the MySQL Reference Manual.

Technique 1
I wrote a short PERL script to backup my database and compress the results into a unique name based on current date.
Sample PERL script --

#!/usr/bin/perl

($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time) ; 

$Year += 1900 ; $Month += 1;

$dt = sprintf("%04d%02d%02d", $Year, $Month, $Day, ) ;

exec "/usr/local/bin/mysqldump --opt -hHOSTNAME -uUSERID -pPASSWORD DATABASE_NAME |gzip > PATHNAME/$dt.gz";
The $dt variable gets resolved to the current date in YYYYMMDD format.

Technique 2
The wizards at Pair networks sent out this gem of wisdom in one of their monthly newsletters.
To back up a particular database, enter this command (all on one line):

/usr/local/bin/mysqldump -hDBXX.PAIR.COM -uDB_USERNAME -pDB_PASSWORD USERNAME_DATABASENAME > 
usr/home/USERNAME/backup/DATABASENAME.`/bin/date +\%Y\%m\%d`
Here are the replacement values for the above command:
DBXX.PAIR.COM = The hostname of the database server the database resides on
DB_USERNAME = The MySQL username for the database in question
DB_PASSWORD = The MySQL password for the username above
USERNAME_DATABASENAME = The full name of the database
USERNAME = Your pair Networks username
These commands will generate a file in the "backup" directory off of the home directory called DATABASENAME.DATE where DATE is the date the backup was made. Make sure that a "backup" directory exists off of your home directory when creating these cron jobs.

Just set this up to run regularly with cron and you now have regular backups.