#!/bin/bash
#author by martin 2015-07-22
#auto install lamp
function apache_install(){
#apache auto install
echo -e "\033[32m prepare apache env \033[0m"
H_FILE=httpd-2.2.31.tar.gz
H_DIR=httpd-2.2.31
yum install apr apr-util apr-devel apr-util-devel -y
cd /usr/src
wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz
tar xf $H_FILE
cd $H_DIR
./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so --with-mpm=worker \
--enable-expires --enable-deflate --enable-headers
make && make install
if [ $? -eq 0 ];then
echo "apache install successful"
fi
exit
}
function mysql_install(){
#mysql auto install
echo -e "\033[32m prepare mysql \033[0m"
M_FILE=mysql-5.1.72.tar.gz
M_DIR=mysql-5.1.72
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
cd /usr/src
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72.tar.gz
tar xf $M_FILE
cd $M_DIR
./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-user=mysql \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/local/mysql/data
if [ $? -eq 0 ];then
make &&make install
fi
if [ $? -eq 0 ];then
echo -e "\033[32mmysql install succefull\033[0m"
/bin/cp support-files/my-small.cnf /etc/my.cnf
/bin/cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cd /usr/local/mysql/
mkdir data
chown mysql.mysql /usr/local/mysql/
./bin/mysql_install_db --user=mysql
exit
fi
}
function php_install(){
#php auto install
echo -e "\033[32m prepare php \033[0m"
P_FILE=php-5.4.22.tar.gz
P_DIR=php-5.4.22
cd /usr/src
wget http://mirrors.sohu.com/php/php-5.4.22.tar.gz
tar xf $P_FILE
cd $P_DIR
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql/ --enable-sockets
if [ $? -eq 0 ];then
echo -e "\033[32m php install successful\033[0m"
fi
make&&make install
/bin/cp /usr/src/php-5.4.22/php.ini-production /usr/local/php5/lib/php.ini
exit
#lamp整合 auto install
echo -e "\033[32m prepare lamp整合 \033[0m"
if [ $1 -eq 4 ];then
sed -i ‘s#DirectoryIndex index.html#DirectoryIndex index.php index.html#g‘ /usr/local/apache2/conf/httpd.conf
echo "AddType application/x-httpd-php .php" >>/usr/local/apache2/conf/httpd.conf
cat > /usr/local/apache2/htdocs/index.php<<EOF
<?php
phpinfo();
?>
EOF
fi
}
case $1 in
apache_install)
apache_install
;;
mysql_install)
mysql_install
;;
php_install)
php_install
;;
*)
echo "usge:sh $0 apache_install|mysql_install|php_install"
;;
esac