微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linux-利用LNMP 实现wordpress站点搭建

LNMP项目实战环境说明

L:Linux(CentOS7)https://mirrors.aliyun.com/centos/7/isos/x86_64/
N:Nginx(1.18.0) https://Nginx.org/en/download.html
M:MysqL(8.0.19) https://dev.MysqL.com/downloads/MysqL/
P:PHP(7.4.10)   http://PHP.net/downloads.PHP
wordpress(5.4.2) https://cn.wordpress.org/download/

设备

centos7  10.0.0.27  : Nginx    PHP-fpm  运行web服务

centos7  10.0.0.37  :运行MysqL@R_404_6274@,redis服务

 

centos7 10.0.0.37 安装@R_404_6274@

[root@client ~]#ll
total 473716
-rw-------. 1 root root      1580 Apr 18 18:20 anaconda-ks.cfg
-rw-r--r--  1 root root      1780 Jun 11 14:53 install_MysqL5.7or8.0_centos.sh
-rw-r--r--  1 root root 485074552 Dec 10  2019 mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

脚本安装MysqL

[root@client ~]#bash  install_MysqL5.7or8.0_centos.sh 
开始安装MysqL@R_404_6274@...
useradd: user 'MysqL' already exists
创建myslq用户                                              [  OK  ]
Enter password:                            #确认密码123456
@R_404_6274@安装完成                                             [  OK  ]

[root@client ~]#cat install_MysqL5.7or8.0_centos.sh 
#!/bin/bash
#
#
#liyanjin
. /etc/init.d/functions
SRC_DIR=`pwd`
MysqL='mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz'
COLOR='echo -e \E[01:31m'
END='\E[0m'
MysqL_ROOT_PASSWORD='123456'

check () {

if [ $UID -ne 0 ];then
   action "当前用户不是root,安装失败" false
   exit 1
fi

cd $SRC_DIR
if [ ! -e $MysqL ];then
    $COLOR"缺少${MysqL}文件"$END
    $COLOR"请将相关软件放在${SRC_DIR}目录下"$END
      exit
elif [ -e /usr/local/MysqL ];then
     action "@R_404_6274@已存在,安装失败" false
      exit
else
   return
fi
}

install_MysqL(){
  $COLOR"开始安装MysqL@R_404_6274@..."$END
  yum -y -q install libaio numactl-libs libaio &> /dev/null
  cd $SRC_DIR
  tar xf $MysqL -C /usr/local/
  MysqL_DIR=`echo $MysqL| sed -nr 's/^(.*[0-9]).*/\1/p'`
  ln -s /usr/local/$MysqL_DIR /usr/local/MysqL
  chown -R root.root /usr/local/MysqL/
  id MysqL &> /dev/full || { useradd -s /sbin/nologin -r MysqL ; action "创建myslq用户"; }

  echo 'PATH=/usr/local/MysqL/bin/:$PATH' > /etc/profile.d/MysqL.sh
  . /etc/profile.d/MysqL.sh
  ln -s /usr/local/MysqL/bin/*   /usr/bin/
  cat > /etc/my.cnf <<-EOF
[MysqLd]
server-id=`hostname -I|cut -d. -f4`
log-bin
datadir=/data/MysqL
socket=/data/MysqL/MysqL.sock

log-error=/data/MysqL/MysqL.log
pid-file=/data/MysqL/MysqL.pid
[client]
socket=/data/MysqL/MysqL.sock
EOF

   cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
   chkconfig --add MysqLd
   chkconfig MysqLd on
   systemctl start MysqLd
   [ $? -ne 0 ] && { $COLOR"@R_404_6274@启动失败,退出!"$END;exit; }
   MysqL_OLDPASSWORD= `awk '/A temporary password/{print $NF}' /data/MysqL/MysqL.log`
   MysqLadmin -uroot -p$MysqL_OLDPASSWORD password $MysqL_ROOT_PASSWORD &> /dev/null
   action "@R_404_6274@安装完成"
}

check

install_MysqL
脚本

创建wordpress @R_404_6274@和用户授权

[root@client ~]#MysqL -uroot -p123456
MysqL: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 19
Server version: 8.0.28 MysqL Community Server - GPL

copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL> create database wordpress;     #创建@R_404_6274@
Query OK, 1 row affected (0.01 sec)

MysqL> create user wordpress@'10.0.0.%' identified by '123456';  创建用户wordpress
Query OK, 0 rows affected (0.01 sec)

MysqL> grant all on wordpress.* to wordpress@'10.0.0.%';     授权用户访问wordpress库所有表
Query OK, 0 rows affected (0.00 sec)

10.0.0.27 主机编译 PHP-fpm

[root@lnpw ~]#yum -y install gcc openssl-devel libxml2-devel bzip2-devel sqlite-devel #安装依赖关系
[root@lnpw ~]#wget https://www.PHP.net/distributions/PHP-7.4.11.tar.xz   #下载PHP编译包
[root@lnpw ~]#tar xfv PHP-7.4.11.tar.xz  -C /usr/local/src/              #解压文件

进入目录编译安装

[root@lnpw ~]#cd /usr/local/src/PHP-7.4.11/
[root@lnpw /usr/local/src/PHP-7.4.11]#ls
appveyor             buildconf.bat        docs        NEWS                 README.REdisT.BINS  travis               Zend
azure                CODING_STANDARDS.md  ext         pear                 run-tests.PHP       TSRM
azure-pipelines.yml  configure            EXTENSIONS  PHP.ini-development  sapi                UPGRADING
build                configure.ac         LICENSE     PHP.ini-production   scripts             UPGRADING.INTERNALS
buildconf            CONTRIBUTING.md      main        README.md            tests               win32
[root@lnpw /usr/local/src/PHP-7.4.11]#./configure --prefix=/usr/local/PHP74 --enable-MysqLnd --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-ablembstring --enable-xml --enable-sockets --enable-fpm
--enable-maintainer-zts --disable-fileinfo
[root@lnpw /usr/local/src/PHP-7.4.11]#make -j 2 && make install

准备配置文件

生成配置文件
[root@lnpw /usr/local/src/PHP-7.4.11]#cp /usr/local/src/PHP-7.4.11/PHP.ini-production /etc/PHP.ini [root@lnpw /usr/local/src/PHP-7.4.11]#cd /usr/local/PHP74/etc/ [root@lnpw /usr/local/PHP74/etc]#ls PHP-fpm.conf.default PHP-fpm.d [root@lnpw /usr/local/PHP74/etc]#cp PHP-fpm.conf.default PHP-fpm.conf [root@lnpw /usr/local/PHP74/etc]#ls PHP-fpm.conf PHP-fpm.conf.default PHP-fpm.d [root@lnpw /usr/local/PHP74/etc]# [root@lnpw /usr/local/PHP74/etc/PHP-fpm.d]#vim www.conf [root@lnpw /usr/local/PHP74/etc/PHP-fpm.d]#grep '^[^;]' www.conf

 [root@lnpw /usr/local/PHP74/etc/PHP-fpm.d]#grep '^[^;]' www.conf
 [www]
 user = www
 group = www
 listen = 127.0.0.1:9000
 pm = dynamic
 pm.max_children = 5
 pm.start_servers = 2
 pm.min_spare_servers = 1
 pm.max_spare_servers = 3
 pm.status_path = /pm_status
 ping.path = /ping
 access.log = log/$pool.access.log
 slowlog = log/$pool.log.slow

[root@lnpw /usr/local/PHP74/etc/PHP-fpm.d]#useradd -r -s /sbin/nologin www   #创建用户
[root@lnpw /usr/local/PHP74/etc/PHP-fpm.d]#mkdir /usr/local/log   #创建访问日志文件路径
[root@centos7-liyj ~]#vim /usr/local/PHP74/etc/PHP-fpm.conf
[global]
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; into a local file.
; Note: the default prefix is /usr/local/PHP74/var
; Default Value: log/PHP-fpm.log
error_log = log/PHP-fpm.log    #启用PHP-fpm.log日志

 

启动并验证 PHP-fpm服务

[root@lnpw ~]#/usr/local/PHP74/sbin/PHP-fpm -t
[11-Jun-2022 18:26:12] NOTICE: configuration file /usr/local/PHP74/etc/PHP-fpm.conf test is successful
[root@lnpw ~]#cp /usr/local/src/PHP-7.4.11/sapi/fpm/PHP-fpm.service /usr/lib/systemd/system/

[root@centos7-liyj ~]#vim /usr/lib/systemd/system/PHP-fpm.service
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.    #调用的进程装载只读的/usr、/boot和/etc目录
#ProtectSystem=full #注释此行
ProtectSystem=false #复制值改为 false ,否则PHP-fpm启动失败

Jun 11 22:16:09 centos7-liyj systemd: Started The PHP FastCGI Process Manager.
Jun 11 22:16:09 centos7-liyj PHP-fpm: [11-Jun-2022 22:16:09] ERROR: Failed to open error_log (/usr/local/PHP74/var/log/PHP-fpm.log): Read-only file system (30)
Jun 11 22:16:09 centos7-liyj PHP-fpm: [11-Jun-2022 22:16:09] ERROR: Failed to post process the configuration
Jun 11 22:16:09 centos7-liyj PHP-fpm: [11-Jun-2022 22:16:09] ERROR: FPM initialization Failed
Jun 11 22:16:09 centos7-liyj systemd: PHP-fpm.service: main process exited, code=exited, status=78/n/a
Jun 11 22:16:09 centos7-liyj systemd: Unit PHP-fpm.service entered Failed state.
Jun 11 22:16:09 centos7-liyj systemd: PHP-fpm.service Failed.
ProtectSystem=full时错误日志

重新加载日志并设置开机启动

[root@lnpw ~]#systemctl daemon-reload
[root@lnpw ~]#systemctl enable --Now PHP-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/PHP-fpm.service to /usr/lib/systemd/system/PHP-fpm.service.
[root@lnpw ~]#

准备测试页

[root@centos7-liyj ~]#mkdir -p /data/Nginx/wordpress
[root@centos7-liyj ~]#vim /data/Nginx/wordpress/test.PHP
[root@centos7-liyj ~]#cat /data/Nginx/wordpress/test.PHP
<?PHP
PHPinfo();
?>

验证测试页

 

 

 

 

 

 部署wordpress

10.0.0.27主机

[root@centos7-liyj ~]#wget https://cn.wordpress.org/latest-zh_CN.tar.gz   #下载wordpresss
--2022-06-11 22:33:52--  https://cn.wordpress.org/latest-zh_CN.tar.gz
Resolving cn.wordpress.org (cn.wordpress.org)... 198.143.164.252
Connecting to cn.wordpress.org (cn.wordpress.org)|198.143.164.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21871609 (21M) [application/octet-stream]
Saving to: ‘latest-zh_CN.tar.gz’

100%[===============================================================================>] 21,871,609  4.88MB/s   in 5.3s   

2022-06-11 22:33:59 (3.96 MB/s) - ‘latest-zh_CN.tar.gz’ saved [21871609/21871609]

[root@centos7-liyj ~]#ll
total 21364
-rw-------. 1 root root     1580 Apr 18 18:20 anaconda-ks.cfg
-rw-r--r--  1 root root 21871609 Jun 11 20:00 latest-zh_CN.tar.gz
[root@centos7-liyj ~]#tar xf latest-zh_CN.tar.gz             #解压缩
[root@centos7-liyj ~]#ll
total 21368
-rw-------. 1 root root     1580 Apr 18 18:20 anaconda-ks.cfg
-rw-r--r--  1 root root 21871609 Jun 11 20:00 latest-zh_CN.tar.gz
drwxr-xr-x  5 1006 1006     4096 Jun 11 20:00 wordpress

递归复制到/data/Nginx/wordpress目录下

[root@centos7-liyj ~]#cp -r wordpress/* /data/Nginx/wordpress/
[root@centos7-liyj ~]#chown -R www.www /data/Nginx/wordpress/
[root@centos7-liyj ~]#ll /data/Nginx/wordpress/
total 216
-rw-r--r--  1 www www   405 Jun 11 22:41 index.PHP
-rw-r--r--  1 www www 19915 Jun 11 22:41 license.txt
-rw-r--r--  1 www www  7401 Jun 11 22:41 readme.html
-rw-r--r--  1 www www    20 Jun 11 22:28 test.PHP
-rw-r--r--  1 www www  7165 Jun 11 22:41 wp-activate.PHP
drwxr-xr-x  9 www www  4096 Jun 11 22:41 wp-admin
-rw-r--r--  1 www www   351 Jun 11 22:41 wp-blog-header.PHP
-rw-r--r--  1 www www  2338 Jun 11 22:41 wp-comments-post.PHP
-rw-r--r--  1 www www  3001 Jun 11 22:41 wp-config-sample.PHP
drwxr-xr-x  5 www www    69 Jun 11 22:41 wp-content
-rw-r--r--  1 www www  3943 Jun 11 22:41 wp-cron.php
drwxr-xr-x 26 www www 12288 Jun 11 22:41 wp-includes
-rw-r--r--  1 www www  2494 Jun 11 22:41 wp-links-opml.PHP
-rw-r--r--  1 www www  3973 Jun 11 22:41 wp-load.PHP
-rw-r--r--  1 www www 48498 Jun 11 22:41 wp-login.PHP
-rw-r--r--  1 www www  8577 Jun 11 22:41 wp-mail.PHP
-rw-r--r--  1 www www 23706 Jun 11 22:41 wp-settings.PHP
-rw-r--r--  1 www www 32051 Jun 11 22:41 wp-signup.PHP
-rw-r--r--  1 www www  4748 Jun 11 22:41 wp-trackback.PHP
-rw-r--r--  1 www www  3236 Jun 11 22:41 xmlrpc.PHP

初始化web页面

打开浏览器输入以下连接

www.lyj.org

 

 

 

 

 

 

 

 

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐