之前学习Apache了解过LAMP(Linux、Apache、Mysql、Perl/PHP/Python)
由于上述架构,已然是一个商业版软件的代名词,后来自由软件趋势兴起,如何用开源软件替代商业软件,这是人们追求的,所有的Linux发行版几乎都会内置这样的软件。
但是由于Nginx的兴趣,卓越的性能,更简单的配置,更强大的功能,更低的资源消耗,LAMP已经渐渐被LNMP取代。
LNMP是网站架构初期最合适的单体架构。因为初创型技术团队对于技术的选型,需要考虑如下因素
- 在创业初期,研发资源有限,研发人力有限,技术储备有限,需要选择一个易维护、简单的技术架构;
- 产品需要快速研发上线,并能够满足快速迭代要求,现实情况决定了一开始没有时间和精力来选择一个过于复杂的分布式架构系统,研发速度必须要快;
- 创业初期,业务复杂度比较低,业务量也比较小,如果选择过于复杂的架构,反而会增加研发难度以及运维难度;
- 遵从选择合适的技术而不是最好的技术原则,并权衡研发效率和产品目标,同时创业初期只有一个PHP研发人员,过于复杂的技术架构必然会带来比较高昂的学习成本。
基于如上的因素,LNMP架构就是最合适的。
如此架构,一般三台服务器足以,Nginx与后台系统部署在一台机器,Mysql数据库单独服务器,Mencached缓存一台服务器。这样的架构优势在于
- 单体架构,架构简单,清晰的分层结构;
- 可以快速研发,满足产品快速迭代要求;
- 没有复杂的技术,技术学习成本低,同时运维成本低,无需专业的运维,节省开支。
LNMP组合工作流程
LNMP工作流是用户通过浏览器输入域名访问Nginx web服务,Nginx判断请求是静态请求则由Nginx返回给用户。如果是动态请求(如.php结尾),那么Nginx会将该请求通过FastCGI接口发送给PHP引擎(php-fpm进程)进行解析,如果该动态请求需要读取mysql数据库,php会继续向后读取数据库,最终Nginx将获取的数据返回给用户。
- 用户通过浏览器输入域名访问到nginx web服务器
- nginx进行用户请求判断
- 静态请求 nginx直接相应给用户
- 动态请求
Nginx安装配置
1.安装nginx所需的pcre库,让nginx支持url重写的rewrite功能yum install pcre pcre-devel -y2.安装openssl-devel模块,nginx需要支持https[root@web01 opt]# yum install openssl openssl-devel -y2.1 安装gcc编译器yum install gcc -y3.下载nginx源码包[root@web01 opt]# mkdir -p /home/chaoge/tools[root@web01 opt]# cd /home/chaoge/tools/[root@web01 tools]# wget http://nginx.org/download/nginx-1.16.0.tar.gz[root@web01 tools]# echo $?04.创建nginx普通用户[root@web01 tools]# useradd nginx -u 1111 -s /sbin/nologin -M5.开始解压缩编译nginx[root@web01 tools]# tar -zxf nginx-1.16.0.tar.gz[root@web01 nginx-1.16.0]# ./configure --user=nginx --group=nginx --prefix=/opt/nginx-1.16.0/ --with-http_stub_status_module --with-http_ssl_module[root@web01 nginx-1.16.0]# echo $?0[root@web01 nginx-1.16.0]# make && make install[root@web01 nginx-1.16.0]# echo $?06.配置软连接,生产环境常用操作,便于运维、开发、测试使用,以及nginx以后的升级[root@web01 nginx-1.16.0]# ln -s /opt/nginx-1.16.0/ /opt/nginx[root@web01 nginx-1.16.0]# ll /opt/总用量 0lrwxrwxrwx 1 root root 18 3月 18 22:45 nginx -> /opt/nginx-1.16.0/drwxr-xr-x 6 root root 54 3月 18 22:43 nginx-1.16.07.配置nginx环境变量[root@web01 ~]# tail -1 /etc/profileexport PATH="/opt/nginx/sbin:/opt/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"[root@web01 ~]#[root@web01 ~]# echo $PATH/opt/nginx/sbin:/opt/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
LNMP之MySQL数据库
Mysql是互联网领域非常重要的,深受广大用户欢迎的一款开源数据库。MysSQL是一款关系型数据库,且把数据保存在不同的二维表,且把数据表再放入数据库中管理,而不是所有的数据统一放在一个大仓库,这样的设计提高MySQL的读写速度。
我们会在后面章节专门学习MYSQL,进阶DBA
安装Mysql
数据库——大的文件夹
数据表——excel表格
安装方式我们可以选择多种
- Yum/rpm包安装,简单、快速、无法定制化、新手推荐使用
- 二进制安装,解压缩后直接简单配置即可使用,速度较快,专业DBA常用
- 源码编译安装,特点是可以定制化安装需求,缺点过程较为复杂 ```shell 1.创建mysql用户 [root@web01 ~]# useradd -s /sbin/nologin mysql [root@web01 ~]# id mysql uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
2.下载mysql二进制软件包,提前配置好yum源,下载wget命令 [root@web01 ~]# yum install wget -y wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.re wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@web01 ~]# mkdir -p /home/mysql/tools [root@web01 ~]# cd /home/mysql/tools/
该mysql文件600M左右,下载时间看网速
[root@web01 tools]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
wget https://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
【软件包选择】2103227582```shellmysql二进制安装包体积较大,名字和源代码包有些区别,但是安装过程较快mysql二进制包 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 615Mmysql源码包 mysql-5.7.26.tar.gz 52M
二进制方式安装mysql
我们这里搭建LNMP环境,nginx和mysql是安装在一台机器上的,当然也可以是分开在不同的服务器上
1.解压并且移动mysql二进制软件包路径[root@web01 tools]# tar -zvxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz[root@web01 tools]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /opt/mysql-5.7.262.生成软连接[root@web01 opt]# ln -s /opt/mysql-5.7.26/ /opt/mysql[root@web01 opt]# ls -l /opt/总用量 0lrwxrwxrwx 1 root root 18 3月 18 10:15 mysql -> /opt/mysql-5.7.26/drwxr-xr-x 9 root root 129 3月 18 10:13 mysql-5.7.263.卸载centos7自带的mariadb库,防止冲突[root@web01 mysql]# rpm -e --nodeps mariadb-libs4.手动创建mysql配置文件 vim /etc/my.cnf[mysqld] 是区段的含义,以下的参数对其生效[mysqld] 对服务端生效的参数[mysql] 对客户端生效的参数[root@web01 mysql]# cat /etc/my.cnf[mysqld]# 基础文件夹basedir=/opt/mysql/# mysql产生的相关数据放在这个目录下datadir=/opt/mysql/data# 进程启动之后产生的socketsocket=/tmp/mysql.sockserver_id=1# 数据库启动之后的默认端口port=3306log_error=/opt/mysql/data/mysql_err.log[mysql]socket=/tmp/mysql.sock
初始mysql数据库文件
1.卸载系统自带的centos7 mariadb-libs,且安装mysql的依赖环境rpm -qa mariadb-libs #检查是否存在[root@web01 mysql]# yum install libaio-devel -y2.创建mysql数据文件夹且授权[root@web01 mysql]# mkdir -p /opt/mysql/data[root@web01 mysql]# chown -R mysql.mysql /opt/mysql/3.初始化数据库[root@web01 mysql]# /opt/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/# 参数解释--user=mysql 指定用户--basedir 指定mysql安装目录--datadir=/opt/mysql/data 指定数据文件夹--initialize-insecure 关闭mysql安全策略--initialize 开启mysql安全模式
配置mysql客户端
1.配置mysql启动脚本,定义mysqld.service,脚本如下[root@web01 mysql]# cat /etc/systemd/system/mysqld.service[Unit]Description=MySQL server by chaogeDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnfLimitNOFILE=5000
启动mysql数据库
[root@web01 mysql]# systemctl start mysqld[root@web01 mysql]# systemctl enable mysqldCreated symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.[root@web01 mysql]# systemctl status mysqld● mysqld.service - MySQL server by chaogeLoaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)Active: active (running) since 三 2020-03-18 11:30:01 EDT; 6s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlMain PID: 5315 (mysqld)CGroup: /system.slice/mysqld.service└─5315 /opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf3月 18 11:30:01 web01 systemd[1]: Started MySQL server by chaoge.3月 18 11:30:01 web01 systemd[1]: Starting MySQL server by chaoge...
检查mysql启动状态
[root@web01 mysql]# netstat -tunlp|grep mysqltcp6 0 0 :::3306 :::* LISTEN 5315/mysqld[root@web01 mysql]# ps -ef|grep mysql |grep -v grepmysql 5315 1 0 11:30 ? 00:00:00 /opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
配置mysql命令环境变量
[root@web01 mysql]# echo "export PATH=/opt/mysql/bin:$PATH" >> /etc/profile
[root@web01 mysql]# source /etc/profile
[root@web01 mysql]# echo $PATH
/opt/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
登录mysql
默认无须输入密码直接进入mysql数据库,且身份是root
[root@web01 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
mysql> select user(); # 查看当前登录的用户
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
# 查看mysql所有用户信息
mysql> select user,authentication_string,host from mysql.user;
+---------------+-------------------------------------------+-----------+
| user | authentication_string | host |
+---------------+-------------------------------------------+-----------+
| root | | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
3 rows in set (0.01 sec)
默认mysql账号root是没有密码的,我们给其设置密码,加大安全性
[root@web01 ~]# mysqladmin -uroot password 'chaoge666'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
# 再次登录,输入密码
[root@web01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
FastCGI介绍
CGI(Common Gateway Interface),全文名是通用网关接口,
用于HTTP服务器和其他机器通信的一种工具。
传统CGI程序性能较弱,因此每次HTTP服务器遇到动态程序的时候,都需要重启解析器来执行解析,之后的处理结果才会返回给HTTP服务器。这样在高并发场景下访问几乎是太差劲了,因此诞生了FastCGI。
FastCGI是一个可伸缩、高速的在HTTP服务器和动态脚本之间通信的接口(在Linux环境下,FastCGI接口就是socket,这个socket可以是文件socket,也可以是IP socket,也就意味着本地通信,远程通信两种),主要优点是把动态语言和HTTP服务器分离开。
- 如果http服务器和后端程序运行在两台服务器上,这个fastcgi通信形式就是IP+端口的形式
- 如果http服务器和后端程序运行在同一台服务器上,那么socket可以是本地通信
最好是运行在两台机器上。
多数主流的web服务器都支持FastCGI,如Apache、nginx、LightHttpd等
同时FastCGI也被许多脚本语言所支持,比较流行的脚本语言之一为PHP。
Fast-CGI接口采用c/s架构,可以将HTTP服务器和脚本解析服务器分离开。
- 当HTTP服务器遇见静态请求,直接返回,
- 遇见动态请求转发给动态服务器,交给FastCGI去处理,实现动静分离,提升服务器性能。

当HTTP服务器发送一个动态请求给FastCGI。
当进来一个请求时,Web 服务器把环境变量和这个页面请求通过一个unix domain socket(都位于同一物理服务器)或者一个IP Socket(FastCGI部署在其它物理服务器)传递给FastCGI进程。
Nginx FastCGI的运行原理
Nginx默认不支持外部动态程序直接解析,所有的外部程序都得通过FastCGI接口调用。FastCGI接口运行在LInux平台默认是socket进程通信,为了调用CGI程序,还需要FastCGI的wrapper(启动cgi的程序),这个wrapper绑定在某个固定的socket上,例如端口或者文件socket都行。
当Nginx把CGI请求发送给该socket,通过FastCGI接口wrapper接收到请求,派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本来读取返回的数据;
wrapper再吧返回的数据通过FastCGI接口沿着固定的socket传递给Nginx;
最后Nginx把返回的数据交给客户端。
FastCGI部署(本地部署)
1.检查Nginx和mysql的安装路径
[root@web01 ~]# ll /opt/
总用量 0
lrwxrwxrwx 1 root root 18 3月 18 10:15 mysql -> /opt/mysql-5.7.26/
drwxr-xr-x 10 mysql mysql 213 3月 18 10:47 mysql-5.7.26
lrwxrwxrwx 1 root root 18 3月 18 22:45 nginx -> /opt/nginx-1.16.0/
drwxr-xr-x 6 root root 54 3月 18 22:43 nginx-1.16.0
2.保证nginx、mysql都启动了
[root@web01 ~]# netstat -tunlp|grep -E "nginx|mysql"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17214/nginx: master
tcp6 0 0 :::3306 :::* LISTEN 5315/mysqld
3.安装部署PHP程序所需的系统库,不要求必须安装,而是安装上之后,可以扩展php更多功能
yum install gcc gcc-c++ make zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel \
freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
默认yum源中缺少libiconv-devel软件包,需要编译安装,用于php的编码转换
[root@web01 ~]# wget -P /home/chaoge/tools/ http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@web01 ~]# cd /home/chaoge/tools/
[root@web01 tools]# ls
libiconv-1.15.tar.gz nginx-1.16.0 nginx-1.16.0.tar.gz
[root@web01 tools]# tar zxf libiconv-1.15.tar.gz
[root@web01 libiconv-1.15]# cd libiconv-1.15
[root@web01 libiconv-1.15]# ./configure --prefix=/opt/libiconv
[root@web01 libiconv-1.15]# make && make install
安装PHP(FastCGI形式)
1.下载获取php软件包
[root@web01 tools]# wget http://mirrors.sohu.com/php/php-7.3.5.tar.gz
2.解压缩php源码包,编译安装
[root@web01 tools]# tar -zxvf php-7.3.5.tar.gz
[root@web01 tools]# cd php-7.3.5
[root@web01 php-7.3.5]#
./configure --prefix=/opt/php7.3.5 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/opt/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
待看到如下显示,表示正确的编译了php
对于如上的参数,根据自己实际工作环境优化增删即可
部分参数解释
--prefix= 指定php安装路径
--enable-mysqlnd 使用php自带的mysql相关软件包
--with-fpm-user=nginx 指定PHP-FPM程序的用户是nginx,和nginx服务保持统一
--enable-fpm 激活php-fpm方式,以FastCGI形式运行php程序
3.在执行完编译脚本文件后,开始执行编译安装
[root@web01 php-7.3.5]# make && make install
看到如此的画面,表示php正确安装结束了,可以用特殊变量验证
[root@web01 php-7.3.5]# echo $?
0

【编译安装结束后,配置环境变量】
[root@web01 php-7.3.5]# ln -s /opt/php7.3.5/ /opt/php
php配置文件
配置文件路径
[root@web01 php-7.3.5]# ls php.ini*
php.ini-development php.ini-production
俩配置文件,分别默认用于开发环境,生成环境,配置参数有所不同
# 可以用如下命令对比文件区别
[root@web01 php-7.3.5]# vimdiff php.ini-development php.ini-production
开发环境下开起了更多的日志、调试信息,生产环境该参数都关闭了
拷贝php配置文件到php默认目录,且改名
[root@web01 php-7.3.5]# cp php.ini-development /opt/php/lib/php.ini
FastCGI的配置文件
1.默认FastCGI的配置文件路径
[root@web01 etc]# pwd
/opt/php/etc
[root@web01 etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
2.生成2个php-frpm的配置文件,先用默认配置,后续可以再后话
[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@web01 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
启动PHP服务(FastCGI模式)
# 启动服务,并且检查状态
[root@web01 etc]# /opt/php/sbin/php-fpm
[root@web01 etc]# netstat -tunlp|grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 109647/php-fpm: mas
修改Nginx支持PHP
1.修改nginx配置文件,在最底行添加 包含文件参数,建议删除nginx.conf原有的server配置
[root@web01 conf]# vim /opt/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
include extra/01_www.conf;
include extra/02_bbs.conf;
include extra/03_blog.conf;
include extra/04_status.conf;
}
【配置PHP的解析配置文件】
[root@web01 conf]# mkdir extra
[root@web01 conf]# vim extra/03_blog.conf
[root@web01 conf]#
[root@web01 conf]#
[root@web01 conf]# cat extra/03_blog.conf
server {
listen 80;
server_name blog.chaoge.com;
location / {
root html/blog;
index index.html;
}
#添加有关php程序的解析
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
检查且启动nginx
[root@web01 conf]# touch extra/01_www.conf
[root@web01 conf]# touch extra/02_bbs.conf
[root@web01 conf]# touch extra/04_status.conf
[root@web01 conf]# nginx -t
nginx: the configuration file /opt/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx-1.16.0//conf/nginx.conf test is successful
测试LNMP环境
[root@web01 conf]# mkdir -p /opt/nginx/html/blog
[root@web01 conf]# echo "<?php phpinfo(); ?>" > ../html/blog/test_info.php
[root@web01 conf]#
当看见如下页面,表示lnmp环境已经能够正确解析了
测试正确后,保证服务器安全,就得删除该test_info.php文件了
测试php访问mysql
php的代码,直接在网页中解析即可
[root@web01 conf]# cat ../html/blog/test_mysql.php
<?php
$link_id=mysqli_connect('localhost','root','chaoge666') or mysql_error();
if($link_id){
echo "mysql successful by chaoge.\n";
}else {
echo mysql_error();
}
?>
-----
如上脚本的中文解释
1.建立mysql连接,把连接信息复制为变量 link_id
2.如果link_id为真,那么就打印一串字符串信息,
3.否则输出报错信息,调试程序

看到如此的画面,lnmp环境基本搭建完毕,nginx+php+mysql的形式。
LNMP远程部署
上述php-fpm和nginx在一起,这里的讲解,是php-fpm和nginx在两台服务器,远程访问
参考博客
https://xuchen.wang/archives/nginxphp.html
还有注意,修改php-fpm的启动地址,改为0.0.0.0:9000
配置文件夹在安装目录的etc/php-fpm.d/下面的已conf为后缀的文件,一般在安装时我们设置成了www.conf。
把 listen = 127.0.0.1:9000 后面的端口号9000换成你需要的端口,然后重启php
LNMP部署开源博客

利用开源工具wordpress可以搭建出精美的博客站点,它是一套利用php语言和mysql数据库开发的程序,用于可以在支持php环境和mysql数据库的服务器上搭建blog站点。
你只需要掌握LNMP环境搭建,即可轻松部署wordpress程序。
LNMP环境准备
1.登录数据库创建用于存储数据库的wordpress库,存储博客数据
mysql> create database wordpress;
Query OK, 1 row affected (0.02 sec)
mysql> show databases like 'wordpress';
+----------------------+
| Database (wordpress) |
+----------------------+
| wordpress |
+----------------------+
1 row in set (0.01 sec)
2.创建专用于wordpress的数据库用户
mysql> create user wordpress;
# 给wordpress用户授权,允许在localhost本地登录mysql,且有增删改查权限,设置密码为123456
mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)
3.刷新权限表
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
4.查询用户信息
mysql> select user,authentication_string,host from mysql.user;
+---------------+-------------------------------------------+-----------+
| user | authentication_string | host |
+---------------+-------------------------------------------+-----------+
| root | *83F7A15725AF362EF5EAFC16E1F3F97FDAB9B411 | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| wordpress | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
+---------------+-------------------------------------------+-----------+
4 rows in set (0.00 sec)
5.nginx配置,选择blog虚拟主机配置,添加一个index.php参数
[root@web01 conf]# cat extra/03_blog.conf
server {
listen 80;
server_name _;
location / {
root html/blog;
index index.php index.html; #在这里新增
}
#添加有关php程序的解析
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
Wordpress博客程序准备
1.下载获取wordpress程序
wget https://wordpress.org/latest.zip
wget https://wordpress.org/latest.tar.gz
2.超哥机器上的资料
[root@web01 conf]# ls /home/chaoge/tools/wordpress-5.3.2.*
/home/chaoge/tools/wordpress-5.3.2.tar.gz /home/chaoge/tools/wordpress-5.3.2.zip
3.解压缩zip版代码
[root@web01 tools]# yum install unzip -y
[root@web01 tools]# unzip wordpress-5.3.2.zip
[root@web01 tools]# mv wordpress /opt/nginx/html/blog/
[root@web01 tools]# cd /opt/nginx/html/blog/
[root@web01 blog]# ls
test_mysql.php wordpress
4.移动worpress代码到nginx目录下,且授权
[root@localhost tools]# mv wordpress /opt/nginx/html/myphp/
[root@web01 blog]# mv wordpress/* .
[root@web01 blog]# ls
index.php wordpress wp-comments-post.php wp-includes wp-mail.php xmlrpc.php
license.txt wp-activate.php wp-config-sample.php wp-links-opml.php wp-settings.php
readme.html wp-admin wp-content wp-load.php wp-signup.php
test_mysql.php wp-blog-header.php wp-cron.php wp-login.php wp-trackback.php
[root@web01 blog]#
[root@web01 blog]#
[root@web01 blog]# chown -R nginx.nginx ../blog/
5.最后一步,注意别忘记重启nginx
nginx -s reload








