Sunday, May 30, 2010

SSH with PHP

I want to create an application that will be able to connect to an SSH server via PHP. I was thinking of using TCL expect and then integrate PHP and the expect script somehow. Fortunately, before I tried that, I did some searching on google and found that there is an SSH wrapper already that can suit my need.

To install the wrapper on Ubuntu, please find the steps below:

1. Install apache and PHP first
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo /etc/init.d/apache2 restart
2. Make sure that the server/computer have a fully qualified domain name (FQDN). Otherwise, apache2 may not be able to start.
sudo vi /etc/hosts
sudo vi /etc/hostname

3. Install the library for ssh wrapper
sudo apt-get install libssh2-1-dev libssh2-php

4. Confirm that ssh has been installed correctly
php -m | grep ssh2

You are expecting to see "ssh2"

5. Finish

Now you can start to write PHP script to connect to an SSH server



Sunday, May 9, 2010

Linux system monitoring command

I was trying to remember what commands I will have to remember when monitoring performance of a Linux server. Luckily, I found this blog and it has the list of the commands.

The explanation and example on the blog is very good. However, it is too long for me as I will only need to recall the command in the future and don't need to many explanation. Therefore, I think it will be good for me if I summarize the command here for my reference in the future.

Here are the tools:
#1: top - Process Activity Command
#2: vmstat - System Activity, Hardware and System Information
#3: w - Find Out Who Is Logged on And What They Are Doing
#4: uptime - Tell How Long The System Has Been Running
#5: ps - Displays The Processes
#6: free - Memory Usage
#7: iostat - Average CPU Load, Disk Activity
#8: sar - Collect and Report System Activity
#9: mpstat - Multiprocessor Usage
#10: pmap - Process Memory Usage
#11 and #12: netstat and ss - Network Statistics
#13: iptraf - Real-time Network Statistics
#14: tcpdump - Detailed Network Traffic Analysis
#15: strace - System Calls
#16: /proc file system - Various Kernel Statistics

Reference : here