jump to navigation

linux debian apache2 installing mod-write June 23, 2007

Posted by chris in : linux , add a comment

To install mod-rewrite in debian type a2enmod rewrite from the shell. You will the be asked to restart apache.

A simple mod-write script that blocks anyone from hotlinking to your images would look like this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

You would either place this in an .htaccess file or if you have root access to the server in /etc/apache2/sites-available and then within the directory you want to protect from hotlinking.

php switch/case statements June 18, 2007

Posted by chris in : php , add a comment
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case 1:
    echo "i equals 1";
    break;
case 2:
    echo "i equals 2";
    break;
}

Update: I have a few developers at my work that have a java background and they didn’t know that you can actually include a conditional in your case, cause I guess java doesn’t let you. So for case 1 (in this instance) you could actually have it test against a variable outside the switch so it would read:

$var = 2;
switch ($i)
{
case 0:
    echo "i equals 0";
    break;
case $i == $var:
    echo "i equals 1";
    break;
case $i== $var:
    echo "i equals 2";
    break;
}

I forget where I used this code recently, but it is useful, as it makes your switch more dynamic.

linux random tar stuff June 15, 2007

Posted by chris in : linux , add a comment

This will probably grow as I need tar to do more stuff.

Excluding a directory from your tarball:
tar -cf backup.tar /home –exclude “/home/cpanel”

linux search from shell (grep) June 4, 2007

Posted by chris in : linux , 1 comment so far

find . -name ‘*.*’ | xargs grep -l ’search term’

UPDATE
The gentlemen who replied below is correct in stating that the command below would be easier.

grep -ril 'search_term' *

resize images from linux command line w/ imagemagick June 3, 2007

Posted by chris in : linux, php , add a comment

In debian execute this shell command apt-get install imagemagick

Now to resize images execute convert -size 125×125 /path/to/image.jpg -resize 125×125 /path/to/image.jpg

Ofcourse you can do this in php by executing the shell command using the exec() function.

a backup system – for the poor and lazy June 2, 2007

Posted by chris in : linux, php , add a comment

Well I’ve put enough time and effort into my server configuration, mysql databases, and my web dev files that it was finally time to start backing up. Now I’m not completely crazy, the server does have a 3ware card in it for mirroring, but in the end its still a server in the closet (its not gay) and something bad could happen. So I spent about 2 hours writing a few backup scripts because I’m too poor for rsync and too lazy for amanda.

All you need is a cheap web host like the one I use (about $5 a month) and some time. Here’s what I did:

(more…)