基于LNMP快速简单搭建wordpress平台


一、WordPress简介

  WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把WordPress当作一个内容管理系统(CMS )来使用。WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的。用户可以在支持PHP和MySQL数据库的服务器上使用自己的博客。WordPress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS,PHP等相关知识。WordPress官方支持中文版,同时有爱好者开发的第三方中文语言包,如wopus中文语言包。WordPress拥有成千上万个各式插件和不计其数的主题模板样式。

 

 二、关闭防火墙

 

三、基础环境要求

  MySQL、PHP、Nginx

四、安装MySQL环境

  ①安装MySQL

    [root@localhost yum.repos.d]# wget  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

    [root@localhost yum.repos.d]# ls
      mysql57-community-release-el7-10.noarch.rpm

    [root@localhost yum.repos.d]# yum -y install mysql57-community-release-el7-10.noarch.rpm

[root@localhost yum.repos.d]# ls
  mysql-community.repo  mysql-community-source.repo  mysql57-community-release-el7-10.noarch.rpm

    [root@localhost yum.repos.d]# yum -y install mysql-community-server

    报错【mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm 的公钥尚未安装

失败的软件包是:mysql-community-libs-compat-5.7.38-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

解决方法【rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

 

  ②启动MySQL

[root@localhost yum.repos.d]# systemctl start mysqld
[root@localhost yum.repos.d]# ps aux | grep mysqld
  mysql 17487 1.4 9.0 1121852 168096 ? Sl 21:49 0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
  root 17742 0.0 0.0 112824 976 pts/0 S+ 21:50 0:00 grep --color=auto mysqld
[root@localhost yum.repos.d]# lsof -i:3306
  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  mysqld 17487 mysql 21u IPv6 75005 0t0 TCP *:mysql (LISTEN)

  ③获取MySQL默认密码

    [root@localhost yum.repos.d]# grep 'password' /var/log/mysqld.log
      2022-05-25T13:49:47.529145Z 1 [Note] A temporary password is generated for root@localhost: G(IZwIz)h65e

  ④登陆MySQL

    [root@localhost yum.repos.d]# mysql  -uroot  -p'G(IZwIz)h65e' 

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>

  ⑤修改MySQL密码

mysql> alter user 'root'@'localhost' identified by 'G(IZwIz)h65e1';
  Query OK, 0 rows affected (0.01 sec)

  ⑥创建wordpress数据库并授权

mysql> create database wordpress;
  Query OK, 1 row affected (0.00 sec)

mysql> create user 'wordpress'@'localhost' identified by 'G(IZwIz)h65e1';
  Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on wordpress.* to 'wordpress'@'localhost';
  Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)

五、安装Nginx环境

  ①安装Nginx

[root@www tmp]# rpm  -Uvh  https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

[root@localhost yum.repos.d]# ls /etc/yum.repos.d/
  CentOS-y  mysql-community.repo  mysql-community-source.repo   nginx.repo

    [root@localhost yum.repos.d]# yum  -y install nginx

  ②添加Nginx的虚拟主机配置文件

    [root@localhost yum.repos.d]# vim /etc/nginx/conf.d/wordpress.conf

server {
  listen 8081;
  server_name localhost;

  fastcgi_buffer_size 1M;
  fastcgi_buffers 32 512k;
  fastcgi_busy_buffers_size 1M;

  root /var/www/web/wordpress;

  location / {
    index index.php index.html index.htm;
    if (!-e $request_filename) {
      rewrite ^/(.*) /index.php?$1 last;
    }
  }

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root html;
  }
}

 

     [root@localhost yum.repos.d]# nginx -s reload    #重新加载一些配置文件

    如果重启失败,应该是我们的配置文件语法错误,可使用nginx -t命令查看错误详情

    如果在重新加载配置报错【nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)】

    解决方法【①先核实nginx.conf中pid指向位置是否对应报错,②进行启动Nginx,在重新加载配置文件即可】

[root@localhost run]# systemctl start nginx
[root@localhost run]# ps -ef | grep nginx
  root 45411 1 0 09:17 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  nginx 45412 45411 0 09:17 ? 00:00:00 nginx: worker process
  nginx 45413 45411 0 09:17 ? 00:00:00 nginx: worker process
  nginx 45414 45411 0 09:17 ? 00:00:00 nginx: worker process
  nginx 45415 45411 0 09:17 ? 00:00:00 nginx: worker process
  root 45440 33960 0 09:17 pts/1 00:00:00 grep --color=auto nginx
[root@localhost run]# nginx -s reload

六、安装PHP环境

①安装remi源

  [root@localhost yum.repos.d]# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

[root@localhost yum.repos.d]# ls

remi-php71.repo  remi-php72.repo  remi-glpi91.repo  remi-php73.repo  remi-glpi92.repo  remi-php74.repo  remi-glpi93.repo  remi-php80.repo  remi-glpi94.repo  remi-php81.repo  remi-modular.repo  remi.repo  remi-php54.repo  remi-safe.repo  epel.repo  remi-php70.repo

②安装yum源管理工具

  [root@localhost yum.repos.d]# yum -y install yum-utils

③安装PHP 7.3

[root@localhost yum.repos.d]# yum -y install  php73-php-fpm  php73-php-cli  php73-php-bcmath  php73-php-gd  php73-php-json  php73-php-mbstring  php73-php-mcrypt  php73-php-mysqlnd  php73-php-opcache  php73-php-pdo  php73-php-pecl-crypto  php73-php-pecl-mcrypt  php73-php-pecl-geoip  php73-php-recode  php73-php-snmp  php73-php-soap  php73-php-xmll

 

④重启php服务

  [root@localhost yum.repos.d]# systemctl restart php73-php-fpm  #重启php, 开机自启enable

  ⑤检查端口9000

[root@localhost yum.repos.d]# lsof  -i:9000
  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  php-fpm 63760 root 6u IPv4 307057 0t0 TCP localhost:cslistener (LISTEN)
  php-fpm 63771 apache 0u IPv4 307057 0t0 TCP localhost:cslistener (LISTEN)
  php-fpm 63772 apache 0u IPv4 307057 0t0 TCP localhost:cslistener (LISTEN)
  php-fpm 63773 apache 0u IPv4 307057 0t0 TCP localhost:cslistener (LISTEN)

七、安装WordPress

  ①下载并解压

    [root@localhost tmp]# wget https://wordpress.org/latest.tar.gz

    [root@localhost tmp]# tar  xf  /tmp/latest.tar.gz -C /usr/ local/

  ②设置WordPress

    设置wp-config.php文件,根据自己的数据库修改相关的配置

[root@localhost local]# mv wordpress/  /  #剪切到/目录下

[root@localhost /]# chmod -R 777 /var/www/web/wordpress/  #授权

[root@localhost wordpress]# cp wp-config-sample.php   /var/www/web/wordpress/wp-config.php
[root@localhost wordpress]# vim wp-config.php

/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'wordpress' );

/** Database password */
define( 'DB_PASSWORD', 'G(IZwIz)h65e1' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

 

 

访问地址:http://192.168.112.147:8081/