I thought I’d do a post about climate change. This is not a believe it or don’t believe it post. I’m just going to list a few things you can do that will help reduce your C02 emissions and save you money. Hopefully at least one of you nerds helps out. I recently changed my outside, hall, stove, and closet lights to 15w fluorescent lights. Might was well (just buy them next time your at the grocery store), who really cares that much about these lights anyways. They last longer than regular bulbs too (5 years) and save on energy bills using 75% less power than a normal bulb does. Sure they cost me $5 a pop, but I won’t have to worry about changing them until 2012. Just do it damnit, there are other things you can do, but I’ll admit that stuff isn’t as easy. Like carpooling, taking the bus, or buying a fuel efficient vehicle. But things like insulating your water heater is easy, saves money, and reduces C02 emissions. Just look over the list, and pick a few
: http://www.climatecrisis.net/takeaction/whatyoucando/index.html
Archive for May, 2007
climate change…i know its not about computers sorry
upgraded debian sarge to etch + 2.6 kernel
Well I’ve been running debian sarge with the 2.4 kernel for a long time and things came to ahead when I was unable to install some pecl and pear packages for some neat stuff I’m doing in PHP. I have a tendency to make drastic decisions. In geekdom upgrading your server to not only a new linux version about the kernel as well in one night is considered drastic…I think. I have lots of important stuff on there too, client files, mysql databases, lots of web content in /var/www and not to mention the countless hours, weeks worth of hours I’ve spent fine tuning it.
linux i discovered umask and sgid for default file/directory permissions
I’ve known for a while that there is a way to set the default group ownership and rwx permissions of files in a directory, but I’ve been content with changing files permission levels on an as needed basis until today.
To set the default file permissions in a directory:
umask 775 /path/to/dir
To set the default group ownership:
chmod g+s /path/to/dir
Here is a good article on file permissions in linux: http://www.linuxforums.org/security/file_permissions.html
linux creating cronjobs with the crontab command
So I needed to setup automated backups poor man style. Since I’m most proficient in PHP I created several PHP scripts that tar, gzip, and ftp my important files to a remote server. I then automated this by adding each script as a cron job to be run every sunday early in the morning. Here’s the crontab syntax:
* * * * * command to be executed - - - - - | | | | | | | | | ----- Day of week (0 - 7) (Sunday=0 or 7) | | | ------- Month (1 - 12) | | --------- Day of month (1 - 31) | ----------- Hour (0 - 23) ------------- Minute (0 - 59)
To edit your cronjobs type crontab -e
Here is a mock example:
15 3 * * 7 /home/root/backupmymusic.php 15 4 * * 7 /home/root/backupmyimages.php
php force redirect from http to https
Here is a quick php script that will force any http connections to https. This assumes that SSL is working properly on your server.
if ($_SERVER['SERVER_PORT']!=443)
{
$url = "https://". $_SERVER['SERVER_NAME'] . ":443".$_SERVER['REQUEST_URI'];
header("Location: $url");
}
setting up ssl for apache2 on debian linux
I needed to setup SSL to increase login security for various web apps I’m running on my server. Luckily I found a good tutorial here. Here’s the process in a nutshell:
php/mysql login authentication the better way
Well I found out from a co-worker the other day then I’ve been authenticating users against a mysql table the bad way. Apparently posting directly to your select query is a big no-no since it can leave you vulnerable to sql injection hacks. So here is the method I am using now. It’s better, but feel free to respond and let me know if there is a better way.
linux using the cat command to append files together
Log rotate recently rotated my logs a little to early so now webalizer is only displaying statistics for the last two days. After changing logrotat to run once a month instead of weekly I wanted to “repair” my apache log files. I always forget how to use the cat command so it became the perfect candidate for a quick article.
file1 – beginning text.
file2 – end text.
cat file1 file2 > newfile
You don’t have to create a new file. You can just append file1 to file2, but I chose this method just incase I messed something up. Here’s exactly what I did: cat access.log.1 access.log > test and once I verified the test file looked good I did a mv test access.log so now I have one giant log file. I then forced webalizer to run and everything looks good now. Since I’m on it, I actually had to copy access.log to access.log.1 to finally get webalizer to see everything I wanted. I forced webalizer to run by executing the /usr/bin/webalizer command on my debian system.
setting up iis7 w/ mysql and php
I recently bought a nice little HP laptop and got a really good deal on it too. It has a dual core pentium, 1gb memory, 120 gb hard drive, and everything else I need. However, it did come with Vista, which meant I needed to get php5 working with iis7 and mysql if i wanted to do an development work on it. Luckily I found this great how to http://blondr.blogspot.com/2006/11/set-up-iis-7-w-mysql-and-php-5.html
php/linux – performing an http post the easy way
It’s been a while since I added anything so here I go. If you have access to execute shell commands and curl is installed on your linux box then this is by far the easiest way to perform an HTTP POST. Here is the simple code:
exec("curl -d \"poststring=true&easy=yes\" http://www.somedomain.com");
Of course you can jazz this up by turning the post string into a variable a long with the url you are posting to. If you add a second parameter to the exec function such as $result then you can easily get a response from the host you are posting too. I came up with this simple method while working on a project at work. I was having problems getting PHPs built-in curl functionality to work, so this was the next best thing or better.