使用LNMP搭建wordpress

使用LNMP搭建wordpress

操作系统 CentOS 7
服务器 192.168.184.137
nginx-1.16.1

1.关闭selinux和防火墙

[root@localhost ~]# systemctl stop firewalld   # 关闭防火墙
[root@localhost ~]# systemctl disable firewalld   # 开机自动关闭防火墙
[root@localhost ~]# getenforce      #查看selinux的状态
enforcing
[root@localhost ~]# setenforce 0       # 临时关闭selinux
[root@localhost ~]# vim /etc/selinux/config   #永久关闭selinux,但是要重启机器才会生效(reboot)
 SELINUX=disabled             #将enforcing修改为disabled

2.源码包安装nginx(此处的nginx是源码编译的,也可以使用yum安装)

(1)下载nginx安装包 , 在此文档中我们使用nginx-1.16.1(下载nginx-1.16.1.tar.gz)

​ 可以访问nginx的官方网站(www.nginx.org)下载包,可以使用wget下载:

[root@localhost ~]# yum -y insyall wget
[root@localhost ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.16.1.tar.gz     #下载成功

(2)解压nginx安装包

[root@localhost ~]# tar xf nginx-1.16.1.tar.gz    #解压
anaconda-ks.cfg  nginx-1.16.1.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.16.1  nginx-1.16.1.tar.gz 

(3)源码包环境安装(依赖环境)

[root@localhost ~]#yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel

(4)进入nginx文件目录下,配置安装路径,编译并安装

[root@localhost ~]# cd nginx-1.16.1 
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
[root@localhost ~]# make && make install 

3.下载wordpress文件并解压到新建的/web/下,修改其权限(本文章使用的安装包是在本地上传的)

[root@localhost ~]# ls
anaconda-ks.cfg  wordpress-4.7.2-zh_CN.tar.gz  nginx-1.16.1  nginx-1.16.1.tar.gz 
[root@localhost ~]# tar xf wordpress-4.7.2-zh_CN.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  wordpress-4.7.2-zh_CN.tar.gz  nginx-1.16.1  nginx-1.16.1.tar.gz  wordpress 
[root@localhost ~]# mkdir /web
[root@localhost ~]# mv wordpress /web/
[root@localhost ~]# chmod -R 777 /web/

4.安装并启动数据库

[root@localhost ~]# yum -y install mariadb mariadb-server
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# netstat -nltp |grep mysqld   #若没有netstat,则yum -y install net-tools
tcp       0      0 0.0.0.0:3306        0.0.0.0:*            LISTEN      11262/mysqld    

5.对数据库进行配置

[root@localhost ~]# mysqladmin -uroot password "123"     #修改数据库密码(密码可自行修改)
[root@localhost ~]# mysql -uroot -p123
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
MariaDB [(none)]> \q
Bye
[root@localhost ~]# systemctl restart mariadb

6.安装php中间件,并重启php-fpm

[root@localhost ~]# yum -y install php php-mysql gd php-gd php-fpm
[root@localhost ~]# systemctl start php-fpm          #重启php-fpm
[root@localhost ~]# netstat -nltp |grep php
tcp      0      0 127.0.0.1:9000       0.0.0.0:*        LISTEN      40847/php-fpm: mast 

7.修改nginx的配置文件(让php和nginx生效)

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf   #修改内容如下
location / {
root    /web/wordpress;
index   index.php  index.html  index.htm;
}

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

1
8.启动nginx

[root@localhost ~]# /usr/local/nginx/sbin/nginx    #会发现报错,是因为没有nginx用户
nginx:[emerg] getpwnam("nginx") failed
[root@localhost ~]# useradd nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
[root@localhost ~]# netstat -nltp |grep nginx
tcp       0      0 0.0.0.0:80       0.0.0.0:*        LISTEN      10968/nginx: master

9.在浏览器验证(输入ip地址访问)
34567
安装完成,你可以使用你的博客了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值