配置阿里云YUM源
官方镜像源下载速度实在太慢,使用阿里云源下载速度更快
[root@localhost yum.repos.d]# mv ./* /tmp/
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@loca lhost yum.repos.d]# yum clean all #清理YUM缓存
[root@localhost yum.repos.d]# yum makecache #更新YUM仓库
搭建环境前准备
SELinux服务关闭
防火墙设置
nginx默认使用80端口,可在nginx.conf中配置
永久开放80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙:
firewall-cmd --reload
查看防火墙开启状态:
systemctl status firewalld
查看80端口是否开放成功:
firewall-cmd --zone=public --query-port=80/tcp
或者将防火墙和SELinux服务关闭
yum install wget -y
安装mysql
wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-community-server mysql
修改初始密码
获取默认密码
systemctl start mysqld.service
grep 'password' /var/log/mysqld.log
2021-08-21T04:22:05.085559Z 1 [Note] A temporary password is generated for
root@localhost: T5jpstN6#3rR
登录修改默认密码(数据库的root密码,不是系统用户root密码)
mysql -uroot -p'T5jpstN6#3rR'
mysql> alter user 'root'@'localhost' identified by 'Yy123.com';
Query OK, 0 rows affected (0.00 sec)
退出后就可以用自己的密码登录
创建WordPress数据库并授权(密码为WordPress用户的登录密码)
mysql> create database wordpress;
mysql> create user 'wordpress'@'localhost' identified by 'Yy123.com';
mysql> grant all privileges on wordpress.* to 'wordpress'@'localhost';
mysql> flush privileges;
安装nginx
yum install nginx -y
添加配置文件
vim /etc/nginx/conf.d/wordpress.conf
server{
listen 80;
server_name www.test.com;
root /wordpress;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
# 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;
}
}
#######################################################
cd /etc/nginx/
备份配置文件
cp nginx.conf /tmp/nginx.conf.bak
修改nginx.conf配置文件
vim /etc/nginx/nginx.conf
38行到#开始前,把中间的内容删除
保存退出,启动nginx
systemctl start nginx
安装php环境
yum install php-fpm php-mysql -y
修改配置文件
vim /etc/php-fpm.d/www.conf
启动服务
systemctl start php-fpm.service
搭建wordpress
wget https://cn.wordpress.org/wordpress-4.7.2-zh_CN.tar.gz
tar zxf wordpress-4.7.2-zh_CN.tar.gz
mv wordpress /
cd /
chmod -R 777 wordpress/
[root@lnmp /]# systemctl restart nginx
[root@lnmp /]# systemctl restart mysqld
[root@lnmp /]# systemctl restart php-fpm
[root@lnmp /]# systemctl stop firewalld
[root@lnmp /]# setenforce 0
setenforce: SELinux is disabled
进入WordPress网站