我是在虚拟机上搭建的。
1、安装数据库
//先从官网下载yum源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
//然后安装mysql源
yum localinstall mysql57-community-release-el7-11.noarch.rpm
//查看源是否安装成功,如下图表示源安装成功
yum repolist enabled |grep "mysql.*-community.*"
2、配置数据库
//安装mysql
yum install mysql-community-server
//启动mysql
systemctl start mysqld
//查看mysql运行状态
systemctl status mysqld
//开机启动
systemctl enable mysqld
systemctl daemon-reload
//mysql安装完后,在/var/log/mysqld.log文件中给root用户生成了一个默认密码,如下找到密码
grep 'password' /var/log/mysqld.log
//然后进入mysql可以修改密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
//默认密码策略是必须有大小写字母,数字和特殊符号且大于8位!
//查看密码策略
show variables like '%password%';
修改密码策略,在/etc/my.cnf文件添加validate_password_policy=0 (0表示LOW,1表示MEDIUM,2表示STRONG) 或者直接关闭密码策略:validate_password=off 重启后生效:systemctl restart mysqld
3、MySQL远程登录授权和修改数据库字符集
//mysql默认安装在 /var/lib/mysql , 日志文件 /var/log/mysqld.log, 配置文件/etc/my.cnf
//添加远程登录用户
//默认的root账户只能localhost登录,为安全起见,添加一个新账户用于远程登陆
grant all privileges on *.* to 'new_user'@'%' identified by 'new_pwd' with grant option;
//配置默认编码为utf8,修改/etc/my.cnf,在[mysqld]下添加:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8
//查看mysql当前编码
show variables like 'character%';
4、安装PHP
rpm -Uvh https://dl.Fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
4.1、清除历史版本
为了防止CentOS上面发生php冲突,所以,这个命令还是先执行一下更好些。
yum -y remove php*
4.3、安装扩展包
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
4.4、安装完成以后,启动服务
systemctl enable php-fpm.service
systemctl start php-fpm.service
安装完成
5、安装nginx
6、下载wordpress,并将文件上传到root目录下
6.1、将压缩包解压到srv目录下
tar -zxvf /root/wordpress-4.9.4-zh_CN.zip -C /srv
6.2、创建数据库wordpress
create database wordpress
6.3、创建新用户
create user 'me'@'localhost' identified by 'Hxs?1234';
MySQL5.7要求密码为至少8位的字母+字符+数字组合
6.4、通过授予新用户的所有权限。没有这个命令,wordpress安装程序将无法启动:
GRANT ALL PRIVILEGES ON wordpress.* TO 'me'@'localhost' IDENTIFIED BY 'Hxs?1234';
FLUSH PRIVILEGES;
6.5、切换到srv目录下,将wordpress目录的所有权授予nginx用户,并将目录的读写权限改为777
chown -R nginx:nginx wordpress
chmod -R 777 wordpress
6.6 打开nginx的conf.d目录下的default.conf文件,并修改配置
vi /etc/nginx/conf.d/default.conf
#
# The default server
#
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /srv/wordpress; //这边改为wordpress的安装位置
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /srv/wordpress; //这边也改为wordpress的安装位置
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;
#}
}