Got error ‘Primary script unknown’ after update PHP-FPM + Apache 2.4

After a update_versions in DirectAdmin I got this error on a sites error log:

[client 1.2.3.4:62903] AH01071: Got error 'Primary script unknown\n'

The URL it self gave:

File not found.

Yesterday everything was working fine. After updating Apache 2.4.x and PHP-FPM (5.6) I figured it had to do something with those services.

But the app (CodeEgniter) was running in a subfolder. The main folder contained a WordPress install and was working fine.

So after some time I tried to play with the .htaccess file, and I succeeded. I changed this old .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteBase /fc2/

To this new variation:

RewriteBase /fc2/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /fc2/index.php [L]

Don’t ask me why, but the Primary script unknown is gone.

So in this case it had nothing to do with ProxyHandler, ProxyPass or other configuration issues between PHP-FPM and Apache. Just a little .htaccess error which results in a bug.

Install SpamFighter and BlockCracking with Exim and dkim

This is what I use to set-up my DirectAdmin boxes with Exim, SpamAssassin, SpamFighter, BlockCracking and dkim.

cd /usr/local/directadmin/custombuild 

./build set clamav yes
./build set exim yes
./build set eximconf yes
./build set eximconf_release 4.4
./build set blockcracking yes
./build set easy_spam_fighter yes
./build set spamassassin yes
./build set sa_update daily

./build update
./build exim
./build clamav
./build spamassassin
./build exim_conf

wget -O /etc/exim.dkim.conf http://files.directadmin.com/services/exim.dkim.conf

service exim restart

After that you can use the file /etc/virtual/domainips to set the interface IP for exim:

*:1.2.3.4

MySQL automatic restore script

We had a .sql export from a MySQL databaseserver from all the databases. In our case the filenames were made up like:

mysqldump-hostname-user_database-D5-22H.sql

So I wrote a little bash script to recreate all the databases and import it’s data:

#!/bin/bash

folder=/var/sqlbackup/

for file in `ls $folder/mysqldump-*.sql`
do
echo $file
IFS='-' read -r -a array <<< "$file"
echo ${array[2]}
echo "create database ${array[2]}" | mysql -u da_admin -ppassword
mysql -u da_admin -pnAcQKhIK ${array[2]} < $file

done

After a little while all databases were full with content again 🙂

Install Dutch Language in DirectAdmin Enhanced skin

I use this code to install the Dutch Language (Nederlandse taal) on all my servers. It will get automatically updated if there is a new version available.

#!/bin/bash
cd /usr/local/directadmin/data/skins/
wget ermis.nl/enhanced.zip
unzip -o enhanced.zip
chown -R diradmin:diradmin enhanced/images/
chown -R diradmin:diradmin enhanced/lang/
chown diradmin:diradmin enhanced/files_custom.conf
chmod -R 755 enhanced/images/
chmod -R 755 enhanced/lang/
chmod 755 enhanced/files_custom.conf
rm -f enhanced.zip

After running this code you can select the Dutch Language (nl) in the Modify User page in DirectAdmin.

How to reinstall the default Enhanced skin

If you need to reinstall the default DirectAdmin skin Enhanced you can use this code:

rm -f /usr/local/directadmin/data/skins/enhanced
cd /usr/local/directadmin/data/skins/
mkdir -p enhanced
wget http://files.directadmin.com/services/all/enhanced.tar.gz
tar -xzf enhanced.tar.gz

After this code the enhanced skin will be updated and be default again. Please not that you update DirectAdmin before reinstalling (and updating) the default Enhanced skin.

Rebuild your DirectAdmin user cache

In some particular cases I was unable to find my users using the DirectAdmin UI. Since then I use this little script to rebuild the user cache of the “Show All Users” list.

[code]#!/bin/sh

cd /usr/local/directadmin/data/users

for r in `ls */reseller.conf | cut -d/ -f1`; do
{
echo “fixing Reseller $r …”;

echo -n ” > $r/users.list

for u in `grep “^creator=$r$” */user.conf | cut -d/ -f1`; do
{
ISUSER=`grep -c usertype=user $u/user.conf`
if [ “$ISUSER” = “1” ]; then
echo $u >> $r/users.list
fi
};
done;
};
done;[/code]

After using this script all users will be shown again in DirectAdmin.

Remove e-mail sent count from e-mailaccount

If you want to reset the e-mail acount of a DirectAdmin account it’s pretty simple, you can just hit the reset button. But there are no such buttons for the e-mail accounts itself. So you can use this little line in SSH to remove the e-mail sent acount of a particular e-mail account:

rm -f /etc/virtual/domain.com/usage/info

Notice this line concerns info@domain.com. So you have to change the domain.com part and the info part.

Adding domain pointer with e-mail and SSL options

If you add a domain pointer to a DirectAdmin domain, you can not set-up the e-mail accounts and SSL certificates by default. Almost all the options are not available.

To fix this you can remove the domain pointer and add the domain as a normal domain to the account. It has to be the same account due to permissions.

Then, remove the private_html folder, symlink it to the public_html and set the correct permissions with this piece of code:

rm -rf /home/user/domains/domain.com/private_html
ln -s /home/user/domains/domain.com/public_html /home/user/domains/domain.com/public_html
chown -h user:user /home/user/domains/domain.com/public_html

Now you have the same effect of the normal Domain Pointer in DirectAdmin, but you are able to use the interface for all other DirectAdmin options!

Fix domains list in DirectAdmin

I don’t know why, but at one of my servers the domains.list file gets erased every x weeks. So after some weeks they are missing in the httpd.conf and the domains will not work.

Before I figure out what causes it, this is a little piece of code to fix the list and rewrite httpd:

for d in `ls /home/user/domains`; do echo $d >> /usr/local/directadmin/data/users/user/domains.list; done
/usr/local/directadmin/custombuild/build rewrite_confs