脚本实现二进制安装 LAMP 架构的 word press

#!/bin/bash
#一键安装LAMP环境 for Centos7
WGETFILE=https://mariadb.nethub.com.hk//mariadb-10.5.5/bintar-linux-systemd-x86_64/mariadb-10.5.5-linux-systemd-x86_64.tar.gz
WORKING_DIR=`pwd`
DATA_DIR="/data/mysql"
BASE_DIR="/usr/local"
FILE='mariadb-10.5.5-linux-systemd-x86_64.tar.gz'
#安装前检查
before_install (){
if [ -e "$FILE" ];then
      echo "安装包存在,开始安装"
else
      echo "检测到当前目录安装包不存在,尝试从互联网下载"
      curl $WGETFILE &> /dev/null
      [  $? -eq 0 ] && wget -c --tries=40 $WGETFILE ||exit
fi

if [ ! -d "/usr/local/mysql" ];then
   return
else
    echo "发现/usr/local目录下存在mysql文件夹,好像已经安装了MYSQL,退出安装,请检查"
	exit
fi

if [ ! -d "/data/mysql" ];then
   mkdir -pv /data/mysql
else
    echo "发现/data/mysql目录,疑似已经安装过,请检查"
	exit
fi
}

install_mysql() {
echo "安装...."
tar -xvf $FILE -C /usr/local/
yum -y install libaio numactl-libs devel wget
yum -y install cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ perl-Data-Dumper 
groupadd mysql
useradd -g mysql mysql
cd /usr/local
Mariad_DIR=`echo $FILE| sed -nr 's/^(.*[0-9]).*/\1/p'`
ln -s  /usr/local/$Mariad_DIR  /usr/local/mysql
chown -R  root.root /usr/local/mysql/
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
.  /etc/profile.d/mysql.sh
ln -s /usr/local/mysql/bin/* /usr/bin/
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
cd /usr/local/mysql
scripts/mysql_install_db --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
echo "安装完毕"
}


#安装PHP
install_php (){
    echo "开始安装PHP"
    yum -y -q  install gcc make libxml2-devel bzip2-devel libmcrypt-devel libsqlite3x-devel oniguruma-devel &>/dev/null
    tar xf php-7.4.12.tar.xz
    cd php-7.4.12/
    ./configure --prefix=/apps/php74 --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 && make install 
    [ $? -eq 0 ] && echo "PHP编译安装成功" ||  { echo "PHP编译安装失败,退出!";exit; }
    cp php.ini-production  /etc/php.ini
	sed -i 's/^expose_php = On/expose_php = Off/' /etc/php.ini
	mkdir /etc/php.d/
    cat > /etc/php.d/opcache.ini <<EOF
[opcache]
zend_extension=opcache.so               
opcache.enable=1
EOF

    cp  sapi/fpm/php-fpm.service /usr/lib/systemd/system/
    cd /apps/php74/etc
    cp  php-fpm.conf.default  php-fpm.conf
    cd  php-fpm.d/
    cp www.conf.default www.conf
    id apache  &> /dev/null || { useradd -s /sbin/nologin -r  apache; echo "创建apache用户"; }
    sed -i.bak  -e  's/^user.*/user = apache/' -e 's/^group.*/group = apache/' /apps/php74/etc/php-fpm.d/www.conf
    systemctl daemon-reload
    systemctl start php-fpm 
    systemctl is-active  php-fpm &> /dev/null ||  { echo "PHP-FPM 启动失败,退出!" ; exit; }
    echo "PHP安装完成"

}

#安装Apache
install_apache () {
#!/bin/bash
#Author: 包万华
# 安装相关包
yum -y install wget gcc make pcre-devel openssl-devel expat-devel
# 下载源代码并解压缩
wget -P /usr/local/src/ https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget -P /usr/local/src/ https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget -P /usr/local/src/ https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
cd /usr/local/src/
tar xf apr-1.7.0.tar.gz
tar xf apr-util-1.6.1.tar.gz
tar xf httpd-2.4.46.tar.gz
# 将apr和apr-util源码与httpd源码合并,三者共同编译安装
mv apr-1.7.0 httpd-2.4.46/srclib/apr
mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
cd httpd-2.4.46/
./configure --prefix=/apps/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre  --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork 
make && make install
# 创建apache账户
useradd -r -s /sbin/nologin apache
# 修改配置文件
sed -i 's/^User.*/User apache/' /apps/httpd/conf/httpd.conf
sed -i 's/^Group.*/Group apache/' /apps/httpd/conf/httpd.conf
# 配置环境变量
echo 'PATH="/apps/httpd/bin:$PATH"' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
# 配置man帮助
echo 'MANDATORY_MANPATH   /apps/httpd/man' >> /etc/man_db.conf
# 创建service unit文件,设置开机启动
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=/apps/httpd/bin/apachectl start
ExecReload=/apps/httpd/bin/apachectl graceful
ExecStop=/apps/httpd/bin/apachectl stop
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now httpd.service
}

#安装Wordpress
install_wordpress(){
    tar xf wordpress-5.4.2-zh_CN.tar.gz  
    [ -d /data/www ] || mkdir -pv /data/www
    mv wordpress/* /apps/httpd
    chown -R apache.apache /apps/httpd
    cd /data/www/
    mv wp-config-sample.php wp-config.php
    mysql -uroot -pbaowanhua123 -e "create database wordpress;grant all on wordpress.* to wordpress@'127.0.0.1' identified by baowanhua123" &>/dev/null
    sed -i.bak -e 's/database_name_here/wordpress/' -e 's/username_here/wordpress/' -e 's/password_here/''baowanhua123''/' -e 's/localhost/127.0.0.1/'  wp-config.php
    $COLOR"WORDPRESS安装完成"
}

before_install

install

install_php

install_apache

install_wordpress


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值