1. 程式人生 > 實用技巧 >在centos7一鍵搭建wordpress

在centos7一鍵搭建wordpress

[root@localhost ~]# ls
anaconda-ks.cfg  LAMP.sh
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
apr-1.7.0.tar.bz2       httpd-2.4.46          mariadb-10.5.5-linux-x86_64.tar.gz  php-7.4.7.tar.gz
apr-util-1.6.1.tar.bz2  httpd-2.4.46.tar.bz2  php-7.4.7                           wordpress-5.4
.2-zh_CN.tar.gz [root@localhost ~]# cat LAMP.sh #!/bin/bash SRC_DIR=/usr/local/src NAME="mariadb-10.5.5-linux-x86_64.tar.gz" MYSQL="mariadb-10.5.5-linux-x86_64" FULL_NAME=${SRC_DIR}/${NAME} DATA_DIR="/data/mysql" RURPLE="\033[1;35m" RED="\033[1;31m" END="\033[0m" HTTPD='httpd-2.4.46.tar.bz2 ' APR='apr-1.7.0.tar.bz2
' APRU='apr-util-1.6.1.tar.bz2 ' WORDPRESS='wordpress-5.4.2-zh_CN.tar.gz' PHP='php-7.4.7.tar.gz' echo -e " $RURPLE 開始安裝基於LAMP的wordpress $END" sleep 2 check_file(){ cd $SRC_DIR echo -e "$RED 請將相關軟體放在${SRC_DIR}目錄下 $END" if [ ! -e ${HTTPD} ];then echo -e "$RED 缺少 ${HTTPD}檔案 $END" exit elif [
! -e ${APR} ];then echo -e "$RED 缺少 ${APR}檔案 $END" exit elif [ ! -e ${APRU} ];then echo -e $RED "缺少 ${APRU}檔案 $END" exit elif [ ! -e ${PHP} ];then echo -e "$RED 缺少 ${PHP}檔案 $END" exit elif [ ! -e ${WORDPRESS} ];then echo -e "$RED缺少 ${WORDPRESS}檔案 $END" exit elif [ ! -e ${NAME} ];then echo -e "$RED 缺少 ${NAME}檔案 $END" exit else echo -e " $RURPLE 相關檔案已經準備好 $END" fi } install_mysql(){ echo -e " $RED 開始安裝MYSQL資料庫$END" echo -e "$RURPLE 開始安裝有關安裝包,請耐心等候... $END" yum -y install wget libaio numactl-libs &> /dev/null echo -e "$RURPLE 安裝包下載完畢! $END" sleep 2 echo -e "$RURPLE 填寫配置檔案my.cnf $END" cat > /etc/my.cnf <<EOF [mysqld] datadir=/data/mysql skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock EOF echo -e "$RURPLE 配置檔案編寫完成!$END" if [ -f ${FULL_NAME} ];then echo -e "$RURPLE 安裝檔案存在$END" else echo -e "$RURPLE 安裝檔案不存在 $END" exit 1 fi if [ -h /usr/local/mysql ];then echo -e "$RURPLE mysql 已經安裝! $END" exit 2 else tar xf ${FULL_NAME} -C /usr/local/ ln -s /usr/local/${MYSQL}/ /usr/local/mysql &> /dev/null if id mysql;then echo -e "$RURPLE mysql 使用者已經存在! $END" else groupadd mysql useradd -r -g mysql -s /bin/false mysql fi if id mysql;then chown -R root.root /usr/local/mysql/ if [ ! -d /data/mysql ];then mkdir -p /data/mysql && chown -R mysql.mysql /data/mysql &> /dev/null /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/ &> /dev/null cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld &> /dev/null chmod +x /etc/init.d/mysqld ln -s /usr/local/mysql/bin/* /usr/bin/ &> /dev/null chkconfig --add mysqld service mysqld start else echo -e " $RURPLE mysql資料目錄已經存在 $END" exit 3 fi fi fi mysql -u root -e "create database wordpress; create user wordpress@'10.0.0.7' identified by 'magedu'; grant all on wordpres.* to wordpress@'10.0.0.7';" echo -e "$RED 資料庫安裝配置完畢 $END" } install_httpd(){ echo -e "$RED 開始安裝apache服務 $END" yum -y install lrzsz gcc pcre-devel openssl-devel expat-devel bzip2 cd ${SRC_DIR} tar xf ${APR} tar xf ${APRU} tar xf ${HTTPD} echo -e "$RED 進行合併編譯,請等候..... $END" 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/httpd24 \ --enable-so \ --enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-included-apr \ --enable-modules=most \ --enable-mpms-shared=all \ --with-mpm=event make && make install [ $? -eq 0 ] && echo -e "$RED apache編譯安裝成功 $END" || { echo -e "$RED apache編譯安裝失敗!退出$END";exit;} echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh . /etc/profile.d/lamp.sh useradd -s /sbin/nologin -r -u 88 apache sed -i.bak -e 's/^User.*/User apache/' -e 's/^Group.*/Group apache/' /apps/httpd24/conf/httpd.conf sed -i 's/^#LoadModule proxy_module modules\/mod_proxy.so/LoadModule proxy_module modules\/mod_proxy.so/' /apps/httpd24/conf/httpd.conf sed -i 's/^#LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/' /apps/httpd24/conf/httpd.conf sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /apps/httpd24/conf/httpd.conf apachectl start cat > /usr/lib/systemd/system/httpd.server<<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 #EnvironmentFile=/etc/sysconfig/httpd ExecStart=/apps/httpd24/bin/apachectl start #ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start ExecReload=/apps/httpd24/bin/apachectl graceful #ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful ExecStop=/apps/httpd24/bin/apachectl stop KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target EOF echo -e " AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps ProxyRequests Off <virtualhost *:80> servername 10.0.0.7 documentroot /data/wordpress <directory /data/wordpress> require all granted </directory> ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1 ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1 CustomLog "logs/access_wordpress_log" common </virtualhost> " >> /apps/httpd24/conf/httpd.conf apachectl restart echo -e "$RED apache服務安裝完畢! $END" } install_php(){ echo -e " ${RED} 開始安裝PHP $END" yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel openssl-devel cd ${SRC_DIR} tar xf ${PHP} cd php-7.4.7 ./configure \ --prefix=/apps/php\ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-openssl \ --with-zlib \ --with-config-file-path=/etc \ --with-config-file-dir=/etc/php.d \ --enable-mbstring \ --enable-xml \ --enable-sockets \ --enable-fpm \ --enable-maintainer-zts \ --disable-fileinfo make && make install [ $? -eq 0 ] && echo -e "$REDPHP編譯安裝成功!$END" || { echo -e " $RED PHP編譯安裝失敗,退出!$END";exit;} echo 'PATH=/apps/php/bin:/apps/httpd24/bin:$PATH' > /etc/profile.d/php74.sh . /etc/profile.d/php74.sh cp php.ini-production /etc/php.ini cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/ cd /apps/php/etc/ cp php-fpm.conf.default php-fpm.conf cp /apps/php/etc/php-fpm.d/www.conf.default /apps/php/etc/php-fpm.d/www.conf sed -i.bak -e 's/^user.*/user = apache/' -e 's/^group.*/group = apache/' -e 's/;pm.status_path = /status/pm.status_path = /status/' -e 's/;ping.path = /ping /ping.path = /ping /' /apps/php/etc/php-fpm.d/www.conf mkdir /etc/php.d car > /etc/php.d/opcache.ini<<EOF [opcache] zend_extension=opcache.so opcache.enable=1 EOF systemctl daemon-reload systemctl enable --now php-fpm.service mkdir /data/wordpress echo -e "$RED PHP安裝完成!$END" } install_wordpress(){ cd ${SRC_DIR} tar xf ${WORDPRESS} -C /data/ setfacl -R -m u:apache:rwx /data/wordpress/ echo -e " $RURPLE WORDPRESS安裝完成!!$END" } check_file install_mysql install_httpd install_php install_wordpress