Markus Hedlund

Developer / Photographer

Contact / GitHub / Instagram

Work With Me

Setup logcheck on Ubuntu 10.10

Logcheck is a nifty tool that reads all system and application logs for you, and then send e-mails with reports of anomalies. It makes maintaining a server easier, and therefore increases security.

I couldn't find a guide for installing and setting up on Ubuntu, so I decided to share my notes.

It was a pretty quick and painless process. After installing it by running

aptitude install logcheck

you should add your email address to the configuration file

/etc/logcheck/logcheck.conf

Change SENDMAILTO with the email address you want to receive the log digests to.

By default logcheck is run 2 minutes past every hour. I changed this to run 7:02, which is done by editing the file

/etc/cron.d/logcheck

Now it's time to check if this works. Running logcheck won't work, since logcheck should be run as the logcheck user. To do this, run

sudo -u logcheck logcheck

as root. Did you get an email? No? Then the message probably is stuck in the spam filter, if you haven't spent a lot of time, making sure spam filters will accept emails from your server.

Good luck, and let me know how it worked for you :-)

Update for Ubuntu 11.04

I tried this guide on Ubuntu 11.04, and it works the same.

Trim unicode/UTF-8 whitespace in PHP

preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string);

This will effectively remove any weird whitespace characters, control characters and even those pesky Apple logos.

Have a look at the page below for more information on the Unicode characters and regular expressions.

nadeausoftware.com

“2006 - MySQL server has gone away” error when importing with SQLyog

Get this annoying error when importing a database with SQLyog? "There was an error executing the query. […]". When you click "Open error file…" the real MySQL error is presented: "Error Code: 2006 - MySQL server has gone away".

Solution

Open "my.ini", located in your MySQL installation folder, and change "max_allowed_packet = 1M" to "max_allowed_packet = 64M" or something higher than 1 MB.

The problem is that SQLyog sends a massive SQL query that exceeds this limit.

PHP: Get filename extension with native PHP function

The extension part of the filename, is what typically tells us what type of file it is. A JPEG image may have the filename "image.jpg", where "jpg" is the extension.

Click through to learn how easy it is to extract this with PHP.

echo pathinfo('filename.jpg', PATHINFO_EXTENSION);

Easy as that! This will output

jpg

pathinfo can be used for much more than retrieving the file extension, please see the PHP documentation for all options.

PhpED: Get back Tortoise SVN in the shell menu

After I reinstalled my system with Windows 7 64 bit, the very handy SVN Tortoise icons were all gone from the shell menu in Nusphere PhpED. This made SVN actions so much more time consuming.

The problem turned out to be that Tortoise SVN was a 64 bit application, and PhpED still is a 32 bit application. For both 32 and 64 bit applications to see Tortoise's shell extensions, you must have both 32 and 64 bit Tortoise installed.

Just having the 32 bit version wont do; Windows Explorer and other 64 bit application will not see the icons then.

Simply download the 32 bit version at http://tortoisesvn.net/downloads, and you should be all set!

Pro tip: Hold down CTRL while right clicking (or pressing the context menu button on the keyboard) in PhpED, and the shell menu will appear directly!