Kategorien
Uncategorized

Update: mini_httpd with PHP as CGI

I also reported this problem via reportbug to the Debian Package-Maintainer Marvin Stark.
He applied my patch and created a new debianized version of mini-httpd which will now work out of the box with PHP and CGI.

Here is the link: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=462930

Kategorien
Uncategorized

iTerm and screen

I usually use iTerm when connecting to linux boxes from my Macbook. When also using screen one may notice that e.g. the backspace key doesn’t work properly. I found a solution for this problem:
– Just fire up iTerm
– Click on „Bookmarks“ – „Manage Profiles“
– Keyboard Profiles – xterm (OS X)
– Modify the setting for delete and set the value to „send hex code 8“

After that your ssh sessions may also use the backspace key with iTerm using screen.

Kategorien
Uncategorized

mini_httpd with PHP as CGI

While playing around a bit with other webservers than Apache, I decided to give mini_httpd a try. The documentation is very "limited" and you have to find out the things yourself. So here are the steps I did to get mini_httpd running on Debian Etch. Downloading and extracting is very easy:

wget 'http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz' tar xzvf mini_httpd-1.19.tar.gz

Next step is compiling. There is no configure script in the sources, so if you want to enable e.g SSL support you need to edit the Makefile manually. But for now I want to keep everything at the default-values. cd mini_httpd-1.19 make After the compilation you will find the binaries in the mini_httpd-1.19 source dir (htpasswd,mini_httpd). Most interesting for now is of course the mini_httpd binary. You may want to copy it to a more common place in the filesystem. Starting mini_httpd: mini_httpd knows some startupoptions like port, user, etc. You can either specify these options on the commandline when starting the server or create a separate configuration file (e.g. mini_httpd.conf) where you set all these values. Here are thorsten@debsrv:/usr/local/src/mini_httpd-1.19$ ./mini_httpd --help usage: ./mini_httpd [-C configfile] [-D] [-p port] [-d dir] [-dd data_dir] [-c cgipat] [-u user] [-h hostname] [-r] [-v] [-l logfile] [-i pidfile] [-T charset] [-P P3P] [-M maxage] I decided to create a configfile with the following content: port=88 (for testing purposes only - would be normally 80) user=nobody nochroot cgipat=**php dir=/opt/mini_httpd data_dir=./html logfile=./logs/mini-httpd.log pidfile=/var/run/mini-httpd.pid charset=iso-8859-1 The startup of the server goes like this afterwards: ./mini_httpd -C mini_httpd.conf I would also like to use PHP in mini_httpd. There is no module like mod_php in Apache, but you can implement it via CGI. There is not much configuration to be done (see cgi-pat in mini_httpd.conf) and the shebang in the php sourcefiles need to point to your php binary (e.g. /usr/local/php-cgi), but I couldn’t get it to work successfully. After some investigation with the help of google I found out, that I need to patch the sources of mini_httpd. There is already a patch available from the m0n0wall project but this patch is not feasible for me, because it adds some m0n0wall related functionality, too. So I modified the patch to fit just to my requirements. It also adds "index.php" to the list of default filenames.

mini_httpd.patch

Dowload this patch and apply it to the sources of mini_httpd. After patching you need to call "make" again to build the new binary. patch -p0 -i mini_httpd.patch make

Kategorien
Uncategorized

Choice of Drupal as your CMS

If you are a bit unsure which Content-Management-System is the right one for you, here is a good reason to choose Drupal.
The Drupal – Song!!!

Very easy to remember. You can sing the song after hearing it once! 🙂

Kategorien
Uncategorized

Creating nice Mosaic Images with Perl

I needed a background header-image for my other website (www.vfl3.de) . I already uploaded a lot of photos to that website and wanted to use them in some way for that header. I thought of creating a mosaic-like background picture which is automatically recreated once a week. So any new uploaded pictures will be automatically considered when the script runs.


./mosaic_poster.pl /path/to/pictures 950 200


The first argument is the path in the filesystem where the script looks for the pictures. With the second and third argument you can specify the ranges of the mosaic-picture (e.g. 950×200 pixel)


#!/usr/bin/perl -w
use strict;
use Image::Magick;
use List::Util 'shuffle';

my $im_srcdir = $ARGV[0];
my $im_width = $ARGV[1] || 800;
my $im_height = $ARGV[2] || 600;
my $poster_out = $ARGV[3] || "poster.jpg";

unless ($im_srcdir) {
print "Usage: $0 imagesourcedir [width] [height] [output-filename]\n";
print "width (default: 800), height (default: 600) and output-filename (default: poster.jpg) are optional.\n";
exit;
}

# create a new image with black background
my $poster = Image::Magick->new(magick=>'jpg');
$poster->Set(size=>"$im_width"."x"."$im_height");
$poster->ReadImage('xc:black');

#Get images for tiles
my @imagesfound = `find $im_srcdir -type f -iname '*jpg' -print|grep -v thumbs`;
my @randlist = shuffle(@imagesfound);
my $xpos = 0; # incrementer for x axis
my $ypos = 0; # incrementer for y axis
my $row_total = $im_height / 50; # number of rows
my $col_total = $im_width / 50; # number of columns
my $cnt_tiles = '';

# for each row
while( $ypos < $row_total ){
$xpos = 0;

#for each column
while( $xpos < $im_width ){
# if the random list is all used up, regenerate it
my $cnt_elements = @randlist;
if( $cnt_elements lt 1 ){
@randlist = ();
@randlist = shuffle(@imagesfound);
}

# remove image from random list so it is not reused in this row
my $currimage = pop @randlist;
chomp $currimage;

# open the tile
my $tile = Image::Magick->new(magick=>'jpg');
$tile->ReadImage($currimage);
my $height = $tile->Get('height');
my $width = $tile->Get('width');

#Resize tile to 100x100 and cut off 50x50 (to be sure, that all tiles have the same size)
$tile->Resize(geometry=>'100x100');
$tile->Mogrify('crop', '50x50');

# insert the tile into the existing large template
$poster->Composite(image=>$tile,x=>$xpos,y=>($ypos*50),geometry=>'0,0,50,50');

# increase tile count and stop loop, when we have enough tiles
$cnt_tiles++;
last if (($row_total*$col_total) eq $cnt_tiles);

# move to next column
$xpos += 50;
}

# move to next row
$ypos++;
}

# reduce quality
$poster->Set(quality=>'75');

# write new image
$poster->Write($poster_out);

Kategorien
Uncategorized

WordPress with lighttpd

A few days ago I switched the webserver for schmalenegger.com from Apache2 to lighttpd. Here’s a short guide what needs to be done to get lighttpd running with WordPress:

As I use Debian Etch, I decided to give to lighty packet from the Debian repositories a shot.


apt-get install lighttpd php5-cgi

After installation the webserver needs to be configured. This is done in the file /etc/lighttpd/lighttpd.conf.


#Load the FastCGI-Modul
server.modules = (
"mod_fastcgi",
)

#Configure PHP
fastcgi.server = ( ".php" =>
(
( "bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket",
"min-procs" => 1,
"max-procs" => 3,
"max-load-per-proc" => 3,
"idle-timeout" => 20 )
)
)

That should be sufficient for running WordPress. Just put your WordPress files under the configured server.document-root from lighttpd.conf and point your webbrowser to your domain.

But what about permalinks?

lighttpd has something called conditions. You can also use them for separating different sites from each other on the same server (Virtual-Hosts in Apache), but also Rewrite Rules can be configured there. So first of all make sure, that the Rewrite-module gets loaded from lighty and add mod_rewrite to the list of modules:


server.modules = (
"mod_rewrite",
)

Then configure some conditions (replace the domains with your own)


# Conditions for different sites
$HTTP["host"] =~ "^(www.)?(schmalenegger.com)$" {
server.document-root = "/www/schmalenegger.com/"
accesslog.filename = "/logs/schmalenegger.com-access.log"
url.rewrite-once = (
"^/(wp-.*)$" => "$1",
".*\.(txt|php|xml|js|ico|gif|jpg|png|css|swf)?.*$" => "$0",
"^([^?]*)?(.*)$" => "/index.php$2"
)
}

Kategorien
Uncategorized

Migrating MySQL dumps in default Debian installations

Debian uses a separate user for the maintanance of MySQL. That user is called debian-sys-maint and will be created automatically when you install MySQL. If you accidentally delete that user or import an old dump with the „mysql“ user database, the MySQL init-script will complain with such an error-message:

Access denied for user ‚debian-sys-maint’@’localhost‘ (using password: YES)

In that case you should recreate that user with the following steps:

1. Get the password of the user from /etc/mysql/debian.cnf
2. Login to your mysql-database and execute the following statement (Replace with the real password from the file /etc/mysql/debian.cnf


GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;

Now, everything should be fine again… 🙂

Kategorien
Uncategorized

Duplicated searchresults when using EventCalendar3 in WordPress

If you use the Eventcalendar Plugin in WordPress you may experience duplicated or even more searchresults if a blogpost is in more than one category. To get rid of this problem change the following in eventcalendar3.php:

function ‚ec3_filter_posts_where‘ add the following to the first if statement


|| $wp_query->is_search

It should look like this afterwards:


if($wp_query->is_page || $wp_query->is_single || $wp_query->is_search )

Kategorien
Uncategorized

The Gimp: Making Colors in a GIF Transparent

Sometimes when working with an image you want to make a certain color transparent. When working with a gif file this would make a round circle look round on any color background. This is actually very simple once you do it once. Finding the information for this took me a while so I thought I would pass it on to anyone that was interested.

1. Open the image in gimp

2. Right click the image and go to LAYER then TRANSPARENCY then ADD ALPHA CHANNEL. You won’t notice anything happening, but don’t be concerned. It basically adds a transparent layer at the bottom of your image so when we erase the colors…..it’s shows the transparent layer. Which of course would show whatever was under it on the screen.

3. Right click on the image again and go to SELECT and then down to BY COLOR. A window that is all black opens up. Don’t change any of the settings….just use the defaults for now.

4. Now click on the color in the image you want to be transparent. These colors will now show up outlined.

5. Right click on the image again and go to EDIT and then down to CLEAR. This should now erase the outlined color you just picked from the image and the „transparent gimp checkerbox“ should show through. This is the Gimps way of showing you that section is now transparent.

6. Right click on the image and choose SAVE AS and make sure to save as a GIF file if you want the transparency to work on the web.

Another fun feature that can be used while using the SELECT and BY COLOR ….. instead of hitting CLEAR you can FILL W BG COLOR or the other one FILL W FG COLOR ……….. this allows you to change the colors over the entire image instantly for the particular pixel color you choose to start with. Very fast and fun once you figure this out.

Kategorien
Uncategorized

vimdiff essentials

Change window: Twice Ctrl+W
Scale both windows to the same size: Ctrl+W,=
Put „Diff“ to the other window („diff put“): dp
Get „Diff“ from other window („diff obtain“): do