Centos7 搭建WordPress个人站点
操作场景
WordPress 是一款使用 PHP 语言开发的博客平台,您可使用通过 WordPress 搭建属于个人的博客平台。
基础环境配置
ip:192.168.101.171Centos7.7
关闭防火墙
$ systemctl stop firewalld
$ systemctl disable firewalld
关闭selinux
$ setenforce 0
$ vim /etc/selinux/config
#将SELINUX=enforcing改为SELINUX=disabled
安装工具
$ yum install -y vim wget
一、YUM方式进行安装
1.1 设置nginx YUM源
官方yum源:http://nginx.org/en/linux_packages.html#RHEL-CentOS
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name = nginx repo
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck = 0
enabled = 1
1.2 安装nginx服务,会安装1.18.0版本
$ yum install -y nginx
1.3 修改发布目录与添加PHP运行环境
$ cd /etc/nginx/conf.d/
$ cp default.conf default.conf.bak
$ vim default.conf
#修改以下内容
server {
listen 80;
server_name localhost;
location / {
root /opt/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/nginx/html;
}
location ~ \.php$ {
root /opt/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
$ mkdir -p /opt/nginx/html
$ mv /usr/share/nginx/html/* /opt/nginx/html/
1.4 设置nginx开机启动
$ systemctl enable nginx.service
$ systemctl start nginx.service
$ systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-04-13 10:59:12 EDT; 14s ago
Docs: http://nginx.org/en/docs/
Process: 20145 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 20146 (nginx)
CGroup: /system.slice/nginx.service
├─20146 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx....
└─20147 nginx: worker process
Apr 13 10:59:12 localhost.localdomain systemd[1]: Starting nginx - high perfo...
Apr 13 10:59:12 localhost.localdomain systemd[1]: Started nginx - high perfor...
Hint: Some lines were ellipsized, use -l to show in full.
1.5 测试是否可以访问nginx
$ curl http://192.168.101.100
二、安装MariaDB
Centos7 之上版本默认是支持mariadb数据库的,因此在此使用yum安装mariadb数据库; $ yum install mariadb-server mariadb -y
启动服务 $ systemctl restart mariadb
$ systemctl enable mariadb
进入MariaDB $ mysql
创建 MariaDB 数据库,例如wordpress; > CREATE DATABASE wordpress;
创建一个新用户user,登录密码为000000; > CREATE USER 'user'@'localhost' IDENTIFIED BY '000000';
给予用户对wordpress数据库的全部权限; > GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '000000';
执行以下命令,使所有配置生效。 > FLUSH PRIVILEGES;
退出MariaDB > exit
三、安装 PHP
依次执行以下命令,更新 yum 中 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 7.2 所需要的包。 $ yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
执行以下命令,启动 PHP-FPM 服务。 $ systemctl start php-fpm
执行以下命令,设置 PHP-FPM 服务为开机自启动。 $ systemctl enable php-fpm
在/opt/nginx/html/目录下创建一个info.php 文件来检查 PHP 是否安装成功,示例代码如下: $ cd /opt/nginx/html/
$ vim info.php
重启httpd服务 $ systemctl restart nginx
测试php # 访问http://192.168.101.100/info.php
四、安装and配置 WordPress
下载 WordPress $ cd /opt/nginx/html
$ wget https://cn.wordpress.org/latest-zh_CN.tar.gz
解压 $ tar -zxvf latest-zh_CN.tar.gz
$ ll
drwxr-xr-x. 5 1006 1006 4096 Apr 29 16:09 wordpress
修改WordPress配置文件 # 进入 WordPress 安装目录,将wp-config-sample.php文件复制到wp-config.php文件中,并将原先的示例配置文件保留作为备份。
$ cd /opt/nginx/html/wordpress
$ cp wp-config-sample.php wp-config.php
编辑配置文件 $ vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );
/** MySQL数据库用户名 */
define( 'DB_USER', 'user' );
/** MySQL数据库密码 */
define( 'DB_PASSWORD', '000000' );
/** MySQL主机 */
define( 'DB_HOST', 'localhost' );
/** 创建数据表时默认的文字编码 */
define( 'DB_CHARSET', 'utf8' );
安装WordPress http://192.168.101.100/wordpress/
根据WordPress安装向导提示输入以下安装信息 安装完成 登入Wordpress