Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Thursday, May 19, 2011

Script to install Apache, PHP and MySql on Ubuntu

Here is a shell script i wrote to download and install LAMP on Ubuntu.


#!/bin/bash

echo "current OS information:"
cat /etc/lsb-release

echo "install patches"
sudo apt-get install update

echo "install apache2 and php5..."
sudo apt-get install apache2 php5 libapache2-mod-php5


echo "create test.php at /var/www/test.php"
echo "" | sudo tee /var/www/test.php

echo "restart apache2"
sudo /etc/init.d/apache2 restart

echo "start firefox to check the test page"
firefox "http://localhost/test.php" &

echo "install mysql"
sudo apt-get install mysql-server mysql-client php5-mysql


echo "install PhpMyAdmin"
sudo apt-get install phpmyadmin

sudo echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf
sudo /etc/init.d/apache2 restart

firefox "http://localhost/phpmyadmin" &

#need to set the default character to gb2312 to support chinese character
#mysql> set names 'gb2312'





Enjoy!

Sunday, February 17, 2008

Config Idle Timeout for openSSH Fedora

With some ssh servers, you can config the time out in /etc/ssh/sshd_config like

IdleTimeOut=10m

However, the openssh shipped with Fedora doesn't support this option.
Two workarounds are:
  • Apply openssh watchdog patch
http://www.sc.isc.tohoku.ac.jp/~hgot/sources/openssh-watchdog.html
  • use TMOUT for shell
In /etc/profile
#set the idle timeout for ssh to 10minutes
TMOUT=600

readonly TMOUT

export TMOUT


Notice here, need to set the TMOUT to readonly, otherwise users can override it.

Saturday, December 15, 2007

Installed Ubuntu 6.1 on my new flash drive today

Installed Ubuntu linux on flashdrive (2G) today.
Thus I can still keep my Fedora on harddisk, and switch back later.

Even better, I can boot and run the popular Ubuntu anywhere as long as i plug-in the flash driver.

What is the difference before Operation System and application software then?

The more we use web apps, such as google doc, salesforce, the less we care about Operation System.

Here is the link to follow

Thursday, December 6, 2007

cannot restore segment prot after reloc: Permission denied

That is SELinux policy problem.

System -> Administration -> Security Level and Firewall -> SELinux Tab. Change
"Enforce" to "Permisive"



Or we can config to only allow this policy
System -> Administration -> Security Level and Firewall-> SELinux tab ->Modify SELinux Policy ->Compatibility -> Allow the use of shared libraries with Text Relocation

Thursday, August 23, 2007

How to find out which process is listening on a port

for example, we want to find out which process is running on port 8005
  • First, use the following command to find if the port is is use or not
    netstat -an |grep 8005


  • Then, use the following command to find which process is using the port
    fuser -n tcp 8005
    the return will be something like '8005/tcp: 9113'.
    it shows pid.


  • After that, we can find the full process information.
    ps -ef |grep 9113



  • In the end. I wrote a script to put all those steps together
    ps_port.sh


    #!/bin/sh
    status=`netstat -an |grep $1`
    if [ "$status" == "" ]; then
    echo "port $1 is free"
    exit
    fi
    ps -ef |grep `fuser -n tcp $1`

    Thursday, August 9, 2007

    editing binary file using VI

    Not using VI as HEX editor for quite long time. nearly forgot how to do it.

    Here are the commands:


    vi ~/myBinary.so
    [esc]:%!xxd
    [esc]:%!xxd -r
    [esc]:wq!

    Sunday, July 22, 2007

    unix shell is still one of my favorite

    unix shell is so easy and powerful, just like vi.
    It is always my favorite.
    the following example shows how to change variable in unix shell to lower case and remove file extension

    for f in *.shp
    do
    #change to lower case
    file_name=`echo $f | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
    #remove file extension to use as table name
    table_name=${file_name%\.*}
    echo "table name: $table_name"
    done<