Archive for the ‘Directadmin Tricks’ Category

How to Modify Default Virtualhost Template in Directadmin

Wednesday, August 20th, 2008

If you own a Direactadmin server, most probably you would like to add something to default virtualhost settings, when a new user is created. You might need any specific php settings, or anything related to Apache - this doesn’t really matter. Let’s see where we can modify these settings; you will need SSH access to your server as we will edit a configuration file.

We need to go to the directory, where configuration templates are located. It is /usr/local/directadmin/data/templates. There are lots of files, but we need virtual_host.conf to make the necessary changes to default virtualhost settings.

A default file should look like this (this is the original version):

|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/usr/local/lib/php/|
<VirtualHost |IP|:80>
|CUSTOM|
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/cgi-bin/|
ServerName www.|DOMAIN|
ServerAlias www.|DOMAIN| |DOMAIN| |SERVER_ALIASES|
ServerAdmin |ADMIN|
DocumentRoot |DOCROOT|
|CGI|

|USECANONICALNAME|

User |USER|
Group |GROUP|
CustomLog /var/log/httpd/domains/|DOMAIN|.bytes bytes
CustomLog /var/log/httpd/domains/|DOMAIN|.log combined
ErrorLog /var/log/httpd/domains/|DOMAIN|.error.log

<Directory |DOCROOT|>
Options +Includes -Indexes
|*if CLI=”1″|
php_admin_flag engine |PHP|
<IfModule !mod_php6.c>
php_admin_flag safe_mode |SAFE_MODE|
</IfModule>
php_admin_value sendmail_path ‘/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|’
|*endif|
|*if OPEN_BASEDIR=”ON”|
php_admin_value open_basedir |OPEN_BASEDIR_PATH|
|*endif|
|*if SUPHP=”1″|
suPHP_Engine |PHP|
suPHP_UserGroup |USER| |GROUP|
|*endif|
</Directory>
|HANDLERS|
|MIMETYPES|

</VirtualHost>

For example, we need to have a common include directory for PHP scripts, operated by many users. Certainly it is possible to go to /usr/local/directadmin/data/users and change include settings one by one. You can also edit php.ini, but this is the most unsecure solution.

In order to add a directory for common inclusion, we need to add it to the following string:

|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/usr/local/lib/php/:/YOUR_DIRECTORY|

This file is easy to understand so if you need to have some specific settings, it is quite easy to apply them. For example, if you need to use wildcard subdomains, you will need the following string:

ServerAlias *.|DOMAIN| |DOMAIN| |SERVER_ALIASES|

Any changes related to default Directadmin virtualhost should be made in this file.

If you need to apply changes to existing users, the glue is to run the following command via SSH:

echo “action=rewrite&value=httpd” >> /usr/local/directadmin/data/task.queue /usr/local/directadmin/dataskq d

This will apply the canges made to all users. All virtualhosts will be rewritten, so triple check the configuration before applying this command - in case of any error your sites may stop working.

DirectAdmin Message System Stopped Working - How to Fix

Wednesday, July 30th, 2008

I’ve noticed a strange thing at one of my DirectAdmin servers. I usually perform my backups once a week. After I start the backup process, I got a message that I will be notified when my backups are ready. One of my servers stopped to send me these notifications and I had to find out why .

First of all I checked my mail server. Everything was OK, messages were sent and received as usual. I took a look at the Directadmin itself - there usually were messages in the top right corner - none were there. Hmm…

I decided to take a look t DirectAdmin system logs, as the problem seemed to be with its own messaging system.  The answer was found in DirectAdmin Task Queue Log - /var/log/directadmin/errortaskq.log . Here is how it looks:

The only thing I had to do was to edit the file /usr/local/directadmin/data/admin/next_ticket.number . I’ve added a number to this file as it was empty and no ticket numbers could be assigned. Why did this number disappear - I really have no Idea.

How to fix “Mailbox in Use” Error in DirectAdmin

Friday, July 25th, 2008

Today I went back from my short trip to the country. First of all I decided to check my mail, and when I did it, I got the following error in my E-mail client: !25.07.2008, 19:20:39: FETCH -ERR [IN-USE] Mailbox in use. That’s not the first time when such an error happens and I already know the solution - I think it’ll be useful for all server administrators (By the way, It’s Sysadmin’s day today).

When you get the message that mailbox is used, you must have some lock files, that prevent using locked mailboxes. It is not so easy to find out the reason why these files appear (If you know, just write about it in comments). The solution is obvious - to find and destroy these files.

Mailbox lock files are usually located at /var/spool/virtual/. You fill find domain name folders there and your e-mail account lock files should be right there. Just check them. I usually use locate to find these files - their number shouldn’t be big.

After you delete these files, your mailboxes will start working as usual.

Awstats and Directadmin - Now Supported Officially

Tuesday, July 22nd, 2008

Today I have updated my Directadmin installation and found that version 1.322 has appeared a few days ago. One of most intersting features I found was awstats support. I’ve been using awstats plugin for a while and now it is integrated in DirectAdmin.

In order to add awstats support to your Directadmin installation you have to perform some simple steps:

cd /usr/local/directadmin/scripts
./awstats.sh

This will do several things.
- download and install the awstats setup.
- add awstats=1 to your directadmin.conf
- add webalizer=0 in your directadmin.conf (webalizer will be shut off, you can override it if you want both)

Webalizer stats are quite simple and not so informative as awstats data is. You will have some log changes, but this should not affect your server performance. You can read more about this at DirectAdmin official site.

How to Set the Correct Hostname for Directadmin

Monday, July 14th, 2008

Often after initial Directadmin setup, made by your server provider, you keep getting the following message: Subject: This is e-mail notification to warn you that your hostname is setup improperly on your system. You keep getting this e-mail daily until you do something with your hostname. It’s quite a strange thing that hostname isn’t set up during main Directadmin installation, but these messages are annoying.

In order to solve this issue we need to run a Directadmin script via SSH. This will fix your installation and our won’t get this message anymore. Let’s go: we need to login as root and run the following script with two parameters:

/usr/local/directadmin/scripts/hostname.sh <hostname>

This will set your server hostname to one you specify in this command.

Setting Custom Error Pages for All User Domains with .htaccess on a Directadmin Server

Wednesday, June 25th, 2008

Sometimes it is useful to use custom error pages on all user domains  (In case of maintenance, new software installation, etc). It’s a pity you are unable to do it for all user domains in Directadmin, just for a single one. But htaccess comes to help us this time.

Go to /home/admin/domains (certainly, replace admin with your username) and create a .htaccess file containing the following code:

ErrorDocument 404 http://google.com

This code will be valid for all domains that are owned by this user, so you don’t need to change your custom error pages one by one.

It’s a pity Directadmin doesn’t have any options for bulk domain options, i.e. bulk domain addiction, bulk DNS modification, etc. Bulk error code setting could also be a nice feature for such a panel and hope it will be realized soon

Simple Site Redirection With DirectAdmin

Friday, June 13th, 2008

Today I’ll write about the rarely used Directadmin feature named Site Redirection. If you’re not familiar with htaccess and want to create some redirects, then this is especially for you.

The interface is easy to understand. You have to enter Local URL Path, Redirect Type (It will be visible in request headers. I’d suggest to use 301 if you aren’t planning to take redirect off your site.

Destination url should begin with http:// and it will be that url where your site visitors will come. Sometines, when you have long initial paths with variables that are sent via GET, you should all ‘?’ or ‘&’ at the end of your destination url in order to avoid bad request.

This method is not so flexible as htaccess, but it’s great for beginners if you want to create some redirects.

Disabling PHP Safemode and open_basedir in Directadmin

Saturday, May 17th, 2008

Sometimes you need to remove limits that are automatically added by DirectAdmin. For example, you are not allowed to include files from anywhere but your home directory, you cannot use CURLOPT_FOLLOWLOCATION in php and so on.

The first case is the result of open_basedir protection. If you’re not running a hosting service and all sites are yours, it is enough safe to disable open_basedir protection for you own sites if you really need it. Safe mode may prevent you from running some scripts and you might also need to turn it off. This can be done from Directadmin Admin Panel. Just follow the screenshot below:

Then you should find your domain and disable open_basedir and safe mode for it. I usually disable these protections by default, but I don’t recommend to do it when you run a hosting service.

Don’t forget to restart Apache after your changes as they will be propagated upon httpd restart only. It will be done automatically in some time, but if you need it instantly, you should reboot it manually.

How To Repair And Optimize All Mysql Databases

Thursday, May 15th, 2008

When I tried to create admin backup for DirectAdmin, I got the message that one of my MySQL databases has errors and these errors were propagated to my backup. I’d suggest this to DirectAdmin developers, as using a simple command should avoid such errors. There is a linux shell tool called mysqlcheck, that allows to check, repair and optimize mysql databases without stopping mysqld. I will show you its usage so you can run this command before creating any kind of backups.

mysqlcheck -uroot -ppass -Aor

Male sure to include MySQL root password for this operation. If you don’t know your root password, check DirectAdmin Help for information regarding it. Let’s describe used options in brief. -A tells us that all databases will be checked. -r - Repairs selected databases, -o - Optimizes selected databases. This simple operation will allow you to have only good databases in your backups. You may also add this operation to your root crontab to keep your databases optimized.

How to Disable Web Access to Account With IP and Username in Directadmin

Tuesday, May 13th, 2008

Sometimes it is necessary to disable http://ip/~username account access for any reason. Site can be unavailable or simply you don’t want users to access it in such a way. There is a simple directive in httpd.conf that will stop it. Just find the following lines and make them the same as below:

<IfModule mod_userdir.c>
#UserDir public_html
UserDir disabled
</IfModule>

Mod_userdir is active by default so you should pay attention to it if you don’t really want your site to be displayed with IP and username