One-click deployment lamp script

1. The script content is written as follows

#!/bin/bash
ip=$(ifconfig | sed -n 2p | awk '{print $2}')
#判断服务器能否访问外网
check_net() {
    
    
    ping -c 2 www.baidu.com > /dev/null 2>&1
    if [ $? -eq 0 ];then
        echo "网络畅通"
    else
        echo "网络不通!!!"
    fi
}
install() {
    
    
    echo "开始安装lamp所需组件"
    yum -y install httpd php php-mysql php-gd mariadb mariadb-server > /dev/null
}
file() {
    
    
    echo "修改Apache配置文件"
    sed -i '164 s/index.html/index.php/' /etc/httpd/conf/httpd.conf
}
index() {
    
    
    echo "创建测试页面"
    echo "<?php phpinfo();?>" > /var/www/html/index.php
}
start_svc() {
    
    
    echo "开启Apache服务"
    systemctl start httpd
    echo "开启mysql服务"
    systemctl start mariadb
}
check_net
install
file
index
start_svc
echo "请访问: http://$ip"

2. Perform the test

[root@host-136 ~]# sh lamp.sh 
网络畅通
开始安装lamp所需组件
修改Apache配置文件
创建测试页面
开启Apache服务
开启mysql服务
请访问: http://192.168.153.136

3. The browser enters the host ip address to successfully access the PHP test page

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46674735/article/details/112535822