一键LAMP(个人)

#!/bin/bash

#LAMP
CPUS=`lscpu |grep "CPU(s)"|awk '{print $2}'|head -1`
PHP="php-7.4.7.tar.gz"
WP_ZIP="wordpress-5.4.2-zh_CN.tar.gz"
WP_INSTALL="/data"

HTTP_INSTALL_DIR="/apps/httpd24"

if [ ! -e ${WP_ZIP} ] ;then
echo "缺少wordpress"
exit
elif [ ! -e ${PHP} ] ; then
echo "缺少PHP"
exit
else
echo "准备完成"
fi

yum -y install gcc make unzip gzip bz2 pcre-devel openssl-devel expat-devel wget libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel php-mysqlnd

#http variable
install_httpd(){

HTTP_URL="https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.gz"
HTTP_FILE="${HTTP_URL##*/}"
APR_URL="https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz"
APR_FILE="${APR_URL##*/}"
APR_UTIL_URL="https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz"
APR_UTIL_FILE="${APR_UTIL_URL##*/}"
cd
wget ${HTTP_URL} && wget ${APR_URL} && wget ${APR_UTIL_URL}
tar xvf ${HTTP_FILE} && tar xvf ${APR_FILE} && tar xvf ${APR_UTIL_FILE}
mv ${APR_FILE%.tar*} ${HTTP_FILE%.tar*}/srclib/apr
mv ${APR_UTIL_FILE%.tar*} ${HTTP_FILE%.tar*}/srclib/apr-util
cd ${HTTP_FILE%.tar*}

./configure --prefix=${HTTP_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=event

make -j ${CPUS} && make install
#环境
echo "PATH=${HTTP_INSTALL_DIR}/bin:$PATH" > /etc/profile.d/http24.sh
. /etc/profile.d/http24.sh
#创建用户
useradd -s /sbin/nologin -r apache
#更改运行用户
sed -Ei "s/daemon/apache/g" ${HTTP_INSTALL_DIR}/conf/httpd.conf
#创建service
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=${HTTP_INSTALL_DIR}/bin/apachectl start
ExecReload=${HTTP_INSTALL_DIR}/bin/apachectl graceful
ExecStop=${HTTP_INSTALL_DIR}bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

}

install_mariadb(){

yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel  gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel

MARIADB_URL="https://mirrors4.tuna.tsinghua.edu.cn/mariadb/mariadb-10.2.33/source/mariadb-10.2.33.tar.gz"
MARIADB_ZIP="${MARIADB_URL##*/}"
INSTALL_DIR="/apps/mysql"
MHOME="/data/mysql"
PASS="123456"

cd
wget ${MARIADB_URL}

mkdir ${MHOME}
useradd -r -s /sbin/nologin -d ${MHOME} mysql
chown mysql.mysql ${MHOME}

tar xf ${MARIADB_ZIP} -C /usr/local/src

cd /usr/local/src/${MARIADB_ZIP%.tar*}

cmake . \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DMYSQL_DATADIR=${MHOME} \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=${MHOME}/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

编译
make -j ${CPUS} && make install
#环境
echo "${INSTALL_DIR}/bin/:$PATH" > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh

cd ${INSTALL_DIR}
scripts/mysql_install_db --datadir=${MHOME} --user=mysql

cp support-files/my-huge.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start

${INSTALL_DIR}/bin/mysql_secure_installation <<EOF

y
${PASS}
${PASS}
y
y
y
y
EOF
}

install_fastcgi(){
INSTALL_DIR="/apps/php74"
cd
tar xf ${PHP}
cd ${PHP%.tar*}

./configure --prefix=${INSTALL_DIR} --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-mysqlnd --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo

make -j ${CPUS} && make install

cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system

cd ${INSTALL_DIR}/etc/
cp php-fpm.conf.default php-fpm.conf

cd php-fpm.d/
cp www.conf.default www.conf

sed -Ei 's/^(user) .*/\1 = apache/' ${INSTALL_DIR}/etc/php-fpm.d/www.conf
sed -Ei 's/^(group) .*/\1 = apache/' ${INSTALL_DIR}/etc/php-fpm.d/www.conf

}

unzip_wordpress(){
# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
cd
tar xf ${WP_ZIP} -C ${WP_INSTALL}
chown -R apache.apache ${WP_INSTALL}/${WP_ZIP%%-*}
}

setup(){
VLAN="10.0.0.%"
WP_PASS="123456"
systemctl enable --now mariadb
mysql -e "create database wordpress;"
mysql -e "grant all on wordpress.* to wpuser@localhost identified by '${WP_PASS}'"

sed -i.bak -e 's/^#LoadModule proxy_module modules\/mod_proxy.so/LoadModule proxy_module modules\/mod_proxy.so/' -e 's/^#LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/' ${HTTP_INSTALL_DIR}/conf/httpd.conf

sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' ${HTTP_INSTALL_DIR}/conf/httpd.conf

echo "AddType application/x-httpd-php .php" >> ${HTTP_INSTALL_DIR}/conf/httpd.conf
echo "ProxyRequests Off" >> ${HTTP_INSTALL_DIR}/conf/httpd.conf
echo "IncludeOptional conf/wordpress.conf" >> ${HTTP_INSTALL_DIR}/conf/httpd.conf

sed -Ei 's/^DocumentRoot.*//' ${HTTP_INSTALL_DIR}/conf/httpd.conf
echo "DocumentRoot ${WP_INSTALL}/${WP_ZIP%%-*}" >> ${HTTP_INSTALL_DIR}/conf/httpd.conf

cat > ${HTTP_INSTALL_DIR}/conf/wordpress.conf <<EOF
DocumentRoot ${WP_INSTALL}/${WP_ZIP%%-*}
<Directory "${WP_INSTALL}/${WP_ZIP%%-*}">
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
EOF
systemctl enable --now httpd php-fpm
}

main(){
install_httpd
install_mariadb
install_fastcgi
unzip_wordpress
setup
}
main
echo "默认创建授权账号为wpuser,密码是${WP_PASS}"

posted @ 2020-10-31 16:49  天际之上可有蓝天  阅读(85)  评论(0编辑  收藏  举报