FAQforge provides answers for frequently asked questions for the Linux-, MAC and Windows operating systems.

Redirect http requests to a new folder with apache rewrite rules

Friday, August 12, 2011 - posted by Till

When you reorganize the structure of a website, you might want to redirect requests to files in a old folder to a new one without loosing the pagerank. In this example, I will redirect all requests from directory "olddir" to directory "newdir", so that requests like http://www.yourdomain.tld/olddir/page.htm get redirected to http://www.yourdomain.tld/newdir/page.htm without loosing the Google pagerank of the pages.

The following rewrite rules can be added into a .htaccess file in the website directory or in the vhost configuration.

RewriteEngine on
RewriteRule ^olddir/(.*)$ newdir/$1 [R=301,L]

This rewrite rule redirects automatically all requests to pages or subdirectorys of "olddir" to the same page or subdirectory in "newdir".

Reduce load of backup scripts with nice and ionice

Wednesday, August 10, 2011 - posted by Till

Runing a nightly backup script on a server system like a webhosting server can produce high load and longer latencys for other processes, e.g. HTML or .php pages load slow during backup because the backup script takes too much I/O or CPU resources.

On Linux systems there are two shell utilitys available to set the I/O and CPU Scheduling for a appliaction or script. The utilitys are named nice and ionice.

Reduce the I/O priority of the script "/usr/local/bin/backup.sh" so that it does not disrupt other processes:

/usr/bin/ionice -c2 -n7 /usr/local/bin/backup.sh

The -n parameter must be between 0 and 7, where lower numbers mean higher priority.

To reduce the CPU priority, use the command nice:

/usr/bin/nice -n 19 /usr/local/bin/backup.sh

The -n parameter can range from -20 to 19, where lower numbers mean higher priority

Nice and ionice can also be combined, to run a script at low I/O and CPU priority:

/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/local/bin/backup.sh

 

If you want to set the time in a OpenVZ Guest automatically, execute the following command on the host system:

vzctl set 101 --capability sys_time:on --save

and restart the guest system:

vzctl restart 101

101 is the ID of the container and has to be changed to match the ID of your OpenVZ VM.

Thanks to PlanetFox for this FAQ.

Disable quota for a Linux user or group on the shell

Thursday, May 5, 2011 - posted by Till

Linux user quotas can be edited with the commands edquota or setquota on the shell. While edquota opens the quota settings in a editor like vim, setquota allows you to specify the quota settings on the commandline.

Example for disabling the quota for the user "testuser":

setquota -u testuser 0 0 0 0 -a

Example for disabling quota for the group "testgroup":

setquota -g testgroup 0 0 0 0 -a

Convert the charset of file names from iso-8859-15 to utf8

Thursday, April 7, 2011 - posted by Till

When you copy files from a older Linux or Windows system to a new Linux system, the filenames can get broken and have to be converted. Handy tool to translate the charset of filenames is convmv.

Example

convmv -f iso-8859-15 -t utf8 -r /var/www/myhome.lan/web/images/*

Your Perl version has fleas #37757 #49830
Starting a dry run without changes...
mv "/var/www/var/www/myhome.lan/web/images/gr▒n.jpg"     "var/www/myhome.lan/web/images/web/images/grün.jpg"

To finally execute the command (not dry run), use the --notest option:

convmv --notest -f iso-8859-15 -t utf8 -r /var/www/myhome.lan/web/images/*

Thanks to PlanetFox for this FAQ.

The following guide explains the installation of the apache module "mod_evasive". Mod_evasive tracks the number of requests of files at the apache webserver and blocks the delivery in case that a certain limit has been reached.

Installation

apt-get install libapache2-mod-evasive

Create the log directory for mod_evasive

mkdir -p /var/log/apache2/evasive
chown -R www-data:root /var/log/apache2/evasive

Now we add the configuration for the module at the end of the file /etc/apache2/mods-available/mod-evasive.load

vi /etc/apache2/mods-available/mod-evasive.load

so that it looks like this:

LoadModule evasive20_module /usr/lib/apache2/modules/mod_evasive20.so

DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 5
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSLogDir "/var/log/apache2/evasive"

and restart apache:

/etc/init.d/apache2 restart

To change the language of the website statistics generated by AWStats on a Debian Linux server to e.g. german (de), edit the /etc/awstats/awstats.conf file:

nano /etc/awstats/awstats.conf

and change the value of the "Lang" variable. To change the languge to e.g. German, cahnge:

Lang="auto"

to

Lang="de"

The website statistics are generated nightly on a ISPConfig 3 server, so it may take up to 24 hours until the statistics will show up in German language.

Thanks to PlaNet Fox for this FAQ.

Change PostgreSQL Locale

Friday, January 21, 2011 - posted by rafael

wrote by Rafael Marangoni, from Suporte Linux team.

This article explains how to change the default PostgreSQL Locale. Be careful, because we're considering that you do not have data on postgresql instance.

First, we need to stop the postgres service (if was not already stopped):

/etc/init.d/postgresql stop

Then we need to remove all data files from postgresql data dir. On RedHat based, that's the dir:

rm -rf /var/lib/pgsql/data/*

Now we change to postgres user:

su postgres

Creating the initial data, selecting the Locale:

initdb --locale=C /var/lib/pgsql/data

or

initdb --locale=pt_BR.UTF-8 /var/lib/pgsql/data

or your locale

/etc/init.d/postgresql stop

Then, we start postgres service:

/etc/init.d/postgresql start

How to enable SSH on VMware ESXi Server

Friday, January 14, 2011 - posted by rafael

wrote by Rafael Marangoni, from BR Link team.

By default, the ssh login is disabled on VMware ESXi, in opposite way what it happens on VMware ESX Server.

But, there’s a way to enable SSH Login.

After the system is installed, go to the console screen and type:

ALT + F1

After that, a Black screen will appear (be calm, that is normal), then type:

unsupported

Next, the Server will prompt for root password. Then you type the root password.

Afterwards, you’ll have shell access. We need to edit the following file:

vi /etc/inetd.conf

Uncomment the line that starts with “SSH”. Save the file (it’s a normal vi, ZZ will do that for you).

Now reboot the server:

reboot

After it reboots, you should login with SSH on port TCP/22, and user root.

Updating Samba on CentOS 5

Friday, January 14, 2011 - posted by rafael

wrote by Rafael Marangoni, from Servidor Linux team.

This article explains howto update the Samba packages on CentOS 5 to version 3.5.

First, we need to add a new repository:

cd /etc/yum.repos.d/

wget http://ftp.sernet.de/pub/samba/3.5/centos/5/sernet-samba.repo

Then, update samba:

yum update samba

Probably, you will need winbind too:

yum install samba3-winbind samba3-utils

Check the rpm version:

rpm -qa | grep samba

Restarting Samba:

/etc/init.d/smb restart