系统相关
首页 > 系统相关> > Linux-利用LNMP 实现wordpress站点搭建

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数据库,redis服务

 

centos7 10.0.0.37 安装数据库

[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数据库...
useradd: user 'mysql' already exists
创建myslq用户                                              [  OK  ]
Enter password:                            #确认密码123456
数据库安装完成                                             [  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 "数据库已存在,安装失败" false
      exit
else
   return
fi
}

install_mysql(){
  $COLOR"开始安装MySQL数据库..."$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"数据库启动失败,退出!"$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 "数据库安装完成"
}

check

install_mysql
脚本

创建wordpress 数据库和用户授权

[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;     #创建数据库
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

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:11,www,--,LNMP,wordpress,usr,Linux,php,root
来源: https://www.cnblogs.com/lyj1023/p/16367056.html