php7 nginx wordpress,Nginx+php7.2+WordPress部署

一、环境介绍

本文介绍的安装环境为百度云BCC的Centos7.5虚拟机。

所有软件下载安装地址为: /opt/workspace/

软件安装用户为:root

二、安装Nginx

说明:Nginx采用源码安装方式

1、安装Nginx源码编译所需依赖库,使用yum安装

yum install gcc-c++

yum install -y pcre pcre-devel

yum install -y zlib zlib-devel

yum install -y openssl openssl-devel

2、使用wget命令下载nginx源码包

wget http://nginx.org/download/nginx-1.15.11.tar.gz

3、解压文件

tar -zxvf nginx-1.15.11.tar.gz

4、配置Nginx,加上常用模块

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module

5、编译以及安装Nginx,centos默认安装位置:/usr/local/nginx

make

make install

三、安装Mysql

1、下载mysql的repo的rpm包,采用yum方式安装mysql

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2、安装repo的rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

3、查看mysql,并使用yum安装mysql-server

yum repolist all | grep mysql

yum install mysql-server

4、启动mysql服务

systemctl start mysqld.service

5、配置mysql

//使用root账户登录

mysql -u root

//设置root密码

set password for 'root'@'localhost' =password('新密码');

//开启mysql的远程连接,默认只允许localhost访问数据库:

grant all privileges on *.* to root@'%'identified by 'password';

//创建wordpree数据库

create database wordpress charset utf8;

//配置完成退出登录

exit

四、安装php

1、安装php的仓库地址的rpm包

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2、安装php7.2

yum install php72w php72w* -y

yum install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel

3、查看php版本号是否为7.2

php -v

4、启动php-fpm服务

systemctl start php-fpm

五、下载并配置wordpress

1、下载并解压文件

//切换目录至/opt/wordspace

cd /opt/workspace

//下载wordpress压缩包

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

//使用list查看下载的wordpress包,此处下载的包为:wordpress-5.0.3-zh_CN.tar.gz

ls

//解压压缩包

tar -zxvf wordpress-5.0.3-zh_CN.tar.gz

2、修改wordpress配置

//切换目录至wordpress配置文件所在目录

cd wordpress/

//拷贝一份配置文件

cp wp-config-sample.php wp-config.php

//使用vi打开文件

vi wp-config.php

//根据注释修改文件开始的数据库连接信息

//修改后保存

六、配置nginx

1、配置ssl证书,支持https,证书可在各个云服务商处下载,证书下载选择nginx,并上传至/usr/local/nginx/conf/目录下

2、修改nginx.conf文件

cd /usr/local/nginx/conf/

nginx文件配置具体如下:

#user nobody;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

upstream php {

server unix:/tmp/php-cgi.socket;

server 127.0.0.1:9000;

}

server {

listen 80;

server_name xxxxx;

return 301 https://$server_name$request_uri;

root /opt/workspace/wordpress;

index index.php index.html;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

index index.php index.html index.htm;

try_files $uri $uri/ /index.php index.php;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# HTTPS server

#

server {

listen 443 ssl;

server_name xxxxxx;

root /opt/workspace/wordpress;

index index.php index.html;

ssl_certificate 你的ssl证书文件.pem;

ssl_certificate_key 你的ssl证书文件.key;

ssl_session_cache shared:SSL:1m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_session_timeout 5m;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

ssl_prefer_server_ciphers on;

location = /favicon.ico {

log_not_found off;

access_log off;

expires max;

}

location = /robots.txt {

allow all;

log_not_found off;

access_log off;

}

location / {

# This is cool because no php is touched for static content.

# include the "$is_args$args" so non-default permalinks doesn't break when using query string

try_files $uri $uri/ /index.php?$args;

}

location ~ \.php$ {

#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

include fastcgi.conf;

fastcgi_intercept_errors on;

fastcgi_pass php;

fastcgi_buffers 16 16k;

fastcgi_buffer_size 32k;

}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {

expires max;

access_log off;

log_not_found off;

}

}

}

3、修改后需要启动nginx

//切换目录至nginx运行目录

cd /usr/local/nginx/sbin

//启动nginx

./nginx

//如果已经启动,重新加载配置

./nginx -s reload

4、访问服务器测试是否正常

七、解决wordpress无法上传图片,安装插件需要ftp问题

1、修改wp-content权限

//切换到wordpress目录

cd /opt/workspace/wordpress/

//切换wp-content权限至777

chmod 777 wp-content

2、登录wordpress,进媒体库上传一张图片

3、查看创建的上传目录的用户以及组

//切换目录

cd /opt/workspace/wordpress/wp-content

//使用ll查看目录权限

TIM%E6%88%AA%E5%9B%BE20190425200226.png

4、根据上一步可以看到uploads目录的用户以及用户组都为apache

5、修改wp-content目录的用户以及用户组

chown -R apache:apache wp-content

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值