www.pokeroconnor.com

Wordpress site redirect

February13

I had the following problem lately: I added the typical rules to htaccess to redirect example.com/anything to www.example.com/anything, e.g.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule (.*)$ http://www.example.com/$1 [L,NC,R=301]

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

But when I went to example.com I got infinite redirects…reason being I had the siteurl field in the wp_options table of the database set to http://example.com.

So, you need to change that to http://www.example.com, and also edit wp-config.php as follows:

define('WP_HOME','http://www.example.com');
define('WP_SITEURL','http://www.example.com');

That should be it - see here if not.

Installing IMAP SMTP Postfix Debian

February6

I run Debian Lenny, and have my bind server setup with mail.yourdomain.com. That’s my starting point, and the following is how to install and configure SMTP and IMAP, using Postfix and SASL.

On debian you need the courier-imap package, and note it runs on port 143.

apt-get install courier-imap

This is a good guide to IMAP side of things.

VIP: Support for maildir-style mailboxes needs to be added, so edit /etc/postfix/main.cf to add the following:

home_mailbox = Maildir/

SMTP

This guide rules as a starter for SMTP.

Run apt-get install postfix-tls sasl2-bin libsasl2 libsasl2-modules, and maybe apt-get install libsasl2-2 but MAKE SURE you change /etc/default/saslauthd to have the following:

START=yes
MECHANISMS=”pam”

Next file to edit is /etc/postfix/sasl/smtpd.conf (you have to create it):
pwcheck_method: saslauthd

VI: /etc/postfix/main.cf

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination

NB, back in terminal do this:

rm -r /var/run/saslauthd/
mkdir -p /var/spool/postfix/var/run/saslauthd
ln -s /var/spool/postfix/var/run/saslauthd /var/run
chgrp sasl /var/spool/postfix/var/run/saslauthd
adduser postfix sasl

Also, copy other pam group to smtp:


cd /etc/pam.d
cp other smtp

Restart and go:

/etc/init.d/postfix restart
/etc/init.d/saslauthd start

Test your config by telnet-ing in:
telnet localhost smtp
Trying 80.237.145.96…
Connected to jimmy.co.at.
Escape character is ‘^]’.
220 kitana.jimmy.co.at ESMTP Mailserver
ehlo reptile.g-tec.co.at
250-kitana.jimmy.co.at
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=NTLM LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250 8BITMIME
AUTH PLAIN amltbXkAamltbXkAcmVhbC1zZWNyZXQ=
235 Authentication successful

Or maybe not successful!!!!
VIP!!!!!!!!!!! May get an error in /var/log/mail.log with “warning: SASL authentication failure: no secret in database“.

In this case you need to set up a user and pass for SASL as follows:
saslpasswd2 -f /etc/sasldb2 -u yourdomain.com paul

Another error is “warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or directory“.

This is solved here, READ IT!

In /etc/init.d/postfix,  around line 43 there is a list of files that are copied from their real directories into the chroot. Change the line so it looks like:
FILES=”etc/localtime etc/services etc/resolv.conf etc/hosts etc/nsswitch.conf etc/sasldb2″

Installing BIND Server

October21

The following are the best resources I could find on installing a BIND (9) server. I installed on Debian Lenny, but the principles of zone files etc are universal. I’ll also detail (somewhat) the steps to installing a BIND DNS server, and some of the common and annoying issues you may come across – damn you AppArmor!!!

For starters, here’s Zone files info. Zones and zone files is probably the most fundamental concept you need to understand when starting BIND/DNS use. Very basically, a zone in DNS terms is what you might in other conversations call a domain, sub-domain or url –  e.g. pokeroconnor.com is a zone, sub.pokeroconnor.com is a zone, poker is a zone etc. Each zone requires “definition” if you will, in named.conf, and forward and reverse zone files. A forward zone file for pokeroconnor.com defines forward name resolution, e.g. pokeroconnor.com to octal IP addresses (123.20.33.122). Reverse zone files then do the opposite (basically), providing octal -> name resolution.

In zone files you need to be aware of the following notation:

  • SOA – start of authority
  • IN – internet record
  • MX – mail record
  • NS – name server
  • A – A class address (in octal) e.g. 111.2.3.44
  • CNAME – really an alias for another zone e.g. if poker.me.com is a CNAME record for me.com, requests for poker.me.com resolve to me.com.

This is vital – every time you edit a zone file, you must increment (or change) the serial value. Otherwise your changes won’t get detected by BIND, and apparently its a very common source of errors. The common format of serial is e.g. 2009092201 – yes its the date, in year, month, day followed by the increment on that date, in this case 01. Of course you can have what you want here, just be sure to change it every time the file changes. More info here, and the definite work on BIND.

Then, to actually install Bind and setup your own nameservers, best links I could find are this and this basic one. Also install the dnsutils package. Important things to note are that it is a VERY good idea to setup bind/named to run in  a chroot ‘jail’. This is so that if someone hacks your bind install, they only have access to that particular app. Once you’ve followed these steps, e.g. install bind, setup chroot user, create zone files and configure named.conf etc, you can then cross your fingers and restart bind. Best place to check for errors of course is in your /var/log/syslog, so check it. I had a particularly annoying and extremely frustrating problem…I had everything installed and chrooted, zone files created, everything in its proper place, but bind would not start. I could stop it, but not start it. When I checked syslog, I saw errors similar to this:

named[22070]: zone 100.11.45.in-addr.arpa/IN: loading from master file 100.11.45.in-addr.arpa failed: file not found

Basically saying that the reverse zone files were not found…but they were there!! They were in the /var/lib/named/etc/bind directory as they should be, so how can the system be reporting them as not found??? It didn’t make ANY sense. Until that is, I eventually found this. If you run debian, I strongly suggest you check out that link. There is a package called AppArmor, which does what a chroot jail does. In other words, it restricts the access and rights of certain apps, and of course named is one of those apps it restricts!! The system couldn’t find the files that were there, because the named user was only allowed access to certain directories specified by AppArmor, and /var/lib/named/etc/bind was not one of them. So, simply doing apt-get –purge apparmor and restarting bind solved the problem. That was the hardest to solve error – I would recommend checking whether you have apparmor installed on your box, and if you do, and you don’t knowingly use it, then remove it!

Locate: command not found error

September23

I just recently did a fresh install of Debian Lenny, but when I tried to locate something, I got the following error:

-bash: locate: command not found

This is because you need to separately install locate, or even better, mlocate which is much faster apparently.

Doing this is simple, you just need to do 2 things…

Firstly, apt-get install mlocate to grab and install the mlocate stuff. Finally, you must run the updatedb command.

Viola, that’s it, short and sweet, now you can locate away!

Also worth mentioning is the purge option with apt-get, e.g. apt-get remove app_name –purge, which completely removes an application and all its configuration files. Or if you want to cleanup after removing an application, run apt-get clean.