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.
Archive for May, 2007
upgraded debian sarge to etch + 2.6 kernel
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
CronJobs – Creating CronJobs with Crontab in Linux
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 cronjobs use the following shell commands:
crontab -e # edits your users crontab file crontab -u username -e # edits another users crontab
Here is a mock example:
15 3 * * 7 /home/root/backupmymusic.php 15 4 * * 7 /home/root/backupmyimages.php
Here is a link for creating a script to check all users cronjobs.
http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users
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:
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.