Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.

Linux

adventures in linux printing, set default printer and firefox command line print

Posted by chris on July 23rd, 2009 Comments (2)

We are in the process of redesigning our packing slips that get sent out to customers with each order. The previous developer went with a solution, html2ps, that has shotty support for CSS and design principals in general. The designer and I decided we needed something else. After trying numerous solutions, a co-worker suggested I give FireFox command line print a try.

Read the rest of this entry »

In Linux, Programming (, , , , , , )

Using perror to Help Debug Mysql Errors

Posted by chris on November 4th, 2008 Comments(0)

Print a description for a system error code or an error code from a MyISAM/ISAM/BDB table handler. Example, type “perror 150″ in the linux shell.

1
2
# perror 150
MySQL error code 150: Foreign key constraint is incorrectly formed
In Linux, SQL (, , )

Manage Multiple Shell Sessions with Screen

Posted by chris on May 27th, 2008 Comments(0)

Screen is useful for running a script or other long process as yourself if you are worried about disconnecting from your SSH session or want to do some other things in the shell as the process runs. You will need screen installed to do this. This will really save you a lot of time with Linux servers.

To start a screen session:

screen -R -D

To detatch from the screen session and continue working from the shell:

Ctrl + a + d

To view the status of your screen sessions:

screen -ls

To reattach an existing screen session:

screen -r <i>screen name</i>

You can get the screen name via the screen -ls command, the screen name should look something like 3003.pts-4.localhost.

In Linux ()

APC (Alternative PHP Cache) on Debian Etch

Posted by chris on March 26th, 2008 Comments(0)

This is one of the best packages you can incorporate into your web development. Basically APC allows you to cache data in memory for extremely fast data access. We are exploring writing an application at work the must have extremely fast access to data, so fast that we are willing to dedicate a server with lots of RAM to this application. Are other alternative is to store the data on XML files with small yet very fast disks that spin at high RPMs, with lots of onboard disk cache, most likely a SAS or SCSI disk. This would allow for fairly quick access as the disks would spin fast and be small so seek time etc…

Honestly both servers would come out to within a few hundred dollars of each other. So the memory-based solution utilizing APC in PHP is probably the best. So tonight I installed APC on my home server, a dual core xeon 2.6 Ghz server with 3 GB of RAM, and 4 SCSI disks in RAID 5, with the OS stored on 2 18 GB disks in a mirror. Yes I am a fucking geek. Would’ve like to have done this on my beta server (geek again), but it only has 1 GB of memory and I intend on storing that much data in memory :)

So here is my experience and how to with APC

Read the rest of this entry »

In Linux, Programming (, )

Getting Your SMTP Server White Listed

Posted by chris on March 15th, 2008 Comments(0)

I used to operate a website that requires users to validate accounts. Unfortunately my email server was looked upon as a spam server. Though not blacklisted providers such as AOL and MSN/Hotmail were sending my emails directly to users spam folders. Luckily there are steps you can take to prevent this:

Setup reverse DNS
Contact your ISP about setting up a reverse DNS record. This only takes a couple of minutes but it has the biggest impact on legitimizing your email server. If your ISP is like mine they will have a web based management console that makes the process idiot-proof.

Setup an SPF record
MSN/Hotmail as well as other email provides are big on this one. openSPF has a wizard that creates your SPF record for you. You’re domain registrar should have an option to add this record into your account or you can add it into your BIND or other DNS server.
http://openspf.org/

Contact AOL directly
You can contact AOL directly about getting on their “white list.” I was amazed by their response time, I was on their whitelist within 24 hours.
postmaster.aol.com/

Contact MSN/Hotmail
Microsoft also has great response time.
http://postmaster.live.com/Services.aspx

Other
Make sure your email server is not an open relay. The easiest way to do this is to restrict sending of emails via your server to the localhost and then use a web-based MTA such as squirrelmail or roundcube. Create some test accounts on gmail, yahoo, aol, and msn to see if your emails are going into spam folders. If they are then get in contact with these providers and see what you can do to resolve the issue.

In Linux (, )

Mod-Log-SQL – Storing Apache Access Logs in a MySql Database

Posted by chris on October 27th, 2007 Comments(0)

Mod log sql is an awesome way of getting away from those old log files and is really handy for both web development and system administration. It’s been a while since I’ve posted a blog and this is something I’ve never done before so here we go. If you are ever doing any kind of parsing of your apache access log and run a relatively high traffic website (the one I’m doing this for, mp3crib.com, averages over 5,000 hits a day and some days gets over 10,000) you will begin eating up huge amounts of CPU and memory (if storing the information in an array). Well lately it’s gotten so bad that my PHP script fails due to memory exhaustion. I can’t have that. I heard somewhere that databases are better than flat files, go figure. If I knew a lower level language then I would of course write my parser in that…but I don’t. So luckily libapache2-mod-log-sql exists.
Read the rest of this entry »

In Linux, SQL (, , , )

rsync debian linux

Posted by chris on August 10th, 2007 Comment(1)

Install rsync on the server you want to backup apt-get install rsync

To backup the entire server create a cron job with the following command in it (you can choose how often you'd like it to run yourself if you know how the time syntax in a cronjob, otherwise search the blog for information on crontab):

rsync -a -e ssh / username@10.10.10.10:/path/to/destination/

Since you will be doing this over SSH you will be prompted for a password, but we can't really enter in a password if this is a cronjob. So on the source system and source user that the cron job will run as enter in the following command and when it asks for a password leave it blank, take the default file location:

ssh-keygen -t rsa

Do the same thing on the destination system, but remember to run the command as the user who will be logging in via SSH for the rsync conrjob.

Open ~/.ssh/id_rsa.pub on the source system and create a new file on the destination system called /home/username/.ssh/authorized_keys, copy the line in the id_rsa.pub to the authorized_keys files. Verify you can SSH into destination system from the source system.

This has just made your backup server pretty insecure, but since it is just a backup server you can restrict who can log into the system via SSH to the source computer.

In Linux ()

easy mysql backup

Posted by chris on July 6th, 2007 Comments(0)

Here’s an example of quick script I wrote in PHP and added as a cronjob to backup some mysql databases:

// dump database tables to sql text files //
exec('mysqldump -uroot -pPasswordHere music > /tmp/music.sql');
exec('mysqldump -uroot -pPasswordHere taskfreak > /tmp/taskfreak.sql');
// pack into tarballs //
exec("tar -cf /tmp/music.sql.tar /tmp/music.sql");
exec("tar -cf /tmp/taskfreak.sql.tar /tmp/taskfreak.sql");
// gzip tarballs //
exec("gzip /tmp/music.sql.tar");
exec("gzip /tmp/taskfreak.sql.tar");

In Linux, Programming, SQL ()

linux debian apache2 installing mod-write

Posted by chris on June 23rd, 2007 Comments(0)

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.

In Linux ()

linux random tar stuff

Posted by chris on June 15th, 2007 Comments(0)

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”

In Linux ()