以lnmp作为本地源安装nginx和部署wordpress

实验环境
准备两台虚拟机,能够互通

192.168.1.173nginx 服务
192.168.1.174php服务

需要用到的文件
wordpress-4.7.3-zh_C.zip 提取码:s8qx
lnmp.zip 提取码:5xwd
在这里插入图片描述

1.基础设置

1.1修改主机名

第一台

[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# bash
[root@nginx ~]#

第二台

[root@localhost ~]# hostnamectl set-hostname php
[root@localhost ~]# bash
[root@php ~]#
1.2使用网络源安装后面所需要使用到的工具

两台上都要安装
我这使用的是MobaXterm-SSH连接工具
提取码:355t

[root@nginx ~]# yum -y install unzip net-tools
[root@php ~]# yum -y install unzip net-tools
1.3配置本地源

上传wordpress-4.7.3-zh_C.zip 和 lnmp.zip 到两台虚拟机

[root@nginx ~]# ls
anaconda-ks.cfg  lnmp.zip  wordpress-4.7.3-zh_C.zip
[root@php ~]# ls
anaconda-ks.cfg  lnmp.zip  wordpress-4.7.3-zh_C.zip

使用unzip命令解压lnmp.zip
可以看到多出一个lnmp文件

[root@nginx ~]# unzip lnmp.zip
[root@nginx ~]# ls
anaconda-ks.cfg  lnmp  lnmp.zip  wordpress-4.7.3-zh_C.zip
[root@php ~]# unzip lnmp.zip
[root@php ~]# ls
anaconda-ks.cfg  lnmp  lnmp.zip  wordpress-4.7.3-zh_C.zip

创建一个bak文件将原有的repo文件移动进去

[root@nginx ~]# mkdir /etc/yum.repos.d/bak
[root@nginx ~]# mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak
[root@php ~]# mkdir /etc/yum.repos.d/bak
[root@php ~]# mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak

在两台虚拟机上分别挂载本地镜像

[root@nginx ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@php ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载

创建配置文件如下
local.repo为自己创建的文件

[root@nginx ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///mnt
gpgcheck=0
enabled=1
[lnmp]
name=lnmp
baseurl=file:///root/lnmp
gpgcheck=0
enabled=1
[root@nginx ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: centos lnmp
Cleaning up list of fastest mirrors
Other repos take up 135 M of disk space (use --verbose for details)
[root@nginx ~]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
centos                                                   | 3.6 kB     00:00
lnmp                                                     | 2.9 kB     00:00
(1/3): centos/group_gz                                     | 165 kB   00:00
(2/3): lnmp/primary_db                                     | 153 kB   00:00
(3/3): centos/primary_db                                   | 3.2 MB   00:00
源标识                               源名称                                状态
centos                               centos                                4,067
lnmp                                 lnmp                                    178

可以看到lnmp有178个包,说明成功了
将配置文件复制到另一台
输入yes 必须全称yes
输入密码即可

[root@nginx ~]# scp /etc/yum.repos.d/local.repo root@192.168.1.174:/etc/yum.repos.d/
The authenticity of host '192.168.1.175 (192.168.1.175)' can't be established.
ECDSA key fingerprint is SHA256:cF3uwwqzrZmRkguWmlw9zjFTDEVtzjDnMhhIpx+f1Ik.
ECDSA key fingerprint is MD5:9f:98:f9:a1:71:8f:28:ce:ad:19:a1:06:e1:bf:6e:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.175' (ECDSA) to the list of known hosts.
root@192.168.1.174's password:
local.repo                                    100%  127   105.0KB/s   00:00
1.4分别关闭防火墙和SElinux
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# setenforce 0
[root@php ~]# systemctl stop firewalld
[root@php ~]# setenforce 0

2.安装服务

2.1第一台上安装nginx服务
[root@nginx ~]# yum -y install nginx

启动服务

[root@nginx ~]# nginx

在浏览器中通过ip访问,我的ip为192.168.1.174
可以看到Welcome to nginx! 说明实验成功
在这里插入图片描述

2.2第二台上安装php服务
[root@php ~]# yum -y install php php-fpm php-mysql

3.实现wordpress安装

3.1创建用户ID

在php上创建

[root@php ~]# groupadd -g 1001 nginx
[root@php ~]# useradd -u 900 nginx -g nginx -s /sbin/nologin
3.2修改nginx中的配置文件
[root@nginx ~]# vi /etc/nginx/conf.d/default.conf
#省略了前后代码
#只需找到下列代码并修改
location / {
        root   /www;	#修改网页目录
        index  index.php index.html index.htm;  #添加index.php
    }
#去掉下列代码的注释并修改
location ~ \.php$ {
        root           /www;	#修改网页目录
        fastcgi_pass   192.168.1.175:9000;	#这里的ip为php主机的ip
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

修改fastcgi_params文件在里面添加一行

[root@nginx ~]# vi /etc/nginx/fastcgi_params
#省略前后代码,找到下面的代码,并在指定位置下添加一行
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; #添加这行代码
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

先重启虚拟机,再重启nginx服务,不然可能会失败。

[root@nginx ~]# systemctl restart nginx
3.3修改php中的文件
[root@php ~]# vi /etc/php-fpm.d/www.conf
#找到下列代码并修改
listen = 192.168.1.175:9000			#这里ip为php节点的ip
listen.allowed_clients = 192.168.1.174  #这里ip为nginx节点的ip
user = nginx
group = nginx

重启php服务

[root@php ~]# systemctl restart php-fpm
3.4创建网页目录

在 nginx 和 php 节点,创建/www 目录,并修改用户和用户组

[root@nginx ~]# mkdir /www
[root@nginx ~]# chown nginx:nginx /www
[root@php ~]# mkdir /www
[root@php ~]# chown nginx:nginx /www
3.4部署wordpress

在nginx和php节点分别解压wordpress并移动到/www下

[root@nginx ~]# unzip wordpress-4.7.3-zh_CN.zip 
[root@nginx ~]# mv wordpress/* /www/
[root@php ~]# unzip wordpress-4.7.3-zh_CN.zip 
[root@php ~]# mv wordpress/* /www/

在nginx节点安装数据库服务,启动并初始化
注意:重启虚拟机后需要重新挂载镜像,关闭防火墙、SElinux

[root@nginx ~]# yum -y install mariadb mariadb-server
[root@nginx ~]# systemctl restart  mariadb
[root@nginx ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@nginx ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

登录数据库,创建wordpress库,并授权
-p后面的为数据库密码

[root@nginx ~]# mysql -uroot -p000000
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "000000";
Query OK, 0 rows affected (0.00 sec)

退出数据库
在nginx节点修改wordpress的配置文件

[root@nginx ~]# cp /www/wp-config-sample.php /www/wp-config.php
[root@nginx ~]# vi /www/wp-config.php

#修改下面部分代码

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'root');

/** MySQL数据库密码 */
define('DB_PASSWORD', '000000');

/** MySQL主机 */
define('DB_HOST', '192.168.1.174');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

将文件拷贝到php节点上

[root@nginx ~]# scp /www/wp-config.php root@192.168.1.175:/www/

在 Nginx 节点重启 Nginx 服务

[root@nginx ~]# nginx -s reload

在浏览器中输入ip即可访问到下图
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
也许大家对LAMP比较熟悉,LAMP代表Linux下Apache、MySQL、PHP这种网站服务器架构;同上LNMP代表的就是Linux下Nginx、MySQL、PHP这种网站服务器架构。 我们为什么采用LNMP这种架构? 采用Linux、PHP、MySQL的优点我们不必多说。 Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。 Nginx相当的稳定、功能丰富、安装配置简单、低系统资…… LNMP这种架构有什么优势? 作为 Web 服务器:相比 Apache,Nginx 使用更少的资,支持更多的并发连接,体现更高的效率。 作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资开销还是 CPU 使用效率都比 Perlbal 要好的多。 作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm 描述了成功并且美妙的使用经验。 Nginx 安装非常的简单,配置文件 非常简洁(还能够支持perl语法),Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。更多Nginx介绍 如何获取LNMP一键安装包? 你可以自由 下载 并使用它在VPS(VDS)或独立服务器上,做为真正的生产环境或测试环境。 它安装那些软件 Nginx MySQL PHP PHPMyAdmin Apache Zend Optimizer eAccelerator ionCube PureFTPd VsFTPd 2012年4月23日发布LNMP 0.9 优化安装过程及错误处理; MySQL安装增加InnoDB选项(可选); 修正eaccelerator和ionCube的PHP版本判断错误的问题; 修正memcached pid创建失败的问题 修正pdo_mysql安装方法; PHP增加部分禁用函数; 优化Nginx升级脚本; 去除vsftpd安装脚本; 修正访问不存在的PHP时返回404; 更新Nginx版本; 更新PHP探针; 增加phpwin伪静态 升级过程增加停止LNMP相关服务; 修正Nginx log_format问题; 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值