Linux运维之路


centos7 搭建 LNMP+wordpress 环境

admin 2019-08-01 427浏览 0条评论
首页/正文
分享到: / / / /

LNMP+wordpress

yum源配置

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
clean all

nginx 配置

#第一步: 下载nginx:
#http://nginx.org/en/download.html 

##注意 nginx版本最好选择 半年到一年之前的版本,不要选用最新版。
##我这里选择1.17的稳定版 


#创建一个目录存放nginx安装包 
mkdir -p /server/tools


#安装包下载:
cd /server/tools
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar xf nginx-1.16.0.tar.gz
cd nginx-1.16.0

#第二步: 解决软件依赖关系
# openssl-devel -- SSL证书相关依赖包
# pcre-devel  -- 正则相关依赖包
# gd-devel  -- 图片处理相关依赖包

yum install -y pcre pcre-devel openssl openssl-devel gd-devel  zlib-devel gcc

#第三步: 创建nginx进程相关用户
useradd -s /sbin/nologin -M www

#第四步:执行预编译
/server/tools/nginx-1.16.0
./configure --prefix=/application/nginx-1.16 --user=www --group=www --with-http_image_filter_module  --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module  


# 第五步:make 编译
make 
echo $?        #这一步可做可不做,返回值为0代表正常 为其他数值为异常

#第六步: 编译安装
make install

#创建软连接,作用在升级新版本时只需要替换软连接,而不需要停止服务更换版本
ln -s /application/nginx-1.16 /application/nginx

#优化nginx启动命令
#添加环境变量:
export PATH="$PATH:/application/nginx/sbin"
echo "export PATH="$PATH:/application/nginx/sbin"">>/etc/profile
source /etc/profile

启动Nginx

直接输入 nginx 命令  启动nginx

nginx -s  发送信号
          reload  重启信号
          stop    停止信号
          
          
ps -ef |grep nginx   查看nginx进程
 
nginx -V 查看编译参数

php配置

下载php

rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php

yum search php72w
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64

测试php 修改php用户为 www

备份:
cp /etc/php-fpm.d/www.conf{,.bak}

查看默认运行用户:
[root@leilei html]# grep "user = " /etc/php-fpm.d/www.conf
user = apache


手动修改默认运行用户
[root@leilei html]vim  /etc/php-fpm.d/www.conf 

user = apache
group = apache

改为:
user = www
group = www


也可以通过命令进行修改:
sed -i  "s#user = apache#user = www#g" /etc/php-fpm.d/www.conf
sed -i  "s#group = apache#group = www#g" /etc/php-fpm.d/www.conf

检查:
[root@leilei html]# egrep "user = |group =" /etc/php-fpm.d/www.conf
user = www
group = www


配置完成重新启动php
[root@leilei html]# systemctl restart php-fpm.service 

设置开机自动运行:
[root@leilei html]# systemctl enable php-fpm.service 


检查进程:

[root@leilei html]# ps -ef |grep php
root      22312      1  0 00:31 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www       22313  22312  0 00:31 ?        00:00:00 php-fpm: pool www
www       22314  22312  0 00:31 ?        00:00:00 php-fpm: pool www
www       22315  22312  0 00:31 ?        00:00:00 php-fpm: pool www
www       22316  22312  0 00:31 ?        00:00:00 php-fpm: pool www
www       22317  22312  0 00:31 ?        00:00:00 php-fpm: pool www
root      22321  22239  0 00:31 pts/2    00:00:00 grep --color=auto php

[root@leilei conf]#  lsof -i:9000
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 22312 root    6u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 22313  www    8u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 22314  www    8u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 22315  www    8u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 22316  www    8u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 22317  www    8u  IPv4  54817      0t0  TCP localhost:cslistener (LISTEN)

php与nginx整合:

location ~ \.php$ {
  root           html;             #匹配网站根
  fastcgi_pass   127.0.0.1:9000;   # 指定php本地监听端口
  fastcgi_index  index.php;        # 默认文件匹配
  fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  # fastcgi的脚本文件的请求路径 用于解析php文件,如果没有配置这行,它就不会读取index.php文件 
  include        fastcgi_params;  # 包含/application/nginx/conf/目录下的 fastcgi_params 的文件
   }
  


#所以整合配置的正确代码:

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

配置完成进行检验:

echo "<?php phpinfo(); ?>" > /application/nginx/html/index.php

检查:

mysql 配置

yum安装

yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb

初始化mariadb

[root@leilei tools]#  mysql_secure_installation 

Enter current password for root (enter for none):   #配置密码 
OK, successfully used password, moving on...
Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y


创建相关数据库:
mysql -uroot -p






测试登陆:
mysql -h 127.0.0.1 -uwordpress -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [discuz]> exit


#创建wordpress数据库
create database wordpress;

#wordpress数据库权限配置,只允许本地访问 用户名 wordpress 密码 123456
grant all on wordpress.* to wordpress@'localhost' identified by '123456';

#刷新权限
flush privileges;

安装wordpress

下载wordpress

官方下载点:

https://cn.wordpress.org/download/releases/

tar.gz 右键复制下载链接

[root@leilei ~]# cd /application/nginx/html
[root@leilei html]# wget https://cn.wordpress.org/wordpress-5.2.2-zh_CN.tar.gz

#解压:
[root@leilei html]# tar -xf wordpress-5.2.2-zh_CN.tar.gz 
[root@leilei html]# mv wordpress/* ./

打开web页面进行安装

点击 现在开始

填写mariadb中创建的库和用户名密码

安装:

设置站点信息:

安装完成

登录:

发布第一篇文章

查看博文:

报错处理:

报错1:

进入wordpress目录授权:

[root@leilei html]# chown -R www.www *
最后修改:2019-08-01 02:12:54 © 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

上一篇

发表评论

评论列表

还没有人评论哦~赶快抢占沙发吧~