27. 第21章 实现LAMP架构

一.一键搭建wordpress博客网站

[root@centos7 ~]# cat install_mysql_httpd_php_wordpress.sh 
#!/bin/bash
#
#*********************************************************************************************
#Author:        zhanghui
#QQ:            19661891
#Date:          2021-03-03
#FileName:      install_mysql_httpd_php_wordpress.sh
#URL:           www.cnblogs.com/neteagles
#Description:   install_mysql_httpd_php_wordpress for centos 7/8 & ubuntu 18.04/20.04
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
SRC_DIR=/usr/local/src
COLOR="echo -e \\033[01;31m"
END='\033[0m'

MYSQL_URL=https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-
MYSQL_VERSION='8.0/'
MYSQL_FILE='mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz'
MYSQL_ROOT_PASSWORD=123456

APR_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_FILE=apr-1.7.0.tar.gz
APR_UTIL_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_UTIL_FILE=apr-util-1.6.1.tar.gz
HTTPD_URL=https://mirrors.cloud.tencent.com/apache/httpd/
HTTPD_FILE=httpd-2.4.48.tar.gz
HTTPD_INSTALL_DIR=/apps/httpd
MPM=event
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`

PHP='php-7.4.15.tar.xz'
PHP_INSTALL_DIR=/apps/php74

SERVERNAME=blog.neteagles.vip

APP='wordpress-5.7.2-zh_CN.tar.gz'
WEB_DIR=/data/www
MYSQL_WORDPRESS_PASSWORD=123456

${COLOR}'开始安装基于LAMP的wordpress'${END}
sleep 3

os(){
    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release;then
        rpm -q redhat-lsb-core &> /dev/null || { ${COLOR}"安装lsb_release工具"${END};yum -y install  redhat-lsb-core &> /dev/null; }
    fi
    OS_ID=`lsb_release -is`
    OS_RELEASE_VERSION=`lsb_release -rs |awk -F'.' '{print $1}'`
}

check_file (){
    cd  ${SRC_DIR}
    ${COLOR}"请将\"${PHP}和${APP}\"软件放在\"${SRC_DIR}\"目录下,如果没有放好软件包,请按ctrl+c退出"${END}
    sleep 10
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        rpm -q wget &> /dev/null || yum -y install wget &> /dev/null
    fi
    if [ !  -e ${MYSQL_FILE} ];then
        ${COLOR}"缺少${MYSQL_FILE}文件"${END}
        ${COLOR}'开始下载MYSQL二进制安装包'${END}
	    wget ${MYSQL_URL}${MYSQL_VERSION}${MYSQL_FILE} || { ${COLOR}"MYSQL二进制安装包下载失败"${END}; exit; }
    else
        ${COLOR}"${MYSQL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_FILE} ];then
        ${COLOR}"缺少${APR_FILE}文件"${END}
        ${COLOR}"开始下载${APR_FILE}源码包"${END}
        wget ${APR_URL}${APR_FILE} || { ${COLOR}"下载${APR_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_UTIL_FILE} ];then
        ${COLOR}"缺少${APR_UTIL_FILE}文件"${END}
        ${COLOR}"开始下载${APR_UTIL_FILE}源码包"${END}
        wget ${APR_UTIL_URL}${APR_UTIL_FILE} || { ${COLOR}"下载${APR_UTIL_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_UTIL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${HTTPD_FILE} ];then
        ${COLOR}"缺少${HTTPD_FILE}文件"${END}
        ${COLOR}"开始下载${HTTPD_FILE}源码包"${END} 
        wget ${HTTPD_URL}${HTTPD_FILE} || { ${COLOR}"下载${HTTPD_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${HTTPD_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${PHP} ];then
        ${COLOR}"缺少${PHP}文件"${END}
        exit
    elif [ ! -e ${APP} ];then
        ${COLOR}"缺少${APP}文件"${END}
        exit
    else
        ${COLOR}"相关文件已准备好"${END}
    fi
}

install_mysql(){
    [ -d /usr/local/mysql ] && { ${COLOR}"MySQL数据库已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装MySQL数据库..."${END}
    ${COLOR}'开始安装MYSQL依赖包'${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper ncurses-compat-libs &> /dev/null
    elif [[ ${OS_RELEASE_VERSION} == 7 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper &> /dev/null
    else
        apt update &> /dev/null;apt -y install numactl libaio-dev libtinfo5 &> /dev/null
    fi
    cd  ${SRC_DIR}
    tar xf ${MYSQL_FILE} -C /usr/local/
    MYSQL_DIR=`echo ${MYSQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    ln -s  /usr/local/${MYSQL_DIR} /usr/local/mysql
    id mysql &> /dev/null || { useradd -s /sbin/nologin -r  mysql ; ${COLOR}"创建mysql用户"${END}; }
    chown -R  mysql.mysql /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
    .  /etc/profile.d/mysql.sh
    cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    [ -d /data/mysql ] || mkdir -p /data/mysql &> /dev/null
    chown -R  mysql.mysql /data/mysql
    mysqld --initialize --user=mysql --datadir=/data/mysql 
    cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        chkconfig --add mysqld
    else
        update-rc.d -f mysqld defaults
    fi
    cat > /lib/systemd/system/mysqld.service <<-EOF
[Unit]
Description=mysql database server
After=network.target

[Service]
Type=notify
PrivateNetwork=false
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d//mysqld stop
ExecReload=/etc/init.d/mysqld reload

[Install]
WantedBy=multi-user.target
Alias=mysqld.service
EOF
    systemctl daemon-reload
    systemctl enable --now mysqld &> /dev/null
    [ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; }
    MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
    mysqladmin  -uroot -p${MYSQL_OLDPASSWORD} password ${MYSQL_ROOT_PASSWORD} &>/dev/null
    ${COLOR}"MySQL数据库安装完成"${END}
}

install_httpd(){
    [ -d ${HTTPD_INSTALL_DIR} ] && { ${COLOR}"Httpd已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装Httpd"${END}
    ${COLOR}"开始安装Httpd依赖包"${END}
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make pcre-devel openssl-devel expat-devel wget bzip2 &> /dev/null
    else
        apt update&> /dev/null
        apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev wget &> /dev/null
    fi
    cd ${SRC_DIR}
    tar xf ${APR_FILE} && tar xf ${APR_UTIL_FILE} && tar xf ${HTTPD_FILE}
    APR_FILE_DIR=`echo ${APR_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    APR_UTIL_FILE_DIR=`echo ${APR_UTIL_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    HTTPD_FILE_DIR=`echo ${HTTPD_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    mv ${APR_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr
    mv ${APR_UTIL_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr-util
    cd ${HTTPD_FILE_DIR}
    ./configure --prefix=${HTTPD_INSTALL_DIR} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=${MPM}
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && $COLOR"Httpd编译安装成功"$END ||  { $COLOR"Httpd编译安装失败,退出!"$END;exit; }
    id apache &> /dev/null || { useradd -s /sbin/nologin -r  apache ; ${COLOR}"创建apache用户"${END}; }
    sed -i 's/daemon/apache/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo "PATH=${HTTPD_INSTALL_DIR}/bin:$PATH" > /etc/profile.d/http24.sh
    . /etc/profile.d/http24.sh
    cat > /lib/systemd/system/httpd.service <<-EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=${HTTPD_INSTALL_DIR}/bin/apachectl start
ExecReload=${HTTPD_INSTALL_DIR}/bin/apachectl graceful
ExecStop=${HTTPD_INSTALL_DIR}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
    ${COLOR}"开始设置HTTPD配置文件"${END}
    sed -i.bak -e 's@#LoadModule proxy_module.*@LoadModule proxy_module modules/mod_proxy.so@' -e 's@#LoadModule proxy_fcgi_module.*@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@' -e 's/    DirectoryIndex.*/    DirectoryIndex index.php index.html/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'AddType application/x-httpd-php .php' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'ProxyRequests Off' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    mkdir ${HTTPD_INSTALL_DIR}/conf.d 
    echo 'Include conf.d/*.conf' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    cat > ${HTTPD_INSTALL_DIR}/conf.d/vhost.conf <<-EOF
<virtualhost *:80>
servername ${SERVERNAME}
documentroot ${WEB_DIR}
<directory ${WEB_DIR}>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)\$ fcgi://127.0.0.1:9000${WEB_DIR}/\$1
ProxyPassMatch ^/(fpm_sddtatus|ping)\$ fcgi://127.0.0.1:9000/\$1
CustomLog "logs/access_wordpress_log" common
</virtualhost>
EOF
    systemctl daemon-reload
    systemctl enable --now httpd &> /dev/null
    systemctl is-active httpd &> /dev/null ||  { ${COLOR}"httpd 启动失败,退出!"${END} ; exit; }
    ${COLOR}"httpd安装完成"${END}
}

install_php (){
    ${COLOR}"开始安装PHP"${END}
    ${COLOR}"开始安装PHP依赖包"${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        cat > /etc/yum.repos.d/PowerTools.repo <<-EOF
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.cloud.tencent.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/8/PowerTools/x86_64/os/
        http://mirrors.163.com/centos/8/PowerTools/x86_64/os/
        http://mirrors.sohu.com/centos/8/PowerTools/x86_64/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
    fi
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel &> /dev/null
    else
        apt update &> /dev/null;apt -y install gcc make openssl pkg-config libssl-dev libsqlite3-dev libonig-dev curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev &> /dev/null 
    fi
    cd ${SRC_DIR}
    tar xf ${PHP}
    PHP_DIR=`echo ${PHP}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    cd ${PHP_DIR}
    ./configure --prefix=${PHP_INSTALL_DIR} --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && ${COLOR}"PHP编译安装成功"${END} ||  { ${COLOR}"PHP编译安装失败,退出!"${END};exit; }
    echo 'PATH=$PHP_INSTALL_DIR/bin:$PATH' >/etc/profile.d/lamp.sh
    . /etc/profile.d/lamp.sh
    cp php.ini-production  /etc/php.ini
    cp sapi/fpm/php-fpm.service /lib/systemd/system/
    cd ${PHP_INSTALL_DIR}/etc
    cp php-fpm.conf.default  php-fpm.conf
    cd php-fpm.d/
    cp www.conf.default www.conf
    sed -i.bak -e 's/^user.*/user = apache/' -e 's/^group.*/group = apache/' -e 's/#pm.status_path =.*/pm.status_path = \/fpm_status/' -e 's/#ping.path =.*/ping.path = \/ping/' ${PHP_INSTALL_DIR}/etc/php-fpm.d/www.conf
    mkdir /etc/php.d/
    cat > /etc/php.d/opcache.ini <<-EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF
    systemctl daemon-reload
    systemctl enable --now php-fpm &> /dev/null 
    systemctl is-active  php-fpm &> /dev/null ||  { ${COLOR}"PHP-FPM 启动失败,退出!"${END} ; exit; }
    $COLOR"PHP安装完成"${END}
}

install_wordpress(){
    ${COLOR}"开始安装WORDPRESS"${END}
    cd ${SRC_DIR}
    tar xf ${APP}  
    [ -d ${WEB_DIR} ] || mkdir -p ${WEB_DIR}
    mv wordpress/* ${WEB_DIR}/
    chown -R apache.apache ${WEB_DIR}/wp-content/
    cd ${WEB_DIR}
    mv wp-config-sample.php wp-config.php
    mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "create database wordpress;create user wordpress@'127.0.0.1' identified by '${MYSQL_WORDPRESS_PASSWORD}';grant all on wordpress.* to wordpress@'127.0.0.1';" &>/dev/null
    sed -i.bak -e 's/database_name_here/wordpress/' -e 's/username_here/wordpress/' -e 's/password_here/'''${MYSQL_WORDPRESS_PASSWORD}'''/' -e 's/localhost/127.0.0.1/'  wp-config.php
    ${COLOR}"WORDPRESS安装完成"${END}
}

main(){
    os
    check_file
    install_mysql
    install_httpd
    install_php
    install_wordpress
}

main

[root@centos7 ~]# bash install_mysql_httpd_php_wordpress.sh

#在windows系统C:\Windows\System32\drivers\etc\hosts文件里添加
10.0.0.7 blog.neteagles.vip  #IP地址为你本地主机的IP

http://blog.neteagles.vip/

二.一键搭建discuz论坛

[root@centos7 ~]# cat install_mysql_httpd_php_discuz.sh
#!/bin/bash
#
#*********************************************************************************************
#Author:        zhanghui
#QQ:            19661891
#Date:          2021-03-03
#FileName:      install_mysql_httpd_php_discuz.sh
#URL:           www.cnblogs.com/neteagles
#Description:   install_mysql_httpd_php_discuz for centos 7/8 & ubuntu 18.04/20.04
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
SRC_DIR=/usr/local/src
COLOR="echo -e \\033[01;31m"
END='\033[0m'

MYSQL_URL=https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-
MYSQL_VERSION='8.0/'
MYSQL_FILE='mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz'
MYSQL_ROOT_PASSWORD=123456

APR_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_FILE=apr-1.7.0.tar.gz
APR_UTIL_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_UTIL_FILE=apr-util-1.6.1.tar.gz
HTTPD_URL=https://mirrors.cloud.tencent.com/apache/httpd/
HTTPD_FILE=httpd-2.4.48.tar.gz
HTTPD_INSTALL_DIR=/apps/httpd
MPM=event
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`

PHP='php-7.4.15.tar.xz'
PHP_INSTALL_DIR=/apps/php74

SERVERNAME=forum.neteagles.vip

APP='Discuz_X3.4_SC_UTF8_20210320.zip'
WEB_DIR=/data/www
MYSQL_DISCUZ_PASSWORD=123456

${COLOR}'开始安装基于LAMP的DISCUZ'${END}
sleep 3

os(){
    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release;then
        rpm -q redhat-lsb-core &> /dev/null || { ${COLOR}"安装lsb_release工具"${END};yum -y install  redhat-lsb-core &> /dev/null; }
    fi
    OS_ID=`lsb_release -is`
    OS_RELEASE_VERSION=`lsb_release -rs |awk -F'.' '{print $1}'`
}

check_file (){
    cd  ${SRC_DIR}
    ${COLOR}"请将\"${PHP}和${APP}\"软件放在\"${SRC_DIR}\"目录下,如果没有放好软件包,请按ctrl+c退出"${END}
    sleep 10
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        rpm -q wget &> /dev/null || yum -y install wget &> /dev/null
    fi
    if [ ! -e ${MYSQL_FILE} ];then
        ${COLOR}"缺少${MYSQL_FILE}文件"${END}
        ${COLOR}'开始下载MYSQL二进制安装包'${END}
        wget ${MYSQL_URL}${MYSQL_VERSION}${MYSQL_FILE} || { ${COLOR}"MYSQL二进制安装包下载失败"${END}; exit; }
    else
        ${COLOR}"${MYSQL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_FILE} ];then
        ${COLOR}"缺少${APR_FILE}文件"${END}
        ${COLOR}"开始下载${APR_FILE}源码包"${END}
        wget ${APR_URL}${APR_FILE} || { ${COLOR}"下载${APR_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_UTIL_FILE} ];then
        ${COLOR}"缺少${APR_UTIL_FILE}文件"${END}
        ${COLOR}"开始下载${APR_UTIL_FILE}源码包"${END}
        wget ${APR_UTIL_URL}${APR_UTIL_FILE} || { ${COLOR}"下载${APR_UTIL_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_UTIL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${HTTPD_FILE} ];then
        ${COLOR}"缺少${HTTPD_FILE}文件"${END}
        ${COLOR}"开始下载${HTTPD_FILE}源码包"${END} 
        wget ${HTTPD_URL}${HTTPD_FILE} || { ${COLOR}"下载${HTTPD_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${HTTPD_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${PHP} ];then
        ${COLOR}"缺少${PHP}文件"${END}
        exit
    elif [ ! -e ${APP} ];then
        ${COLOR}"缺少${APP}文件"${END}
        exit
    else
        ${COLOR}"相关文件已准备好"${END}
    fi
}

install_mysql(){
    [ -d /usr/local/mysql ] && { ${COLOR}"MySQL数据库已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装MySQL数据库..."${END}
    ${COLOR}'开始安装MYSQL依赖包'${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper ncurses-compat-libs &> /dev/null
    elif [[ ${OS_RELEASE_VERSION} == 7 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper &> /dev/null
    else
        apt update &> /dev/null;apt -y install numactl libaio-dev libtinfo5 &> /dev/null
    fi
    cd  ${SRC_DIR}
    tar xf ${MYSQL_FILE} -C /usr/local/
    MYSQL_DIR=`echo ${MYSQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    ln -s  /usr/local/${MYSQL_DIR} /usr/local/mysql
    id mysql &> /dev/null || { useradd -s /sbin/nologin -r  mysql ; ${COLOR}"创建mysql用户"${END}; }
    chown -R  mysql.mysql /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
    .  /etc/profile.d/mysql.sh
    cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    [ -d /data/mysql ] || mkdir -p /data/mysql &> /dev/null
    chown -R  mysql.mysql /data/mysql
    mysqld --initialize --user=mysql --datadir=/data/mysql 
    cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        chkconfig --add mysqld
    else
        update-rc.d -f mysqld defaults
    fi
    cat > /lib/systemd/system/mysqld.service <<-EOF
[Unit]
Description=mysql database server
After=network.target

[Service]
Type=notify
PrivateNetwork=false
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d//mysqld stop
ExecReload=/etc/init.d/mysqld reload

[Install]
WantedBy=multi-user.target
Alias=mysqld.service
EOF
    systemctl daemon-reload
    systemctl enable --now mysqld &> /dev/null
    [ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; }
    MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
    mysqladmin  -uroot -p${MYSQL_OLDPASSWORD} password ${MYSQL_ROOT_PASSWORD} &>/dev/null
    ${COLOR}"MySQL数据库安装完成"${END}
}

install_httpd(){
    [ -d ${HTTPD_INSTALL_DIR} ] && { ${COLOR}"Httpd已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装Httpd"${END}
    ${COLOR}"开始安装Httpd依赖包"${END}
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make pcre-devel openssl-devel expat-devel wget bzip2 &> /dev/null
    else
        apt update&> /dev/null
        apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev wget &> /dev/null
    fi
    cd ${SRC_DIR}
    tar xf ${APR_FILE} && tar xf ${APR_UTIL_FILE} && tar xf ${HTTPD_FILE}
    APR_FILE_DIR=`echo ${APR_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    APR_UTIL_FILE_DIR=`echo ${APR_UTIL_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    HTTPD_FILE_DIR=`echo ${HTTPD_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    mv ${APR_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr
    mv ${APR_UTIL_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr-util
    cd ${HTTPD_FILE_DIR}
    ./configure --prefix=${HTTPD_INSTALL_DIR} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=${MPM}
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && $COLOR"Httpd编译安装成功"$END ||  { $COLOR"Httpd编译安装失败,退出!"$END;exit; }
    id apache &> /dev/null || { useradd -s /sbin/nologin -r  apache ; ${COLOR}"创建apache用户"${END}; }
    sed -i 's/daemon/apache/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo "PATH=${HTTPD_INSTALL_DIR}/bin:$PATH" > /etc/profile.d/http24.sh
    . /etc/profile.d/http24.sh
    cat > /lib/systemd/system/httpd.service <<-EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=${HTTPD_INSTALL_DIR}/bin/apachectl start
ExecReload=${HTTPD_INSTALL_DIR}/bin/apachectl graceful
ExecStop=${HTTPD_INSTALL_DIR}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
    ${COLOR}"开始设置Httpd配置文件"${END}
    sed -i.bak -e 's@#LoadModule proxy_module.*@LoadModule proxy_module modules/mod_proxy.so@' -e 's@#LoadModule proxy_fcgi_module.*@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@' -e 's/    DirectoryIndex.*/    DirectoryIndex index.php index.html/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'AddType application/x-httpd-php .php' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'ProxyRequests Off' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    mkdir ${HTTPD_INSTALL_DIR}/conf.d 
    echo 'Include conf.d/*.conf' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    cat > ${HTTPD_INSTALL_DIR}/conf.d/vhost.conf <<-EOF
<virtualhost *:80>
servername ${SERVERNAME}
documentroot ${WEB_DIR}
<directory ${WEB_DIR}>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)\$ fcgi://127.0.0.1:9000${WEB_DIR}/\$1
ProxyPassMatch ^/(fpm_sddtatus|ping)\$ fcgi://127.0.0.1:9000/\$1
CustomLog "logs/access_discuz_log" common
</virtualhost>
EOF
    systemctl daemon-reload
    systemctl enable --now httpd &> /dev/null
    systemctl is-active httpd &> /dev/null ||  { ${COLOR}"httpd 启动失败,退出!"${END} ; exit; }
    ${COLOR}"httpd安装完成"${END}
}

install_php (){
    ${COLOR}"开始安装PHP"${END}
    ${COLOR}"开始安装PHP依赖包"${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        cat > /etc/yum.repos.d/PowerTools.repo <<-EOF
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.cloud.tencent.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/8/PowerTools/x86_64/os/
        http://mirrors.163.com/centos/8/PowerTools/x86_64/os/
        http://mirrors.sohu.com/centos/8/PowerTools/x86_64/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
    fi
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel &> /dev/null
    else
        apt update &> /dev/null;apt -y install gcc make openssl pkg-config libssl-dev libsqlite3-dev libonig-dev curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev &> /dev/null 
    fi
    cd ${SRC_DIR}
    tar xf ${PHP}
    PHP_DIR=`echo ${PHP}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    cd ${PHP_DIR}
    ./configure --prefix=${PHP_INSTALL_DIR} --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && ${COLOR}"PHP编译安装成功"${END} ||  { ${COLOR}"PHP编译安装失败,退出!"${END};exit; }
    echo 'PATH=$PHP_INSTALL_DIR/bin:$PATH' >/etc/profile.d/lamp.sh
    . /etc/profile.d/lamp.sh
    cp php.ini-production  /etc/php.ini
    cp sapi/fpm/php-fpm.service /lib/systemd/system/
    cd ${PHP_INSTALL_DIR}/etc
    cp php-fpm.conf.default  php-fpm.conf
    cd php-fpm.d/
    cp www.conf.default www.conf
    sed -i.bak -e 's/^user.*/user = apache/' -e 's/^group.*/group = apache/' -e 's/#pm.status_path =.*/pm.status_path = \/fpm_status/' -e 's/#ping.path =.*/ping.path = \/ping/' ${PHP_INSTALL_DIR}/etc/php-fpm.d/www.conf
    mkdir /etc/php.d/
    cat > /etc/php.d/opcache.ini <<-EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF
    systemctl daemon-reload
    systemctl enable --now php-fpm &> /dev/null 
    systemctl is-active  php-fpm &> /dev/null ||  { ${COLOR}"PHP-FPM 启动失败,退出!"${END} ; exit; }
    $COLOR"PHP安装完成"${END}
}

install_discuz(){
    ${COLOR}"开始安装DISCUZ"${END}
    cd ${SRC_DIR}
    rpm -q unzip &> /dev/null || yum -y install unzip &> /dev/null
    unzip ${APP} &> /dev/null  
    [ -d ${WEB_DIR} ] || mkdir -p ${WEB_DIR}
    mv upload/* ${WEB_DIR}/
    setfacl -R -m u:apache:rwx ${WEB_DIR}
    mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "create database ultrax;create user ultrax@'127.0.0.1' identified by '${MYSQL_DISCUZ_PASSWORD}';grant all on ultrax.* to ultrax@'127.0.0.1';" &>/dev/null
    ${COLOR}"DISCUZ安装完成"${END}
}

main(){
    os
    check_file
    install_mysql
    install_httpd
    install_php
    install_discuz
}

main

[root@centos7 ~]# bash install_mysql_httpd_php_discuz.sh

#在windows系统C:\Windows\System32\drivers\etc\hosts文件里添加
10.0.0.8 froum.neteagles.vip  #IP地址为你本地主机的IP

http://forum.neteagles.vip/

三.一键搭建phpMyAdmin

[root@centos7 ~]# cat install_mysql_httpd_php_phpmyadmin.sh 
#!/bin/bash
#
#*********************************************************************************************
#Author:        zhanghui
#QQ:            19661891
#Date:          2021-03-03
#FileName:      install_mysql_httpd_php_phpmyadmin.sh
#URL:           www.cnblogs.com/neteagles
#Description:   install_mysql_httpd_php_phpmyadmin for centos 7/8 & ubuntu 18.04/20.04
#Copyright (C): 2021 All rights reserved
#********************************************************************************************
SRC_DIR=/usr/local/src
COLOR="echo -e \\033[01;31m"
END='\033[0m'

MYSQL_URL=https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-
MYSQL_VERSION='8.0/'
MYSQL_FILE='mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz'
MYSQL_ROOT_PASSWORD=123456

APR_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_FILE=apr-1.7.0.tar.gz
APR_UTIL_URL=https://mirrors.cloud.tencent.com/apache/apr/
APR_UTIL_FILE=apr-util-1.6.1.tar.gz
HTTPD_URL=https://mirrors.cloud.tencent.com/apache/httpd/
HTTPD_FILE=httpd-2.4.48.tar.gz
HTTPD_INSTALL_DIR=/apps/httpd
MPM=event
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`

PHP='php-7.4.15.tar.xz'
PHP_INSTALL_DIR=/apps/php74

SERVERNAME=phpmyadmin.neteagles.vip

APP='phpMyAdmin-5.1.0-all-languages.zip'
WEB_DIR=/data/www

${COLOR}'开始安装基于LAMP的PHPMYADMIN'${END}
sleep 3

os(){
    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release;then
        rpm -q redhat-lsb-core &> /dev/null || { ${COLOR}"安装lsb_release工具"${END};yum -y install  redhat-lsb-core &> /dev/null; }
    fi
    OS_ID=`lsb_release -is`
    OS_RELEASE_VERSION=`lsb_release -rs |awk -F'.' '{print $1}'`
}

check_file (){
    cd  ${SRC_DIR}
    ${COLOR}"请将\"${PHP}和${APP}\"软件放在\"${SRC_DIR}\"目录下,如果没有放好软件包,请按ctrl+c退出"${END}
    sleep 10
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        rpm -q wget &> /dev/null || yum -y install wget &> /dev/null
    fi
    if [ ! -e ${MYSQL_FILE} ];then
        ${COLOR}"缺少${MYSQL_FILE}文件"${END}
        ${COLOR}'开始下载MYSQL二进制安装包'${END}
        wget ${MYSQL_URL}${MYSQL_VERSION}${MYSQL_FILE} || { ${COLOR}"MYSQL二进制安装包下载失败"${END}; exit; }
    else
        ${COLOR}"${MYSQL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_FILE} ];then
        ${COLOR}"缺少${APR_FILE}文件"${END}
        ${COLOR}"开始下载${APR_FILE}源码包"${END}
        wget ${APR_URL}${APR_FILE} || { ${COLOR}"下载${APR_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${APR_UTIL_FILE} ];then
        ${COLOR}"缺少${APR_UTIL_FILE}文件"${END}
        ${COLOR}"开始下载${APR_UTIL_FILE}源码包"${END}
        wget ${APR_UTIL_URL}${APR_UTIL_FILE} || { ${COLOR}"下载${APR_UTIL_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${APR_UTIL_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${HTTPD_FILE} ];then
        ${COLOR}"缺少${HTTPD_FILE}文件"${END}
        ${COLOR}"开始下载${HTTPD_FILE}源码包"${END} 
        wget ${HTTPD_URL}${HTTPD_FILE} || { ${COLOR}"下载${HTTPD_FILE}源码包下载失败"${END}; exit; }
    else
        ${COLOR}"${HTTPD_FILE}文件已准备好"${END}
    fi
    if [ ! -e ${PHP} ];then
        ${COLOR}"缺少${PHP}文件"${END}
        exit
    elif [ ! -e ${APP} ];then
        ${COLOR}"缺少${APP}文件"${END}
        exit
    else
        ${COLOR}"相关文件已准备好"${END}
    fi
} 

install_mysql(){
    [ -d /usr/local/mysql ] && { ${COLOR}"MySQL数据库已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装MySQL数据库..."${END}
    ${COLOR}'开始安装MYSQL依赖包'${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper ncurses-compat-libs &> /dev/null
    elif [[ ${OS_RELEASE_VERSION} == 7 ]] &> /dev/null;then
        yum -y install libaio perl-Data-Dumper &> /dev/null
    else
        apt update &> /dev/null;apt -y install numactl libaio-dev libtinfo5 &> /dev/null
    fi
    cd  ${SRC_DIR}
    tar xf ${MYSQL_FILE} -C /usr/local/
    MYSQL_DIR=`echo ${MYSQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    ln -s  /usr/local/${MYSQL_DIR} /usr/local/mysql
    id mysql &> /dev/null || { useradd -s /sbin/nologin -r  mysql ; ${COLOR}"创建mysql用户"${END}; }
    chown -R  mysql.mysql /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
    .  /etc/profile.d/mysql.sh
    cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    [ -d /data/mysql ] || mkdir -p /data/mysql &> /dev/null
    chown -R  mysql.mysql /data/mysql
    mysqld --initialize --user=mysql --datadir=/data/mysql 
    cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        chkconfig --add mysqld
    else
        update-rc.d -f mysqld defaults
    fi
    cat > /lib/systemd/system/mysqld.service <<-EOF
[Unit]
Description=mysql database server
After=network.target

[Service]
Type=notify
PrivateNetwork=false
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d//mysqld stop
ExecReload=/etc/init.d/mysqld reload

[Install]
WantedBy=multi-user.target
Alias=mysqld.service
EOF
    systemctl daemon-reload
    systemctl enable --now mysqld &> /dev/null
    [ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; }
    MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
    mysqladmin  -uroot -p${MYSQL_OLDPASSWORD} password ${MYSQL_ROOT_PASSWORD} &>/dev/null
    ${COLOR}"MySQL数据库安装完成"${END}
}

install_httpd(){
    [ -d ${HTTPD_INSTALL_DIR} ] && { ${COLOR}"Httpd已存在,安装失败"${END};exit; }
    ${COLOR}"开始安装Httpd"${END}
    ${COLOR}"开始安装Httpd依赖包"${END}
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make pcre-devel openssl-devel expat-devel wget bzip2 &> /dev/null
    else
        apt update&> /dev/null
        apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev wget &> /dev/null
    fi
    cd ${SRC_DIR}
    tar xf ${APR_FILE} && tar xf ${APR_UTIL_FILE} && tar xf ${HTTPD_FILE}
    APR_FILE_DIR=`echo ${APR_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    APR_UTIL_FILE_DIR=`echo ${APR_UTIL_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    HTTPD_FILE_DIR=`echo ${HTTPD_FILE}_| sed -nr 's/^(.*[0-9]).*/\1/p'`
    mv ${APR_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr
    mv ${APR_UTIL_FILE_DIR} ${HTTPD_FILE_DIR}/srclib/apr-util
    cd ${HTTPD_FILE_DIR}
    ./configure --prefix=${HTTPD_INSTALL_DIR} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=${MPM}
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && $COLOR"Httpd编译安装成功"$END ||  { $COLOR"Httpd编译安装失败,退出!"$END;exit; }
    id apache &> /dev/null || { useradd -s /sbin/nologin -r  apache ; ${COLOR}"创建apache用户"${END}; }
    sed -i 's/daemon/apache/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo "PATH=${HTTPD_INSTALL_DIR}/bin:$PATH" > /etc/profile.d/http24.sh
    . /etc/profile.d/http24.sh
    cat > /lib/systemd/system/httpd.service <<-EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=${HTTPD_INSTALL_DIR}/bin/apachectl start
ExecReload=${HTTPD_INSTALL_DIR}/bin/apachectl graceful
ExecStop=${HTTPD_INSTALL_DIR}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
    ${COLOR}"开始设置HTTPD配置文件"${END}
    sed -i.bak -e 's@#LoadModule proxy_module.*@LoadModule proxy_module modules/mod_proxy.so@' -e 's@#LoadModule proxy_fcgi_module.*@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@' -e 's/    DirectoryIndex.*/    DirectoryIndex index.php index.html/' ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'AddType application/x-httpd-php .php' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    echo 'ProxyRequests Off' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    mkdir ${HTTPD_INSTALL_DIR}/conf.d 
    echo 'Include conf.d/*.conf' >> ${HTTPD_INSTALL_DIR}/conf/httpd.conf
    cat > ${HTTPD_INSTALL_DIR}/conf.d/vhost.conf <<-EOF
<virtualhost *:80>
servername ${SERVERNAME}
documentroot ${WEB_DIR}
<directory ${WEB_DIR}>
require all granted
</directory>
ProxyPassMatch ^/(.*\.php)\$ fcgi://127.0.0.1:9000${WEB_DIR}/\$1
ProxyPassMatch ^/(fpm_sddtatus|ping)\$ fcgi://127.0.0.1:9000/\$1
CustomLog "logs/access_phpmyadmin_log" common
</virtualhost>
EOF
    systemctl daemon-reload
    systemctl enable --now httpd &> /dev/null
    systemctl is-active httpd &> /dev/null ||  { ${COLOR}"httpd 启动失败,退出!"${END} ; exit; }
    ${COLOR}"httpd安装完成"${END}
}

install_php (){
    ${COLOR}"开始安装PHP"${END}
    ${COLOR}"开始安装PHP依赖包"${END}
    if [[ ${OS_RELEASE_VERSION} == 8 ]] &> /dev/null;then
        cat > /etc/yum.repos.d/PowerTools.repo <<-EOF
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.cloud.tencent.com/centos/8/PowerTools/x86_64/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/8/PowerTools/x86_64/os/
        http://mirrors.163.com/centos/8/PowerTools/x86_64/os/
        http://mirrors.sohu.com/centos/8/PowerTools/x86_64/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
    fi
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        yum -y install gcc make libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel &> /dev/null
    else
        apt update &> /dev/null;apt -y install gcc make openssl pkg-config libssl-dev libsqlite3-dev libonig-dev curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev &> /dev/null 
    fi
    cd ${SRC_DIR}
    tar xf ${PHP}
    PHP_DIR=`echo ${PHP}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    cd ${PHP_DIR}
    ./configure --prefix=${PHP_INSTALL_DIR} --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
    make -j ${CPUS} && make install
    [ $? -eq 0 ] && ${COLOR}"PHP编译安装成功"${END} ||  { ${COLOR}"PHP编译安装失败,退出!"${END};exit; }
    echo 'PATH=$PHP_INSTALL_DIR/bin:$PATH' >/etc/profile.d/lamp.sh
    . /etc/profile.d/lamp.sh
    cp php.ini-production  /etc/php.ini
    cp sapi/fpm/php-fpm.service /lib/systemd/system/
    cd ${PHP_INSTALL_DIR}/etc
    cp php-fpm.conf.default  php-fpm.conf
    cd php-fpm.d/
    cp www.conf.default www.conf
    sed -i.bak -e 's/^user.*/user = apache/' -e 's/^group.*/group = apache/' -e 's/#pm.status_path =.*/pm.status_path = \/fpm_status/' -e 's/#ping.path =.*/ping.path = \/ping/' ${PHP_INSTALL_DIR}/etc/php-fpm.d/www.conf
    mkdir /etc/php.d/
    cat > /etc/php.d/opcache.ini <<-EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF
    systemctl daemon-reload
    systemctl enable --now php-fpm &> /dev/null 
    systemctl is-active  php-fpm &> /dev/null ||  { ${COLOR}"PHP-FPM 启动失败,退出!"${END} ; exit; }
    $COLOR"PHP安装完成"${END}
}

install_phpmyadmin(){
    ${COLOR}"开始安装PHPMYADMIN"${END}
    cd ${SRC_DIR}
    rpm -q unzip &> /dev/null || yum -y install unzip &> /dev/null
    unzip ${APP} &> /dev/null
    [ -d ${WEB_DIR} ] || mkdir -p ${WEB_DIR}
    mv phpMyAdmin-5.1.0-all-languages/* ${WEB_DIR}/
    yum -y install php-json php-xml &> /dev/null
    systemctl restart php-fpm
    cd ${WEB_DIR}
    mv config.sample.inc.php config.inc.php
    sed  -i.bak -e 's/localhost/127.0.0.1/' -e '16c\$cfg['blowfish_secret'] = 'a1b2c3000111222333aaabbbccc00012';' config.inc.php
    mkdir ${WEB_DIR}/tmp
    chmod 777 ${WEB_DIR}/tmp
    ${COLOR}"PHPMYADMIN安装完成"${END}
}

main(){
    os
    check_file
    install_mysql
    install_httpd
    install_php
    install_phpmyadmin
}

main

[root@centos7 ~]# bash install_mysql_httpd_php_phpmyadmin.sh

#在windows系统C:\Windows\System32\drivers\etc\hosts文件里添加
10.0.0.7 phpmyadmin.neteagles.vip  #IP地址为你本地主机的IP

http://phpmyadmin.neteagles.vip/

posted @ 2021-03-04 02:13  网络之鹰  阅读(925)  评论(0编辑  收藏  举报