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

How to backup the cronjobs of all users on Debian and Ubuntu Linux?

Tuesday, October 20, 2009 - posted by Till

The cronjobs (crontabs) for all system users in Debian and Ubuntu Linux are stored in the directory /var/spool/cron/crontabs. To make a backup with tar, use this command:

tar pcfz /root/user_crontabs.tar.gz /var/spool/cron/crontabs

The backup file user_crontabs.tar.gz is be stored in the /root/ folder.

How to use a custom php.ini with suphp

Monday, October 19, 2009 - posted by Till

To use a custom php.ini file with SuPHP for a website, you can define the path to the php.ini file in a .htaccess file or in the apache vhost like this:

suPHP_ConfigPath /home/websites/domain.tld/

Then add a php.ini file in the directory /home/websites/domain.tld/ which may be a copy of the global php.ini were you just changed a few settings or an empty file were you add only the settings that shall be overridden in the global PHP configuration.

If you use ISPConfig 2 or 3, you can add the suPHP_ConfigPath setting also in the apache directives field of the website  in ISPConfig.

If you want to redirect a subdomain like sub.domain.tld into a subdirectory of the website and keep the original URL in the browser location bar, you may use the following apache directives.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.tld [NC]
RewriteRule ^/(.*)$ /sub/$1 [L]

This rewrite rule can be added into a .htaccess file in the website root or inside the vhost file. If you use ISPConfig 2 or 3, you can add this also into the apache directives field in the website settings.

Replace sub.domain.tld with the subdomain that shall be redirected and /sub/ with the path to the directory were the pages for this subdomain are located.

How to display hidden files with pure-ftpd on Debian and Ubuntu Linux

Thursday, October 15, 2009 - posted by Till

If hidden files (files that start with a dot like .htaccess, .bash_history, .profile or .ssh) are not displayed in your FTP client, then they are most likely disabled in the FTP server. To enable hidden files in pure-ftpd on Debian and Ubuntu Linux, execute this command:

echo “yes” > /etc/pure-ftpd/conf/DisplayDotFiles

and then restart pureftpd.

If all your visitors shall access your website with a URL like www.domain.com and not without www, use the following apache rewrite rule for redirecting them.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}$1 [L,R]

The apache rewrite rule can be added in a .htaccess file in the website root directory or if you use ISPConfig 2 or 3, you can also add the rwrite rule into the apache directives field of the website.

If you run a firewall on your Linux server and want to use passive FTP connections, you have to define the passive port range in pure-ftpd and your firewall to ensure that the connections dont get blocked. The following example is for pure-ftpd on Debian or Ubuntu Linux and ISPConfig 3:

1) Configure pure-ftpd
echo "40110 40210" > /etc/pure-ftpd/conf/PassivePortRange
/etc/init.d/pure-ftpd-mysql restart

2) Configure the firewall. If you use ISPConfig 3 on my server to configure the bastille firewall, you can add the nescessera port range in the ISPConfig firewall settings.

Change the list of Open TCP ports from:

20,21,22,25,53,80,110,143,443,3306,8080,10000

to:

20,21,22,25,53,80,110,143,443,3306,8080,10000,40110:40210

and then click on “Save”.

How to redirect an HTTP connection to HTTPS in apache webserver

Tuesday, October 6, 2009 - posted by Till

Http connections can be redirected to https with the apache mod_rewrite module, which should be available in every apache installation. Create a file with the name .htaccess in the website root directory which contains the following lines:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

If you use ISPConfig 2 or 3, you can add these lines also in the apache directives field of  the website settings form instead of adding them to a .htaccess file. But the approach with the .htaccess file will work on ISPConfig as well.

Is there a recommended Linux distribution for ISPConfig 3?

Monday, October 5, 2009 - posted by Till

ISPconfig 3 is developed on Debian Linux, this means that Debian is the most tested Linux distribution for ISPConfig. Additionally, Debian has almost all required software packages for ISPConfig in its main repositories without the need to compile them manually and Debian has proven to be very stable in Server enviroments.

This leads to my personal recommendation to use Debian Linux for ISPConfig.

Sometimes you need a specific file from a Debian .deb package e.g. because you deleted a file from your system or the installation of a package is broken in that way that it can not be reinstalled without adding the missing file first. This FAQ shows you how to download the .deb file from the Debian or Ubuntu repository and then exctract its contents.

Download the dpkg file. In this example, I will download the courier-athlib:

cd /tmp
aptitude download courier-authlib

Now extract the .deb package into the directory /tmp/extract/:

dpkg-deb -x *.deb /tmp/extract/

How to enable the query log in MySQL

Wednesday, September 30, 2009 - posted by Till

To debug applications which use a mysql database, it comes in handy to enable the query log to get all SQL queries that were sent to the database.  Open the MySQL configuration file (my.cnf)

vi /etc/mysql/my.cnf

and add the line:

log=/var/log/mysql.log

in the [mysql] section of the file. Depending on the Linux distribution that you use, the my.cnf file can be /etc/my.cnf or /etc/mysql/my.cnf.

Afterwards restart mysql to apply the new the configuration:

/etc/init.d/mysql restart