1.使用官方仓库安装Nginx
[[email protected] ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
#安装Nginx
[[email protected] ~]# yum install nginx -y
2.安装php7.1
[[email protected] ~]# yum remove php-mysql-5.4 php php-fpm php-common
[[email protected] ~]# cat /etc/yum.repos.d/php.repo
[php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
[[email protected] ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
3.安装Mariadb数据库
[[email protected] ~]# yum install mariadb-server mariadb -y
4.部署wordpress
[[email protected] conf.d]# vim blog.oldboy.com.conf
server {
listen 80;
server_name blog.oldboy.com;
root /code/wordpress;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
5.根据配置文件创建目录
[[email protected] conf.d]# mkdir /code
6.重载Nginx
[[email protected] conf.d]# nginx -t
[[email protected] conf.d]# systemctl restart nginx
[[email protected] conf.d]# systemctl enable nginx
7.启动php-fpm,并加入开机自启
[[email protected] conf.d]# systemctl start php-fpm
[[email protected] conf.d]# systemctl enable php-fpm
8.启动数据库
[[email protected] conf.d]# systemctl start mariadb
[[email protected] conf.d]# systemctl enable mariadb
[[email protected] conf.d]# mysqladmin password ‘123456‘ #配置密码(默认mysql是空密码)
[[email protected] conf.d]# mysql -uroot -p123456 #使用账号和密码登录mysql
9.根据nginx中定义的内容,创建站点目录并且进行授权
[[email protected] conf.d]# cd /code
[[email protected] code]# wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.tar.gz
[[email protected] code]# tar xf wordpress-5.0.3-zh_CN.tar.gz
修改nginx与php-fpm的运行用户为www,并授权代码属主和属组都为www
#注意:如果没有该用户,启动一定会报错
[[email protected] code]# groupadd -g 666 www
[[email protected] code]# useradd -u666 -g666 www
修改nginx与php-fpm管理进程,的运行身份为www
[[email protected] code]# sed -i ‘/^user /c user www;‘ /etc/nginx/nginx.conf
[[email protected] code]# sed -i ‘/^user/c user = www‘ /etc/php-fpm.d/www.conf
[[email protected] code]# sed -i ‘/^group/c group = www‘ /etc/php-fpm.d/www.conf
最后授权代码为www
[[email protected] code]# chown -R www.www /code/wordpress
一定要重启才生效
[[email protected] code]# systemctl restart nginx
[[email protected] code]# systemctl restart php-fpm
10.创建数据库
MariaDB [(none)]> create database wordpress; #创建一个库,名称叫wordpress
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases; #查询该台数据库服务有多少个库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
输入blog.oldboy.com就可以安装wordpress搭建博客了。
点击外观-添加-上传主题-选择文件-上传 发现会报413 Request Entity Too Large
因为nginx对上传的文件大小做了限制
11.解决nginx上传文件大小限制
[[email protected] ~]# vim /etc/nginx/conf.d/blog.oldboy.com.conf
server {
listen 80;
server_name blog.oldboy.com;
root /code/wordpress;
client_max_body_size 100m;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
PS:client_max_body_size 100m;#默认nginx仅支持上传1m大小的文件
[[email protected] code]# systemctl restart nginx
继续上传主题--最后启用
原文地址:https://blog.51cto.com/14284799/2385285