shell 自动安装LAMP

LNMP脚本安装示例

通过if语句和变量实现一件安装LAMP环境的脚本:

一键源码安装LAMP脚本, 先分解脚本的各个功能:

打印菜单

1)安装apache WEB服务器

2)安装mysqldb服务器

3)安装php服务器

4)整合LAMP架构并启动服务器

1.Apache服务器安装部署

下载httpd-2.4.46.tar.gz版本 下载URL , 解压 , 进入安装目录 , configgure;make; make install

官网链接地址:https://downloads.apache.org//httpd/httpd-2.4.46.tar.gz

阿里云连接地址:https://mirrors.aliyun.com/apache/httpd/httpd-2.4.46.tar.gz

教程地址:https://help.aliyun.com/knowledge_detail/41114.html

教程地址:https://blog.csdn.net/helloworld19970916/article/details/81059299

2.mysql服务器安装

下载 mysql-5.7.23.tar.gz 版本, 下载URL , 解压, 进入安装目录 , configure;make;make install

链接地址:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.23.tar.gz

搜狐连接地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.23.tar.gz

 

3.PHP服务器安装

下载 php-7.4.9.tar.gz版本 下载URL , 解压 , 进入安装目录 , configure;make; make install

连接地址:https://www.php.net/distributions/php-7.4.9.tar.gz

搜狐链接地址:http://mirrors.sohu.com/php/php-7.4.9.tar.gz

4.LAMP架构的整合和服务器启动

/usr/local/apache2/bin/apachectl start

Vim htdocs/index.php

<?php

phpinfo();

?>

一、在/data/shell/下新建auto_lamp.sh

 
#!/bin/bash
#auto install LAMP
#by dxw 2020-10-4

#httpd define path variable
H_FILES=httpd-2.4.46.tar.gz
H_FILES_DIR=httpd-2.4.46
H_URL=https://mirrors.aliyun.com/apache/httpd
H_PREFIX=/usr/local/apache2

#mysql define path variable
M_FILES=mysql-5.7.23.tar.gz
M_FILES_DIR=mysql-5.7.23
M_URL=https://cdn.mysql.com/archives/mysql-5.7
M_PREFIX=/usr/local/mysql5.7

#php define path variable
P_FILES=php-7.4.9.tar.gz
P_FILES_DIR=php-7.4.9
P_URL=http://mirrors.sohu.com/php
P_PREFIX=/usr/local/php7


echo -e '\033[32m----------------------------------------------033[0m'
echo
if [ -z "$1" ];then
	echo -e "\033[36mplease Select install Menu follow:\033[0m"
	echo -e "\033[32m1)编译安装Apache服务器\033[1m"
	echo "2)编译安装MySQL服务器"
	echo "3)编译安装PHP服务器"
	echo "4)配置index.php并启动LAMP服务"
	echo -e "\033[31mUsage: { /bin/sh $o 1|2|3|4|help}\033[0m"
	exit
fi

if [[ "$1" -eq "help"  ]];then
        echo -e "\033[36mplease Select install Menu follow:\033[0m"
        echo -e "\033[32m1)编译安装Apache服务器\033[1m"
        echo "2)编译安装MySQL服务器"
        echo "3)编译安装PHP服务器"
        echo "4)配置index.php并启动LAMP服务"
        echo -e "\033[31mUsage: { /bin/sh $o 1|2|3|4|help}\033[0m"
        exit
fi

#################################################
#Install httpd web server
if [[ "$1" -eq "1"  ]];then
	mkdir -p $H_PREFIX
        wget -c $H_URL/$H_FILES && tar -zxf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX
	if [ $? -eq 0 ];then
		make && make install
		echo -e "\n\033[32m--------------------------------------------------\033[0m" 
		echo -e "\033[32mThe $H_FILES_DIR Server Install Success !\033[0m"
	else	
		echo -e "\033[32mThe $H_FILES_DIR Make or Make install ERROR, Please check.....\033[0m"
		exit 0
	fi
fi
#Install MySQL DB server
if [[ "$1" -eq "2"  ]];then
        mkdir -p $M_PREFIX
        wget -c $M_URL/$M_FILES && tar -zxvf $M_FILES && cd $M_FILES_DIR && ./configure --prefix=$M_PREFIX
        if [ $? -eq 0 ];then
                make && make install
                echo -e "\n\033[32m--------------------------------------------------\033[0m" 
                echo -e "\033[32mThe $M_FILES_DIR Server Install Success !\033[0m"
        else    
                echo -e "\033[32mThe $M_FILES_DIR Make or Make install ERROR, Please check.....\033[0m"
                exit 0
        fi
fi
#Install PHP server
if [[ "$1" -eq "3"  ]];then
        mkdir -p $P_PREFIX
        wget -c $P_URL/$P_FILES && tar -zxvf $P_FILES && cd $P_FILES_DIR && ./configure --prefix=$P_PREFIX
        if [ $? -eq 0 ];then
                make && make install
                echo -e "\n\033[32m--------------------------------------------------\033[0m" 
                echo -e "\033[32mThe $P_FILES_DIR Server Install Success !\033[0m"
        else
                echo -e "\033[32mThe $P_FILES_DIR Make or Make install ERROR, Please check.....\033[0m"
                exit 0
        fi
fi
if [[ "$1" -eq "4" ]];then
        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 ens33| grep "Bcast"| awk '{print $2}' | cut -d: -f2
        echo "you can access http://$ip/"
cat >$H_PREFIX/htdocs/index.php <<EOF
<?
        php.info();
?>
EOF
fi

  其他的可以在上面扩展 , 这里只提供思路

 
posted @ 2020-11-06 00:58  白色的番茄  阅读(199)  评论(0编辑  收藏  举报