HOW TO: Installing MySQL on RedHat/CentOS/Amazon Linux in 5 easy steps.

This seems like it should be a really complicated tasks, but once you have done a few it sinks in that this is really simple…


Just run each of the following 5 steps as root.  Answer any questions with the common sense response, and you are done

yum groupinstall “MySQL Database”
/usr/bin/mysql_install_db –user=mysql
service mysqld start
chkconfig mysqld on


Step 1 uses the groupinstall  command to install all of the most common mysql daemons.  This one line eliminates perhaps half a dozen steps.

Step 2 does the initial DB configuration for the software.  You can select the defaults for all most all options, but when it asks about security, say no because we are gonna do it in the next two lines.

Step 3 starts the MySQL server for the first time

Step 4 when run with all the defaults secures your server nicely.

Step 5 is one that lots of  the tutorials miss.  When you reboot your DB server, it would be nice if MySQL ran right? Well this line does that.


If you want to change your server configuration from the default, run this line:

nano /etc/my.cnf

After saving, if you are done restart the MySQL daemon:

service mysqld start

Simple as that, you are done… Any Questions?

HOW TO: How do you redirect all https traffic to http?

There are LOTS of ways to do this.


This is what I do so that I can use the same code in any site’s .htaccess

RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,L]


I like this better than checking for port 443 because sometimes load balancers handle the certificate and encryption then send the information to port 80.   This works in that situation. Of course you can adjust this code to redirect to www.%{SERVER_NAME} if that is your preference.


Of course redirecting all https traffic to http is equally simple by adding a ! or not to the https check and adjusting your target.

RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]



HOW TO: Determine which flavor or version of Linux is installed

If you are working with a Linux or Unix server, you may not even know which operating system release is on the server or even if it is a 32 bit or 64 bit machine. How do you even tell if your server is 32bit or 64bit? Usually this is not too terribly important. Most of the commands just work. However, it can become important when you want to install or upgrade the server software.

Fortunately, getting the OS version and machine information is JUST as simple..

cat /etc/*-release

That one line will work all versions that anyone who needs to read this article will ever run into.*

Debian: /etc/debian_version, /etc/debian_release (rare)
Fedora Core: /etc/fedora-release
Gentoo Linux: /etc/gentoo-release
Mandrake: /etc/mandrake-release
Mandriva/Mandrake Linux: /etc/mandriva-release, /etc/mandrake-release, /etc/mandakelinux-release
Novell Linux Desktop: /etc/nld-release
Red Hat: /etc/redhat-release
Solaris SPARC: /etc/release
Sun JDS: /etc/sun-release
SUSE Linux: /etc/SuSE-release, /etc/novell-release
SUSE Linux ES9: /etc/sles-release
Ubuntu Linux: /etc/lsb-release

This will produce results like:

CentOS release 5.5 (Final)


Red Hat Enterprise Linux Server release 5.4 (Tikanga)


The next thing you need to know is if the kernel you have installed is 64 bit ot 32 bit. You can do that via this command

cat /proc/cpuinfo



Here is an example of a 32bit kernel: (Notice the x86)

Linux version 2.6.18-164.el5PAE ( (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Tue Aug 18 15:59:11 EDT 2009

Here is an example of a 64bit kernel:(Notice the x64)

Linux version 2.6.18-028stab070.5 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Fri Sep 17 15:37:23 MSD 2010

I hope this helps!




If you have built your own server, there is a possility you have to run a slightly different command line as some version use *_version as the file name.

These flavours include:

Red Hat: /etc/redhat_version
Slackware: /etc/slackware-version
Knoppix: knoppix_version

So if the above line produced no results try:

cat /etc/*version

See more examples of these files here on Linux Mafia

HOW TO: Take a quick glance at errors from a project.

PHP records all errors to a file named error_log

I needed to look at the status of a project on two servers to see what errors were being thrown.

This command line shows the top 20 errors and how often they occurred within the last 1000 errors..
tail -1000 error_log | awk -F ‘]’ ‘{print $4}’| sort | uniq -c | sort -nr | head -20

Depending upon the load on your server, that could report on the errors in the last half hour, or across several days. In either case, it will give you a quick idea on where you should clean your code of warnings and notices and where you need to do some fixing… Just remember there’s no time line involved in the report. So the error messages could be from something already fixed.