0
点赞
收藏
分享

微信扫一扫

LNMP环境搭建WordPress自动化安装脚本

此脚本是LAMP环境安装WordPress脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.4

软件版本:

Nginx:1.16.1

Mysql:5.7.29

PHP:7.3.7

WordPress:5.4

[root@localhost ~]# vim auto_install_lnmp_wordpress.sh

  1. #!/bin/bash
  2. #Date:2020-4-13 14:08:55
  3. #Author Blog:
  4. # https://www.yangxingzhen.com
  5. #Author WeChat:
  6. # 微信公众号:小柒博客
  7. #Author mirrors site:
  8. # https://mirrors.yangxingzhen.com
  9. #About the Author
  10. # BY:YangXingZhen
  11. # Mail:xingzhen.yang@yangxingzhen.com
  12. #Auto Install LNMP environment

  13. source /etc/rc.d/init.d/functions

  14. #Define Nginx path variables
  15. NGINX_URL=http://nginx.org/download
  16. NGINX_FILE=nginx-1.16.1.tar.gz
  17. NGINX_FILE_DIR=nginx-1.16.1
  18. NGINX_PREFIX=/usr/local/nginx

  19. #Define Boost path variables
  20. Boost_URL=https://mirrors.yangxingzhen.com/mysql
  21. Boost_File=boost_1_59_0.tar.gz

  22. #Define Mysql path variables
  23. MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
  24. MYSQL_FILES=mysql-5.7.29.tar.gz
  25. MYSQL_FILES_DIR=mysql-5.7.29
  26. MYSQL_PREFIX=/usr/local/mysql
  27. MYSQL_DIR=/data/mysql
  28. MYSQL_USER=mysql

  29. #Define PHP path variables
  30. PHP_URL=http://mirrors.sohu.com/php
  31. PHP_FILE=php-7.3.7.tar.gz
  32. PHP_FILE_DIR=php-7.3.7
  33. PHP_PREFIX=/usr/local/php
  34. USER=www

  35. #Define ZIP path variables
  36. ZIP_URL=https://nih.at/libzip
  37. ZIP_FILE=libzip-1.2.0.tar.gz
  38. ZIP_FILE_DIR=libzip-1.2.0

  39. #Define Wordpress path variables
  40. WORD_URL=https://mirrors.yangxingzhen.com/wordpress
  41. WORD_FILES=wordpress-5.4-zh_CN.zip
  42. WORD_FILES_DIR=wordpress

  43. function Install_Nginx() {
  44. #Install Nginx Soft
  45. if [ ! -d ${NGINX_PREFIX} ];then
  46. yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ wget
  47. wget -c ${NGINX_URL}/${NGINX_FILE}
  48. tar zxf ${NGINX_FILE}
  49. cd ${NGINX_FILE_DIR}
  50. sed -i 's/1.16.1/ /;s/nginx\//nginx/' src/core/nginx.h
  51. useradd -s /sbin/nologin www
  52. ./configure --prefix=${NGINX_PREFIX} \
  53. --user=www \
  54. --group=www \
  55. --with-http_ssl_module \
  56. --with-http_stub_status_module
  57. if [ $? -eq 0 ];then
  58. make && make install
  59. action "NGINX Install Success..." /bin/true
  60. else
  61. action "NGINX Install Failed..." /bin/false
  62. exit 1
  63. fi
  64. else
  65. echo -e "\033[32m Nginx has been installed \033[0m"
  66. fi
  67. }

  68. function Install_Mysql() {
  69. if [ ! -d ${MYSQL_PREFIX} ];then
  70. #Install Package
  71. yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl

  72. #Install Boost
  73. wget -c ${Boost_URL}/${Boost_File}
  74. tar zxf ${Boost_File} -C /usr/local/

  75. #Install MYSQL
  76. wget -c ${MYSQL_URL}/${MYSQL_FILES}
  77. tar zxf ${MYSQL_FILES}
  78. cd ${MYSQL_FILES_DIR}
  79. cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
  80. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
  81. -DMYSQL_DATADIR=${MYSQL_DIR} \
  82. -DSYSCONFDIR=/etc \
  83. -DEXTRA_CHARSETS=all \
  84. -DDEFAULT_CHARSET=utf8 \
  85. -DDEFAULT_COLLATION=utf8_general_ci \
  86. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  87. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  88. -DWITH_MEMORY_STORAGE_ENGINE=1 \
  89. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  90. -DDOWNLOAD_BOOST=1 \
  91. -DWITH_BOOST=/usr/local/boost_1_59_0 \
  92. -DENABLED_LOCAL_INFILE=1 \
  93. -DMYSQL_TCP_PORT=3306 \
  94. -DWITH_READLINE=1 \
  95. -DMYSQL_USER=${MYSQL_USER} \
  96. -DWITH_SSL=yes
  97. if [ $? -eq 0 ];then
  98. make && make install
  99. action "The MYSQL Install Sussess..." /bin/true
  100. else
  101. action "The MYSQL Install Failed..." /bin/false
  102. exit 1
  103. fi
  104. else
  105. echo -e "\033[31mThe MYSQL already Install...\033[0m"
  106. exit 1
  107. fi
  108. }

  109. function Install_PHP() {
  110. #Install Libzip
  111. yum y install wget gcc gcc-c++
  112. wget -c ${ZIP_URL}/${ZIP_FILE}
  113. tar zxf ${ZIP_FILE}
  114. cd ${ZIP_FILE_DIR}
  115. ./configure
  116. if [ $? -eq 0 ];then
  117. make && make install
  118. action "The Libzip Install Sussess..." /bin/true
  119. else
  120. action "The Libzip Install Failed..." /bin/false
  121. exit 1
  122. fi

  123. cat >/etc/ld.so.conf <<EOF
  124. /usr/local/lib64
  125. /usr/local/lib
  126. /usr/lib
  127. /usr/lib64
  128. EOF
  129. ldconfig -v

  130. #Install PHP
  131. if [ ! -d ${PHP_PREFIX} ];then
  132. #Install Package
  133. yum -y install epel-release
  134. yum -y install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devellibxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel cmake
  135. cd ~ && wget -c ${PHP_URL}/${PHP_FILE}
  136. tar zxf ${PHP_FILE}
  137. cd ${PHP_FILE_DIR}
  138. ./configure --prefix=${PHP_PREFIX} \
  139. --with-config-file-path=/etc \
  140. --enable-fpm \
  141. --with-fpm-user=${USER} \
  142. --with-fpm-group=${USER} \
  143. --enable-inline-optimization \
  144. --disable-debug \
  145. --disable-rpath \
  146. --enable-shared \
  147. --enable-soap \
  148. --with-libxml-dir \
  149. --with-xmlrpc \
  150. --with-openssl \
  151. --with-mhash \
  152. --with-pcre-regex \
  153. --with-sqlite3 \
  154. --with-zlib \
  155. --enable-bcmath \
  156. --with-iconv \
  157. --with-bz2 \
  158. --enable-calendar \
  159. --with-curl \
  160. --with-cdb \
  161. --enable-dom \
  162. --enable-exif \
  163. --enable-fileinfo \
  164. --enable-filter \
  165. --with-pcre-dir \
  166. --enable-ftp \
  167. --with-gd \
  168. --with-openssl-dir \
  169. --with-jpeg-dir \
  170. --with-png-dir \
  171. --with-zlib-dir \
  172. --with-freetype-dir \
  173. --enable-gd-jis-conv \
  174. --with-gettext \
  175. --with-gmp \
  176. --with-mhash \
  177. --enable-json \
  178. --enable-mbstring \
  179. --enable-mbregex \
  180. --enable-mbregex-backtrack \
  181. --with-onig \
  182. --enable-pdo \
  183. --with-mysqli=mysqlnd \
  184. --with-pdo-mysql=mysqlnd \
  185. --with-zlib-dir \
  186. --with-pdo-sqlite \
  187. --with-readline \
  188. --enable-session \
  189. --enable-shmop \
  190. --enable-simplexml \
  191. --enable-sockets \
  192. --enable-sysvmsg \
  193. --enable-sysvsem \
  194. --enable-sysvshm \
  195. --enable-wddx \
  196. --with-libxml-dir \
  197. --with-xsl \
  198. --enable-zip \
  199. --enable-mysqlnd-compression-support \
  200. --with-pear \
  201. --enable-opcache
  202. if [ $? -eq 0 ];then
  203. \cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
  204. make && make install
  205. action "The PHP Install Sussess..." /bin/true
  206. else
  207. action "The PHP Install Failed..." /bin/false
  208. exit 1
  209. fi
  210. else
  211. echo -e "\033[31mThe PHP already Install...\033[0m"
  212. exit 1
  213. fi
  214. }

  215. function LNMP_Config() {
  216. #Nginx config
  217. useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
  218. ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/sbin
  219. cat >${NGINX_PREFIX}/conf/nginx.conf <<EOF
  220. user ${USER} ${USER};
  221. worker_processes auto;
  222. pid logs/nginx.pid;
  223. events {
  224. use epoll;
  225. worker_connections 10240;
  226. multi_accept on;
  227. }
  228. http {
  229. include mime.types;
  230. default_type application/octet-stream;
  231. log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
  232. '\$status \$body_bytes_sent "\$http_referer" '
  233. '"\$http_user_agent" "\$http_x_forwarded_for"';
  234. access_log logs/access.log main;
  235. error_log logs/error.log warn;
  236. sendfile on;
  237. tcp_nopush on;
  238. keepalive_timeout 120;
  239. tcp_nodelay on;
  240. server_tokens off;
  241. gzip on;
  242. gzip_min_length 1k;
  243. gzip_buffers 4 64k;
  244. gzip_http_version 1.1;
  245. gzip_comp_level 4;
  246. gzip_types text/plain application/x-javascript text/css application/xml;
  247. gzip_vary on;
  248. client_max_body_size 10m;
  249. client_body_buffer_size 128k;
  250. proxy_connect_timeout 90;
  251. proxy_send_timeout 90;
  252. proxy_buffer_size 4k;
  253. proxy_buffers 4 32k;
  254. proxy_busy_buffers_size 64k;
  255. large_client_header_buffers 4 4k;
  256. client_header_buffer_size 4k;
  257. open_file_cache_valid 30s;
  258. open_file_cache_min_uses 1;
  259. server {
  260. listen 80;
  261. server_name localhost;
  262. location / {
  263. root html/wordpress;
  264. index index.php index.html index.htm;
  265. }
  266. location ~* \.php$ {
  267. root html/wordpress;
  268. fastcgi_connect_timeout 300s;
  269. fastcgi_send_timeout 300s;
  270. fastcgi_read_timeout 300s;
  271. fastcgi_buffer_size 64k;
  272. fastcgi_buffers 4 64k;
  273. fastcgi_busy_buffers_size 128k;
  274. fastcgi_temp_file_write_size 256k;
  275. fastcgi_pass 127.0.0.1:9000;
  276. fastcgi_index index.php;
  277. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  278. include fastcgi_params;
  279. }
  280. }
  281. }
  282. EOF

  283. #Config PHP
  284. \cp php.ini-production /etc/php.ini
  285. \cp ${PHP_PREFIX}/etc/php-fpm.conf.default ${PHP_PREFIX}/etc/php-fpm.conf
  286. \cp ${PHP_PREFIX}/etc/php-fpm.d/www.conf.default ${PHP_PREFIX}/etc/php-fpm.d/www.conf
  287. \cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
  288. cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
  289. [www]
  290. listen = 0.0.0.0:9000
  291. listen.mode = 0666
  292. user = www
  293. group = www
  294. pm = dynamic
  295. pm.max_children = 128
  296. pm.start_servers = 20
  297. pm.min_spare_servers = 5
  298. pm.max_spare_servers = 35
  299. pm.max_requests = 10000
  300. rlimit_files = 1024
  301. slowlog = log/\$pool.log.slow
  302. EOF

  303. #Mysql Config
  304. useradd -s /sbin/nlogin mysql >/dev/null 2>&1
  305. mkdir -p ${MYSQL_DIR}
  306. chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
  307. cat >/etc/my.cnf <<EOF
  308. [mysqld]
  309. #数据存储目录
  310. datadir = ${MYSQL_DIR}
  311. #socket通信文件
  312. socket = /tmp/mysql.sock
  313. #使用mysql用户启动
  314. user = ${MYSQL_USER}
  315. #MYSQL服务运行的端口号
  316. port = 3306
  317. #开启bin-log日志
  318. log-bin = mysql-bin
  319. #MYSQL服务ID号
  320. server-id = 1
  321. #定义error错误文件
  322. log-error = ${MYSQL_DIR}/mysqld.log
  323. #PID文件路径
  324. pid-file = mysqld.pid
  325. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  326. #设置字符集为utf8
  327. character-set-server = utf8
  328. [client]
  329. default-character-set = utf8
  330. port = 3306
  331. socket = /tmp/mysql.sock
  332. [mysql]
  333. default-character-set = utf8
  334. EOF

  335. #Initialization Mysql
  336. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
  337. ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
  338. \cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
  339. chmod o+x /etc/init.d/mysqld

  340. #Config iptables(firewalld)、selinux
  341. SYS_VERSION=$(awk -F. '{print $1}' /etc/redhat-release |awk '{print $NF}')
  342. if [ ${SYSTEM_VERSION} -eq 6 ];then
  343. service iptables stop
  344. chkconfig iptables off
  345. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  346. setenforce 0
  347. else
  348. systemctl stop firewalld.service
  349. systemctl disable firewalld.service
  350. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  351. setenforce 0
  352. fi

  353. #Start MYSQL、php-fpm、nginx and Add MySQL、php-fpm、nginx boot self start
  354. ${NGINX_PREFIX}/sbin/nginx
  355. systemctl start php-fpm
  356. /etc/init.d/mysqld start
  357. grep -qw "${NGINX_PREFIX}" /etc/rc.d/rc.local
  358. if [ $? -ne 0 ];then
  359. echo "${NGINX_PREFIX}/sbin/nginx" >>/etc/rc.d/rc.local
  360. chmod +x /etc/rc.d/rc.local
  361. fi
  362. systemctl enable php-fpm
  363. chkconfig --add mysqld
  364. chkconfig mysqld on
  365. chmod +x /etc/rc.d/rc.local
  366. }

  367. function Install_WordPress (){
  368. #Wordpress Config
  369. wget ${WORD_URL}/${WORD_FILES}
  370. unzip ${WORD_FILES} -d ${NGINX_PREFIX}/html
  371. chown -R www.www ${NGINX_PREFIX}/html/wordpress
  372. mysql -e "create database wordpress charset=utf8;"
  373. mysql -e "grant all on wordpress.* to wordpress@'localhost' identified by '123456';"
  374. mysql -e "flush privileges"
  375. }

  376. function Main (){
  377. Install_Nginx
  378. Install_Mysql
  379. Install_PHP
  380. LNMP_Config
  381. Install_WordPress
  382. }

  383. Main

脚本执行方式:

[root@localhost ~]# sh auto_install_lnmp_wordpress.sh

举报

相关推荐

0 条评论