首页 > 数据库 >7、install_mysql_httpd_php_wordpress

7、install_mysql_httpd_php_wordpress

时间:2023-02-09 03:11:33浏览次数:48  
标签:httpd END HTTPD COLOR -- wordpress php DIR

#!/bin/bash
#
#********************************************************************
#Author:		    zikang
#QQ: 			    [email protected]
#Date: 			    2021-03-03
#FileName:		    install_mysql_httpd_php_wordpress.sh
#Description:		install_mysql_httpd_php_wordpress for centos 7&8
#Copyright (C): 	2021 All rights reserved
#********************************************************************
SRC_DIR=/usr/local/src
MYSQL_URL=https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-
MYSQL_VERSION=8.0
MYSQL_APP='mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz'
COLOR="echo -e \\033[01;31m"
END='\033[0m'
MYSQL_ROOT_PASSWORD=123456
MYSQL_WORDPRESS_PASSWORD=123456

APR_URL=https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
APR_FILE=apr-1.7.0
TAR=.tar.bz2
APR_UTIL_URL=https://mirrors.tuna.tsinghua.edu.cn/apache/apr/
APR_UTIL_FILE=apr-util-1.6.1
HTTPD_URL=https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/
HTTPD_FILE=httpd-2.4.46
HTTPD_INSTALL_DIR=/apps/httpd24
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`
MPM=event

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

SERVERNAME=www.jackiezhu.com

APP='wordpress-5.6.2-zh_CN.tar.gz'
WEB_DIR=/data/www

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

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

install_mysql(){
    ${COLOR}"开始安装MySQL数据库..."${END}
    cd  ${SRC_DIR}              
    ${COLOR}'开始安装MYSQL依赖包'${END}
    if [[ `awk -F"[. ]+" '{print $4}' /etc/redhat-release` == 8 ]];then
        yum -y install libaio perl-Data-Dumper ncurses-compat-libs &> /dev/null
    else
        yum -y install libaio perl-Data-Dumper &> /dev/null
    fi
    tar xf ${MYSQL_APP} -C /usr/local/
    MYSQL_DIR=`echo ${MYSQL_APP}| sed -nr 's/^(.*[0-9]).*/\1/p'`
    ln -s  /usr/local/${MYSQL_DIR} /usr/local/mysql
    chown -R  root.root /usr/local/mysql/
    id mysql &> /dev/null || { useradd -s /sbin/nologin -r  mysql ; ${COLOR}"创建mysql用户"${END}; }
    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 ] || mkdir /data
    mysqld --initialize --user=mysql --datadir=/data/mysql 
    cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    service mysqld start &> /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}"数据库安装完成"${END}
}

install_httpd(){
    ${COLOR}"开始安装HTTPD"${END}
    ${COLOR}"开始安装HTTPD依赖包"${END}
    if [ `awk -F'"' '/^ID=/{print $2}' /etc/os-release` == "centos" ] &> /dev/null;then
        yum -y install gcc make pcre-devel openssl-devel expat-devel bzip2 &> /dev/null
    else
        apt update
        apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev &> /dev/null
    fi
    cd ${SRC_DIR}
    tar xf ${APR_FILE}${TAR} && tar xf ${APR_UTIL_FILE}${TAR} && tar xf ${HTTPD_FILE}${TAR}
    mv ${APR_FILE} ${HTTPD_FILE}/srclib/apr
    mv ${APR_UTIL_FILE} ${HTTPD_FILE}/srclib/apr-util
    cd ${HTTPD_FILE}
    ./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; }
    useradd -s /sbin/nologin -r apache
    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
    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 [[ `awk -F"[. ]+" '{print $4}' /etc/redhat-release` == 8 ]];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
    yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel &> /dev/null
    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 /usr/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}
}

set_httpd(){
    ${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 restart httpd
    ${COLOR}"HTTPD配置文件设置完成"${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}
}

check_file
install_mysql
install_httpd
install_php
set_httpd
install_wordpress

标签:httpd,END,HTTPD,COLOR,--,wordpress,php,DIR
From: https://www.cnblogs.com/zikang/p/17103941.html

相关文章

  • PHP , Navicat安装
    1、PHPStudy小皮面板:https://public.xp.cn/upgrades/phpStudy_64.zip    解压缩后       浏览器输入127.0.0.1:80  通过路径查看站点 ......
  • PHP、Navicat安装
    PHPStudy小皮面板:https://public.xp.cn/upgrades/phpStudy_64.zip下载完成后解压后双击点击立即安装 安装完成启动MySQL,Nginx    浏览器输网址127.0.0.1:......
  • PHP图片压缩
    //直接调用就可以了<?phpnamespacethink\admin\storage;/***图片压缩*ClassCompress*@packageEasyAdmin\upload\driver*/classCompress{private$src;......
  • 前端页面分页算法 js+php
    实现效果: 实现思路:通过当前选中页码数值和总页码数量,计算返回结果,以数组的形式返回。遍历数组内容,完成页面渲染。 php算法:/***getNavigatePage**@......
  • php8.2.1编译fileinfo扩展时提示 make: *** [libmagic/softmagic.lo] Error 1
     安装:cd/opt/php-8.2.1/ext/fileinfo/usr/local/php82/bin/phpize./configure--with-php-config=/usr/local/php82/bin/php-config#make&&makeinstall错误如......
  • 【福利活动】1分钟Serverless部署PHP商城实验班上线啦!
    带你体验如何使用Serverless应用引擎SAE快速部署一个PHP商城,并体验SAE带来的弹性伸缩、应用监控等强大能力。活动时间:2月6日-2月17日活动链接(建议PC端访问):​h......
  • PHPMyWind支持PowerPoint一键粘贴
    ​ ueditor粘贴不能粘贴word中的图片是一个很头疼的问题,在我们的业务场景中客户要求必须使用ueditor并且支持word的图片粘贴,因为这个需求头疼了半个月,因为前端方面因为安......
  • PHPMyWind支持PowerPoint导入
    ​ 当前功能基于PHP,其它语言流程大抵相同。大概流程:1.将docx文件上传到服务器中2.使用PHPoffice/PHPword实现将word转换为HTML3.将HTML代码返回并赋值到编辑器中......
  • PHPMyWind支持PowerPoint一键导入
    ​ 1.编辑器修改(可选)1.1在 ueditor/config.json 中添加代码块    /* 上传word配置 */    "wordActionName":"wordupload",/* 执行上传视频的action......
  • PHP 的glob()函数 和 关键字global
    glob()函数phpglob()函数返回匹配指定模式的文件名或目录。因此我们可以使用glob函数来查找文件,也可以实现目录的遍历。函数说明:arrayglob(string$pattern[,int......