Tag Archives: Linux

HTTPS in RHEL and PHP in less than 5 minutes !

Enabling HTTPS will give your application an added layer of security. The SSL layer will encrypt all communication that happens between the customer’s browser and your application. In this article, I am not describing things in detail about each security option. This is good enough to get started in most of the cases.

Login to Redhat Linux as user root and run the below commands to install apache ( with ssl support ) and PHP version 5.

#yum install httpd mod_ssl openssl php5
#service httpd restart

You should be able access your server via HTTPS now using the browser like https://yourservername.domain/application/login.php . You are now using a self signed certificate for the server. Your browsers might warn you about this , but it is safe to accept it and continue.

If your server was using HTTP only and you recently upgraded it to HTTPS, Here’s a quick and dirty method in PHP to detect if your users are still using HTTP and redirect them to HTTPS. All you need to do is include this code in the start of your php file.

< ?php
$loginURL="https://yourserver/application/login.php" ;
if($_SERVER['HTTPS']){
echo <<<REDIRECT
Redirecting to ... $loginURL 
<script>
window.location($loginURL);
</script>
REDIRECT;
}
?>

As you see, a little time spent can go great lengths towards securing your website and applications. Feel free to comment. πŸ™‚

SNMP Monitoring using Nagios

Nagios is very good and commonly used monitoring tool for systems and network equipments. It can monitor and report availability statistics as well as provide alerts in case of host or service incidents. I am going to discuss on how to use the SNMP capabilities of Nagios and GNU/Linux to enable monitoring without special agents installed on the hosts.

Usually, Nagios will need you to install NRPE addons to report disk space and so many other updates about the system that need to be monitored. This needs you to install additional software on the target machines which is not always possible/recommended practice. Instead, we are going to use the SNMP software that comes as part of the GNU/Linux OS to provide information for Nagios. I am not going to brief about how to install Nagios and Plugins. You could read that in a beautiful how-to here : http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html

There are two steps in enabling SNMP Monitoring.

Configure SNMP in the host to be monitored.

  • Edit /etc/snmp/snmpd.conf and add one line. ( rocommunity public )
  • Restart snmpd service ( sudo /etc/init.d/snmpd restart )

Configure Nagios to check free RAM in the host via SNMP .
First, add a host entry like this to your .cfg file.

define host {
use linux-server
host_name linuxserver01
alias MyLinuxServer
address 192.168.1.24
}

Now we will add a service to check free RAM

define service{
use generic-service
host_name linuxserver01
service_description Free RAM
check_command snmp_freeram_linux
}

Next, we will define the snmp_freeram_linux command to use snmp_check plugin that comes as part of Nagios Plugins installation.

define command{
command_name  snmp_freeram_linux
command_line /usr/local/nagios/libexec/check_snmp -H $HOSTNAME$ -C public -o .1.3.6.1.4.1.2021.4.11.0
}

After this, restart Nagios. ( sudo /etc/init.d/nagios restart )

You should be now able to see a new service added to host and SNMP getting the data. With some efforts, you would be able to configure SNMP for other operating systems and network equipments too. If you have queries, please let me know. πŸ™‚

Making Ubuntu Better !

Here’s a few things I do just after installing Ubuntu Linux. While this step is not mandatory, it sure makes a lot of good additions to the experience. With these few simple commands, your new Ubuntu system will get lot of additional things that is going to make it feature packed, shinier and a pleasure to use.

Before we start
Having a internet connection is necessary to do these tricks. Before we start, update your system by running the following commands one by one.

sudo apt-get update 
sudo apt-get upgrade

Multimedia
Adding VLC Player, Lots of different codecs for playing variety of Media formats like MP3, MP4 etc is so easy. This command will also install some of the fonts used commonly in Microsoft Office Documents for compatibility. avidemux is a simple but capable Video Editor.

sudo apt-get install vlc ubuntu-restricted-extras avidemux

Graphics Applications
Scribus is a Desktop Publishing Software. InkScape is a Vector Graphics application just like Corel Draw. Gimp could compete well with Photoshop.

sudo apt-get install gimp scribus inkscape

Windows Programs
You want to run Windows Programs in Ubuntu ? Sure. Let’s install Wine. After installing wine, you could just double click any .exe files just like you did earlier to run them. You could even install Windows Software packages on Ubuntu. They will appear under Applications -> Wine -> Programs Menu after installation.

sudo apt-get install wine

Sun Java Support
If any of your programs are not running because Sun Java is not installed or the OpenJDK is not able to run them, install Sun Java.

sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Skype, Acrobat Reader, Flash and lot more..
You want to customize it further and add lots of more softwares like Skype, Acrobat Reader, Google Chrome and much more ? Install Ubuntu Tweak. Download the package and double click on the file to install. Once installed, this tool appears under the Applications menu. There are a huge number of things you could do with this very handy application. For example, if you dont like the “close” button on the left side of your windows, this tool will help you to change it back to the right corner..

For GUI Lovers
All the above apt-get commands can be done via GUI using applications -> software center. Just search for the package name and click install. Like I always say, it’s all about choice. πŸ™‚

Side Note : Some of these commands actually makes you install non-open-source applications or libraries to your system. You have been warned. πŸ™‚

wget & shell scripting for automated downloads

GNU Logo - OpenSouceMy friend Leo came up with this interesting problem. He found a site where a lot of religious videos are hosted for free and he wanted to download them all. The problem is, that the site has a navigation system and you need to click 3 times to go to download page of each video. Considering that the site has about 400 videos to download, this seemed a huge task.

I knew that wget can be used for downloading files from web sites. Checking the download links of 2-3 videos revealed that the videos are stored in a particular folder (http://webserver/folder/ ) inside the webserver. The video links were all like : 1.avi , 2.avi, 3.avi and so on. Then it was all just a matter of minutes to write a small shell script. Here is the code :

#!/bin/bash
counter=0
while (($counter < 450 ));
do
echo Downloading Video $counter..
wget http://webserver/folder/$counter.avi
let counter++
done

echo "Done !"

I saved it as download.sh in my Ubuntu Linux machine and ran it using the below command.
rajesh@ubuntubox:~$ ./download.sh

The script took it's time downloading files one after one .We could do parallel downloads, but that will cause trouble for the web site admins, we are nice people you know πŸ™‚ . Open Source saves the day !

Side Note: if you are using windows, you could probably use cygwin to do this in windows. This script is not perfect, but this did the job for us. One can easily use this as a base for developing it further for other tasks.

Loving Ubuntu !

Installed latest Ubuntu 10.04 on my laptop. For those who don’t know, Ubuntu is a Linux Operating System just like Windows or more than that.

Check out the features of this new version here : http://www.ubuntu.com/desktop/features

In my experience, installation took approximately 20 minutes, asking only 7 very basic questions to me. It includes a few great enhancements to enrich your computer experience.

  • Wireless configuration was a breeze. It found my home wireless automatically and prompted for password. That’s all. I am online withing a few seconds. πŸ™‚ πŸ™‚
  • Software Center application provides access to 32000+ free/open source applications that are ready to be downloaded and installed with a single click. Yes, a single click is all you need. πŸ™‚
  • It contains an update manager that could update all my software including the Operating System with one click. I do not have to keep on downloading security updates, firefox, openoffice or chrome seperately. this cute little application lists all updates in one place where I can click “Update” and it does the rest.

You do not need to partition or install the software to see how it looks. You can experience the Ubuntu magic just by booting from the CD. Try it, and if you like it, join the revolution. πŸ™‚