首页 > 其他分享 >LAMP环境搭建WordPress自动化安装脚本

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

时间:2022-12-30 16:00:42浏览次数:43  
标签:FILES bin enable -- PREFIX LAMP WordPress Install 搭建

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

系统环境:CentOS 7.4

软件版本:

Apache:2.4.28

Mysql:5.7.29

PHP:7.3.7

WordPress:5.4

[root@localhost ~]# vim auto_install_lamp_wordpress.sh

  1. #!/bin/bash
  2. #Date:2018-5-20 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:[email protected]
  12. #Auto Install LAMP Environment And Wordpress

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

  14. #Define APR path variables
  15. APR_URL=https://mirrors.yangxingzhen.com/apr
  16. APR_FILES=apr-1.6.3.tar.gz
  17. APR_FILES_DIR=apr-1.6.3
  18. APR_PREFIX=/usr/local/apr

  19. #Define APR-util path variables
  20. APR_UTIL_URL=https://mirrors.yangxingzhen.com/apr-util
  21. APR_UTIL_FILES=apr-util-1.6.1.tar.gz
  22. APR_UTIL_FILES_DIR=apr-util-1.6.1
  23. APR_UTIL_PREFIX=/usr/local/apr-util

  24. #Define PCRE path variables
  25. PCRE_URL=https://mirrors.yangxingzhen.com/pcre
  26. PCRE_FILES=pcre-8.41.tar.gz
  27. PCRE_FILES_DIR=pcre-8.41
  28. PCRE_PREFIX=/usr/local/pcre

  29. #Define Apache path variables
  30. APACHE_URL=https://mirrors.yangxingzhen.com/apache
  31. APACHE_FILES=httpd-2.4.28.tar.gz
  32. APACHE_FILES_DIR=httpd-2.4.28
  33. APACHE_PREFIX=/usr/local/apache
  34. APACHE_INIT_FILE=/etc/init.d/httpd

  35. #Define Boost path variables
  36. Boost_URL=https://mirrors.yangxingzhen.com/mysql
  37. Boost_File=boost_1_59_0.tar.gz

  38. #Define Mysql path variables
  39. MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
  40. MYSQL_FILES=mysql-5.7.29.tar.gz
  41. MYSQL_FILES_DIR=mysql-5.7.29
  42. MYSQL_PREFIX=/usr/local/mysql
  43. MYSQL_DIR=/data/mysql
  44. MYSQL_USER=mysql

  45. #Define PHP path variables
  46. PHP_URL=http://mirrors.sohu.com/php
  47. PHP_FILE=php-7.3.7.tar.gz
  48. PHP_FILE_DIR=php-7.3.7
  49. PHP_PREFIX=/usr/local/php
  50. USER=apache

  51. #Define ZIP path variables
  52. ZIP_URL=https://nih.at/libzip
  53. ZIP_FILE=libzip-1.2.0.tar.gz
  54. ZIP_FILE_DIR=libzip-1.2.0

  55. #Define Wordpress path variables
  56. WORD_URL=https://mirrors.yangxingzhen.com/wordpress
  57. WORD_FILES=wordpress-5.4-zh_CN.zip
  58. WORD_FILES_DIR=wordpress

  59. function Install_Apache (){
  60. #Install APR
  61. if [ ! -d ${APR_PREFIX} ];then
  62. yum -y install gcc gcc-c++ wget
  63. cd ${HOME} && wget -c ${APR_URL}/${APR_FILES}
  64. tar zxf ${APR_FILES}
  65. cd ${APR_FILES_DIR}
  66. ./configure --prefix=${APR_PREFIX}
  67. if [ $? -eq 0 ];then
  68. make && make install
  69. action "The APR Install Sussess..." /bin/true
  70. else
  71. aciton "The APR Install Failed..." /bin/false
  72. exit 1
  73. fi
  74. else
  75. echo -e "\033[32mThe APR Already Install...\033[0m"
  76. fi

  77. #Install APR-util
  78. if [ ! -d ${APR_UTIL_PREFIX} ];then
  79. yum -y install expat expat-devel
  80. cd ${HOME} && wget -c ${APR_UTIL_URL}/${APR_UTIL_FILES}
  81. tar zxf ${APR_UTIL_FILES}
  82. cd ${APR_UTIL_FILES_DIR}
  83. ./configure --prefix=${APR_UTIL_PREFIX} --with-apr=${APR_PREFIX}
  84. if [ $? -eq 0 ];then
  85. make && make install
  86. action "The APR-util Install Sussess..." /bin/true
  87. else
  88. aciton "The APR-util Install Failed..." /bin/false
  89. exit 1
  90. fi
  91. else
  92. echo -e "\033[32mThe APR-util Already Install...\033[0m"
  93. fi

  94. #Install PCRE
  95. if [ ! -d ${PCRE_PREFIX} ];then
  96. cd ${HOME} && wget -c ${PCRE_URL}/${PCRE_FILES}
  97. tar zxf ${PCRE_FILES}
  98. cd ${PCRE_FILES_DIR}
  99. ./configure --prefix=${PCRE_PREFIX}
  100. if [ $? -eq 0 ];then
  101. make && make install
  102. action "The PCRE Install Sussess..." /bin/true
  103. else
  104. aciton "The PCRE Install Failed..." /bin/false
  105. exit 1
  106. fi
  107. else
  108. echo -e "\033[32mThe PCRE Already Install...\033[0m"
  109. fi

  110. #Install Apache
  111. if [ ! -d ${APACHE_PREFIX} ];then
  112. yum -y install openssl openssl-devel
  113. cd ${HOME} && wget -c ${APACHE_URL}/${APACHE_FILES}
  114. tar zxf ${APACHE_FILES}
  115. cd ${APACHE_FILES_DIR}
  116. ./configure --prefix=${APACHE_PREFIX} \
  117. --with-apr=${APR_PREFIX} \
  118. --with-apr-util=${APR_UTIL_PREFIX} \
  119. --enable-so \
  120. --enable-rewrite \
  121. --enable-ssl \
  122. --with-pcre=${PCRE_PREFIX} \
  123. --with-mpm=worker
  124. if [ $? -eq 0 ];then
  125. make && make install
  126. action "The Apache Install Sussess..." /bin/true
  127. else
  128. aciton "The Apache Install Failed..." /bin/false
  129. exit 1
  130. fi
  131. else
  132. echo -e "\033[32mThe Apache Already Install...\033[0m"
  133. exit 0
  134. fi
  135. }

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

  140. #Install Boost
  141. cd ${HOME} && wget -c ${Boost_URL}/${Boost_File}
  142. tar zxf ${Boost_File} -C /usr/local/

  143. #Install MYSQL
  144. wget -c ${MYSQL_URL}/${MYSQL_FILES}
  145. tar zxf ${MYSQL_FILES}
  146. cd ${MYSQL_FILES_DIR}
  147. cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
  148. -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
  149. -DMYSQL_DATADIR=${MYSQL_DIR} \
  150. -DSYSCONFDIR=/etc \
  151. -DEXTRA_CHARSETS=all \
  152. -DDEFAULT_CHARSET=utf8 \
  153. -DDEFAULT_COLLATION=utf8_general_ci \
  154. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  155. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  156. -DWITH_MEMORY_STORAGE_ENGINE=1 \
  157. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  158. -DDOWNLOAD_BOOST=1 \
  159. -DWITH_BOOST=/usr/local/boost_1_59_0 \
  160. -DENABLED_LOCAL_INFILE=1 \
  161. -DMYSQL_TCP_PORT=3306 \
  162. -DWITH_READLINE=1 \
  163. -DMYSQL_USER=${MYSQL_USER} \
  164. -DWITH_SSL=yes
  165. if [ $? -eq 0 ];then
  166. make && make install
  167. action "The Mysql Install Sussess..." /bin/true
  168. else
  169. action "The Mysql Install Failed..." /bin/false
  170. exit 1
  171. fi
  172. else
  173. echo -e "\033[31mThe Mysql Already Install...\033[0m"
  174. exit 1
  175. fi
  176. }

  177. function Install_PHP() {
  178. #Install Libzip
  179. yum –y install wget gcc gcc-c++
  180. cd ${HOME} && wget -c ${ZIP_URL}/${ZIP_FILE}
  181. tar zxf ${ZIP_FILE}
  182. cd ${ZIP_FILE_DIR}
  183. ./configure
  184. if [ $? -eq 0 ];then
  185. make && make install
  186. action "The Libzip Install Sussess..." /bin/true
  187. else
  188. action "The Libzip Install Failed..." /bin/false
  189. exit 1
  190. fi

  191. cat >/etc/ld.so.conf <<EOF
  192. /usr/local/lib64
  193. /usr/local/lib
  194. /usr/lib
  195. /usr/lib64
  196. EOF
  197. ldconfig -v

  198. #Install PHP
  199. if [ ! -d ${PHP_PREFIX} ];then
  200. #Install Package
  201. yum -y install epel-release
  202. 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
  203. cd ${HOME} && wget -c ${PHP_URL}/${PHP_FILE}
  204. tar zxf ${PHP_FILE}
  205. cd ${PHP_FILE_DIR}
  206. ./configure --prefix=${PHP_PREFIX} \
  207. --with-config-file-path=/etc \
  208. --with-apxs2=/usr/local/apache/bin/apxs \
  209. --enable-fpm \
  210. --with-fpm-user=${USER} \
  211. --with-fpm-group=${USER} \
  212. --enable-inline-optimization \
  213. --disable-debug \
  214. --disable-rpath \
  215. --enable-shared \
  216. --enable-soap \
  217. --with-libxml-dir \
  218. --with-xmlrpc \
  219. --with-openssl \
  220. --with-mhash \
  221. --with-pcre-regex \
  222. --with-sqlite3 \
  223. --with-zlib \
  224. --enable-bcmath \
  225. --with-iconv \
  226. --with-bz2 \
  227. --enable-calendar \
  228. --with-curl \
  229. --with-cdb \
  230. --enable-dom \
  231. --enable-exif \
  232. --enable-fileinfo \
  233. --enable-filter \
  234. --with-pcre-dir \
  235. --enable-ftp \
  236. --with-gd \
  237. --with-openssl-dir \
  238. --with-jpeg-dir \
  239. --with-png-dir \
  240. --with-zlib-dir \
  241. --with-freetype-dir \
  242. --enable-gd-jis-conv \
  243. --with-gettext \
  244. --with-gmp \
  245. --with-mhash \
  246. --enable-json \
  247. --enable-mbstring \
  248. --enable-mbregex \
  249. --enable-mbregex-backtrack \
  250. --with-onig \
  251. --enable-pdo \
  252. --with-mysqli=mysqlnd \
  253. --with-pdo-mysql=mysqlnd \
  254. --with-zlib-dir \
  255. --with-pdo-sqlite \
  256. --with-readline \
  257. --enable-session \
  258. --enable-shmop \
  259. --enable-simplexml \
  260. --enable-sockets \
  261. --enable-sysvmsg \
  262. --enable-sysvsem \
  263. --enable-sysvshm \
  264. --enable-wddx \
  265. --with-libxml-dir \
  266. --with-xsl \
  267. --enable-zip \
  268. --enable-mysqlnd-compression-support \
  269. --with-pear \
  270. --enable-opcache
  271. if [ $? -eq 0 ];then
  272. \cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
  273. make && make install
  274. action "The PHP Install Sussess..." /bin/true
  275. else
  276. action "The PHP Install Failed..." /bin/false
  277. exit 1
  278. fi
  279. else
  280. echo -e "\033[31mThe PHP already Install...\033[0m"
  281. exit 1
  282. fi
  283. }



  284. function LAMP_Config() {
  285. #Apache config and Integrating PHP
  286. useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
  287. \cp ${APACHE_PREFIX}/bin/apachectl ${APACHE_INIT_FILE}
  288. chmod o+x ${APACHE_INIT_FILE}
  289. sed -i 's/User daemon/User apache/' ${APACHE_PREFIX}/conf/httpd.conf
  290. sed -i 's/Group daemon/Group apache/' ${APACHE_PREFIX}/conf/httpd.conf
  291. sed -i '/AddType *.* .tgz/a\\tAddType application/x-httpd-php .php' ${APACHE_PREFIX}/conf/httpd.conf
  292. sed -i 's/index.html/index.php index.html/' ${APACHE_PREFIX}/conf/httpd.conf
  293. sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/' ${APACHE_PREFIX}/conf/httpd.conf

  294. #Config PHP
  295. \cp php.ini-production /etc/php.ini
  296. \cp ${PHP_PREFIX}/etc/php-fpm.conf.default ${PHP_PREFIX}/etc/php-fpm.conf
  297. \cp ${PHP_PREFIX}/etc/php-fpm.d/www.conf.default ${PHP_PREFIX}/etc/php-fpm.d/www.conf
  298. \cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
  299. cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
  300. [www]
  301. listen = 0.0.0.0:9000
  302. listen.mode = 0666
  303. user = ${USER}
  304. group = ${USER}
  305. pm = dynamic
  306. pm.max_children = 128
  307. pm.start_servers = 20
  308. pm.min_spare_servers = 5
  309. pm.max_spare_servers = 35
  310. pm.max_requests = 10000
  311. rlimit_files = 1024
  312. slowlog = log/\$pool.log.slow
  313. EOF

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

  346. #Initialization Mysql
  347. /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
  348. ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
  349. \cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
  350. chmod o+x /etc/init.d/mysqld

  351. #Start Mysql、php-fpm、Apache and Add MySQL、php-fpm、Apache boot self start
  352. ${APACHE_INIT_FILE} restart
  353. systemctl start php-fpm
  354. /etc/init.d/mysqld start
  355. sed -i '/#!\/bin\/sh/a#description: apache web server' ${APACHE_INIT_FILE}
  356. sed -i '/#!\/bin\/sh/a#chkconfig: - 20 90' ${APACHE_INIT_FILE}
  357. chkconfig --add httpd
  358. chkconfig httpd on
  359. chkconfig --add mysqld
  360. chkconfig mysqld on
  361. systemctl enable php-fpm
  362. }

  363. function Install_WordPress() {
  364. #WordPress Config
  365. cd ${HOME} && wget ${WORD_URL}/${WORD_FILES}
  366. unzip ${WORD_FILES}
  367. \cp -a wordpress/* ${APACHE_PREFIX}/htdocs
  368. chown -R ${USER}.${USER} ${APACHE_PREFIX}/htdocs
  369. mysql -e "create database wordpress charset=utf8;"
  370. mysql -e "grant all on wordpress.* to wordpress@'localhost' identified by '123456';"
  371. mysql -e "flush privileges"
  372. }

  373. function Main() {
  374. Install_Apache
  375. Install_Mysql
  376. Install_PHP
  377. LAMP_Config
  378. Install_WordPress
  379. }

  380. Main

脚本执行方式:

[root@localhost ~]# vim auto_install_lamp_wordpress.sh

  • 输入编号:6762,直达文章
  • 输入m|M,直达目录列表

标签:FILES,bin,enable,--,PREFIX,LAMP,WordPress,Install,搭建
From: https://blog.51cto.com/u_12018693/5980592

相关文章

  • WordPress添加支付宝第三方登录功能
    OpenSocial操作简单适用范围广;可操作性强;无第三方平台、无接口文件冗余;功能特点社交登陆:腾讯QQ、微博、微信、豆瓣、谷歌、微软、Facebook、Twitter、Github等社交分享:QQ......
  • WordPress添加百度第三方登录功能
    OpenSocial操作简单适用范围广;可操作性强;无第三方平台、无接口文件冗余;功能特点社交登陆:腾讯QQ、微博、微信、豆瓣、谷歌、微软、Facebook、Twitter、Github等社交分享:QQ......
  • 使用Docker Registry快速搭建私有镜像仓库
    1、Docker是什么?Docker是Docker.Lnc公司开源的一个基于LXC技术之上搭建的Container容器引擎,源代码托管在Github上,基于Go语言并遵从Apache2.0协议开源。Docker属于Linux容器......
  • Windows下PHP开发环境搭建
    介绍几种快速搭建PHP本地开发环境的方式1.xampp2.phpstudy3.Laragon集成开发环境: https://laragon.org/docs/4.Wamp5.在子系统中安装Linux版本的lnmp环境(1.使用宝......
  • 【Java框架型项目从入门到装逼】第七节 - 学生管理系统项目搭建
    本次的教程是打算用Spring,SpringMVC以及传统的jdbc技术来制作一个简单的增删改查项目,对用户信息进行增删改查,就这么简单。###1.新建项目首先,打开eclipse,新建一个web项目。......
  • Maven搭建SpringMvc+Spring+Hibernate框架
    假设你已经在Myeclipse上面创建好啦一个Maven项目,现在我们开始往pom.xml里面新增jar的配置。1.<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://ww......
  • zookeeper集群搭建中服务启动常见问题
    1、执行./zkServer.shstart后查看服务状态显示Itisprpbably isnotrunning.但是查看进程jps,zookeeper服务进程是正常启动的。解决办法:先停止zookeeper服务./zkServer.......
  • Android开发环境搭建
    现在主流的Android开发环境有:①Eclipse+ADT+SDK②AndroidStudio+SDK③IntelliJIDEA+SDK现在国内大部分开发人员还是使用的Eclipse,而谷歌宣布不再更新ADT后,并且官......
  • bind搭建服务器成功啦!
    bind搭建权威服务器成功啦!只限自己用,不做不合规矩的事。非常感谢王某工作室,很早就像搭建了,网上百度了很多,网文写的不全面,内容都差不多,还是找个专业人士帮忙,快的多。赞 ......
  • BBS项目(二):首页导航条搭建 修改密码功能 首页数据展示 个人站点页面
    目录首页导航条搭建session判断用户是否登录更换验证码导航条更多功能退出系统修改密码前端页面使用大模态框编写模态框前端表单编写修改密码后端逻辑接受参数验证参数修改......