#!/bin/sh #auto install LAMP shell #by zkg 2019-06-26
#定义apache变量 H_FILES=httpd-2.4.39.tar.gz H_FILES_DIR=httpd-2.4.39 H_URL=http://mirrors.cnnic.cn/apache/httpd/ H_PREFIX=/usr/local/apache2
#定义MYSQL DB变量 M_FILES=mysql-5.5.33.tar.gz M_FILES_DIR=mysql-5.5.33 M_URL=https://downloads.mysql.com/archives/community/?tpl=files&os=src&version=5.5.33/ M_PREFIX=/usr/local/mysql55
#定义PHP变量 P_FILES=php-7.0.9.tar.gz P_FILES_DIR=php-7.0.9 P_URL=http://php.net/get/php-7.0.9.tar.gz/from/a/mirror P_PREFIX=/usr/local/php7
#一键安装菜单 PS3="Please select Install Menu(1-4):" select MENU in "ApacheWEB服务器安装" "MysqlDB服务器安装" "PHP服务器安装" "LAMP架构整合并启动服务" do #安装apache WEB服务器 case $MENU in ApacheWEB服务器安装) wget -c $H_URL/$H_FILES && tar -xzvf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX if [ $? -eq 0 ];then make && make install echo -e "\033[32mthe $H_FILES_DIR Server Install successfully!\033[0m" else echo -e "\033[32mthe $H_FILES_DIR Server Install Failed,please check...!\033[0m" exit 0 fi ;;
#安装Mysql DB服务器
MysqlDB服务器安装)
wget -c $M_URL/$M_FILES && tar -xzvf $M_FILES && cd $M_FILES_DIR && yum -y install cmake;cmake . -DCMAKE_INSTALL_PREFIX=$M_PREFIX \
-DMYSQL_DATADIR=/data/myql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/data/mysql.sock \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0
cp support-files/my*.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
if [ $? -eq 0 ];then
make && make install
echo -e "\033[32mthe $M_FILES_DIR Server Install successfully!\033[0m"
else
echo -e "\033[32mthe $M_FILES_DIR Make or Make install ERROR,please check...!\033[0m"
exit 0
fi
;;
#安装PHP服务器
PHP服务器安装)
wget -c $P_URL/$P_FILES && tar -xzvf $P_FILES && cd $P_FILES_DIR && ./configure --prefix=$P_PREFIX \
--with-config-file-path=$P_PREFIX/etc \
--with-mysql=$M_PREFIX \
--with-apxs2=$H_PREFIX/apxs
if [ $? -eq 0 ];then
make ZEND_EXTRA_LIBS='-liconv' && make install
echo -e "\033[32mthe $P_FILES_DIR Server Install successfully!\033[0m"
else
echo -e "\033[32mthe $P_FILES_DIR Server Install Failed,please check...!\033[0m"
exit 0
fi
;;
#整合LAMP架构并启动服务
LAMP架构整合并启动服务)
sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' $H_PREFIX/conf/httpd.conf
$H_PREFIX/bin/apachectl restart
echo " AddType application/x-httpd-php .php" >>$H_PREFIX/conf/httpd.conf
IP=`ifconfig eth1|grep "Bcast"|awk '{print $2}'|cut -d: -f2`
echo "you can access http://$IP/"
cat >$H_PREFIX/htdocs/index.php <<EOF <?php phpinfo() ?> EOF ;; esac done