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

小柒博客 评论62,350字数 1509阅读5分1秒阅读模式

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

系统环境:CentOS 7.9

软件版本:

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. cd ~ && 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. cd ~ && wget -c ${Boost_URL}/${Boost_File}
  74. tar zxf ${Boost_File} -C /usr/local/
  75. #Install MYSQL
  76. cd ~ && 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. cd ~ && 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. --with-gettext \
  174. --with-gmp \
  175. --with-mhash \
  176. --enable-json \
  177. --enable-mbstring \
  178. --enable-mbregex \
  179. --enable-mbregex-backtrack \
  180. --with-onig \
  181. --enable-pdo \
  182. --with-mysqli=mysqlnd \
  183. --with-pdo-mysql=mysqlnd \
  184. --with-zlib-dir \
  185. --with-pdo-sqlite \
  186. --with-readline \
  187. --enable-session \
  188. --enable-shmop \
  189. --enable-simplexml \
  190. --enable-sockets \
  191. --enable-sysvmsg \
  192. --enable-sysvsem \
  193. --enable-sysvshm \
  194. --enable-wddx \
  195. --with-libxml-dir \
  196. --with-xsl \
  197. --enable-zip \
  198. --enable-mysqlnd-compression-support \
  199. --with-pear \
  200. --enable-opcache
  201. if [ $? -eq 0 ];then
  202. \cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
  203. make && make install
  204. action "The PHP Install Sussess..." /bin/true
  205. else
  206. action "The PHP Install Failed..." /bin/false
  207. exit 1
  208. fi
  209. else
  210. echo -e "\033[31mThe PHP already Install...\033[0m"
  211. exit 1
  212. fi
  213. }
  214. function LNMP_Config() {
  215. #Nginx config
  216. useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
  217. ln -sf ${NGINX_PREFIX}/sbin/nginx /usr/sbin
  218. cat >${NGINX_PREFIX}/conf/nginx.conf <<EOF
  219. user ${USER} ${USER};
  220. worker_processes auto;
  221. pid logs/nginx.pid;
  222. events {
  223. use epoll;
  224. worker_connections 10240;
  225. multi_accept on;
  226. }
  227. http {
  228. include mime.types;
  229. default_type application/octet-stream;
  230. log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
  231. '\$status \$body_bytes_sent "\$http_referer" '
  232. '"\$http_user_agent" "\$http_x_forwarded_for"';
  233. access_log logs/access.log main;
  234. error_log logs/error.log warn;
  235. sendfile on;
  236. tcp_nopush on;
  237. keepalive_timeout 120;
  238. tcp_nodelay on;
  239. server_tokens off;
  240. gzip on;
  241. gzip_min_length 1k;
  242. gzip_buffers 4 64k;
  243. gzip_http_version 1.1;
  244. gzip_comp_level 4;
  245. gzip_types text/plain application/x-javascript text/css application/xml;
  246. gzip_vary on;
  247. client_max_body_size 10m;
  248. client_body_buffer_size 128k;
  249. proxy_connect_timeout 90;
  250. proxy_send_timeout 90;
  251. proxy_buffer_size 4k;
  252. proxy_buffers 4 32k;
  253. proxy_busy_buffers_size 64k;
  254. large_client_header_buffers 4 4k;
  255. client_header_buffer_size 4k;
  256. open_file_cache_valid 30s;
  257. open_file_cache_min_uses 1;
  258. server {
  259. listen 80;
  260. server_name localhost;
  261. location / {
  262. root html/wordpress;
  263. index index.php index.html index.htm;
  264. }
  265. location ~* \.php$ {
  266. root html/wordpress;
  267. fastcgi_connect_timeout 300s;
  268. fastcgi_send_timeout 300s;
  269. fastcgi_read_timeout 300s;
  270. fastcgi_buffer_size 64k;
  271. fastcgi_buffers 4 64k;
  272. fastcgi_busy_buffers_size 128k;
  273. fastcgi_temp_file_write_size 256k;
  274. fastcgi_pass 127.0.0.1:9000;
  275. fastcgi_index index.php;
  276. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  277. include fastcgi_params;
  278. }
  279. }
  280. }
  281. EOF
  282. #Config PHP
  283. \cp php.ini-production /etc/php.ini
  284. \cp ${PHP_PREFIX}/etc/php-fpm.conf.default ${PHP_PREFIX}/etc/php-fpm.conf
  285. \cp ${PHP_PREFIX}/etc/php-fpm.d/www.conf.default ${PHP_PREFIX}/etc/php-fpm.d/www.conf
  286. \cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
  287. cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
  288. [www]
  289. listen = 0.0.0.0:9000
  290. listen.mode = 0666
  291. user = www
  292. group = www
  293. pm = dynamic
  294. pm.max_children = 128
  295. pm.start_servers = 20
  296. pm.min_spare_servers = 5
  297. pm.max_spare_servers = 35
  298. pm.max_requests = 10000
  299. rlimit_files = 1024
  300. slowlog = log/\$pool.log.slow
  301. EOF
  302. #Mysql Config
  303. useradd -s /sbin/nlogin mysql >/dev/null 2>&1
  304. mkdir -p ${MYSQL_DIR}
  305. chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
  306. cat >/etc/my.cnf <<EOF
  307. [mysqld]
  308. #数据存储目录
  309. datadir = ${MYSQL_DIR}
  310. #socket通信文件
  311. socket = /tmp/mysql.sock
  312. #使用mysql用户启动
  313. user = ${MYSQL_USER}
  314. #MYSQL服务运行的端口号
  315. port = 3306
  316. #开启bin-log日志
  317. log-bin = mysql-bin
  318. #MYSQL服务ID号
  319. server-id = 1
  320. #定义error错误文件
  321. log-error = ${MYSQL_DIR}/mysqld.log
  322. #PID文件路径
  323. pid-file = mysqld.pid
  324. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  325. #设置字符集为utf8
  326. character-set-server = utf8
  327. [client]
  328. default-character-set = utf8
  329. port = 3306
  330. socket = /tmp/mysql.sock
  331. [mysql]
  332. default-character-set = utf8
  333. EOF
  334. #Initialization Mysql
  335. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
  336. ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
  337. \cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
  338. chmod o+x /etc/init.d/mysqld
  339. #Config iptables(firewalld)、selinux
  340. SYS_VERSION=$(awk -F. '{print $1}' /etc/redhat-release |awk '{print $NF}')
  341. if [ ${SYSTEM_VERSION} -eq 6 ];then
  342. service iptables stop
  343. chkconfig iptables off
  344. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  345. setenforce 0
  346. else
  347. systemctl stop firewalld.service
  348. systemctl disable firewalld.service
  349. sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  350. setenforce 0
  351. fi
  352. #Start MYSQL、php-fpm、nginx and Add MySQL、php-fpm、nginx boot self start
  353. ${NGINX_PREFIX}/sbin/nginx
  354. systemctl start php-fpm
  355. /etc/init.d/mysqld start
  356. grep -qw "${NGINX_PREFIX}" /etc/rc.d/rc.local
  357. if [ $? -ne 0 ];then
  358. echo "${NGINX_PREFIX}/sbin/nginx" >>/etc/rc.d/rc.local
  359. chmod +x /etc/rc.d/rc.local
  360. fi
  361. systemctl enable php-fpm
  362. chkconfig --add mysqld
  363. chkconfig mysqld on
  364. chmod +x /etc/rc.d/rc.local
  365. }
  366. function Install_WordPress (){
  367. #Wordpress Config
  368. cd ~ && wget ${WORD_URL}/${WORD_FILES}
  369. [ -f /usr/bin/unzip ] || yum -y install unzip
  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

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
历史上的今天
4 月
13
Wechat
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
Shell最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2020年4月13日 14:54:18
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/6760.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证
加载中...