一、LNMP架构
LNMP工作过程
首先,浏览器发送http request请求到服务器(Nginx),服务器响应并处理web请求,将一些静态资源(CSS,图片,视频等)保存服务器上,然后将php脚本通过接口传输协议(网关协议)PHP-FCGI(fast-cgi)传输给PHP-FPM(进程管理程序),PHP-FPM不做处理,然后PHP-FPM调用PHP解析器进程,PHP解析器解析php脚本信息。PHP解析器进程可以启动多个,进行并发执行。然后将解析后的脚本返回到PHP-FPM,PHP-FPM再通过fast-cgi的形式将脚本信息传送给Nginx.服务器再通过Http response的形式传送给浏览器。浏览器再进行解析与渲染然后进行呈现。
二、WordPress搭建
1.安装Linux
2.安装数据库(也可以安装mariadb)
进入数据库
mysql -uroot -p
建立新的数据库
create database wordpress character set utf8 collate utf8_bin;###数据库名为wordpress
grant all on wordpress.* to wordpress@'localhost' identified by 'Wordpress@123';###设置用户名和密码
grant all on wordpress.* to wordpress@'%' identified by 'Wordpress@123';###设置另一个,可以不设置
这里最好自己登录新建的数据库试一下,以免后面步骤发生错误
mysql -uwordpress -p
3.安装Nginx
进入配置文件
vim /etc/nginx/conf.d/default.conf
修改以下内容
location ~ \.php$ {
root /usr/share/nginx/html/wordpress/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4.安装php php-fpm php-mysql
yum install php-fpm php-mysql php
在根路径下创建一个文件(index.php),方便测试
<?php
$link=mysql_connect('localhost','root','xxxxxx');
if ($link)
echo 'mysql is running!';
else
echo 'mysql isn't connected!';
?>
5.从官网下载wordpress包,解压
tar -zxf wordpress-4.8.1-zh_CN.tar.gz
解压后将wordpress文件移动到/usr/share/nginx/html下
mv wordpress /usr/share/nginx/html
在usr/share/nginx/html/wordpress/路径下将wp-config-sample.php 复制一个并改名为wp-config.php,打开后修改以下内容:
define( 'DB_NAME', 'wordpress' );###数据库名
/** MySQL database username */
define( 'DB_USER', 'wordpress' );###用户名
/** MySQL database password */
define( 'DB_PASSWORD', 'Wordpress@123' );###数据库密码
三、验证
在浏览器输入192.168.122.127/wordpress/index.php
但是会出现一个版本错误提示
Your server is running PHP version 5.4.16 but WordPress 5.2.3 requires at least 5.6.0.
进入/usr/share/nginx/html/wordpress/wp-includes
vim version.php
修改以下内容
$required_php_version = '5.2.3';###修改PHP版本号
现在就可以访问了,会出现注册信息页面