LNMP构建动态网站wordpress
一、部署LNMP架构
1、安装nginx
#配置nginx源
cat>/etc/yum.repos.d/nginx.repo<<-EOF
[NGINX]
name=nginx
baseurl=http://nginx.org/packages/centos/7/x86_64/
enabled=1
gpgcheck=0
EOF
#生成yum缓存
[[email protected] ~]# yum makecache
#安装NGINX软件
[[email protected] ~]# yum -y install nginx
#启动nginx服务
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl restart nginx
2、安装PHP
#卸载就版本PHP软件
[[email protected] ~]# yum remove php-mysql-5.4 php php-fpm php-common
若你是新机器即可忽略卸载旧版本PHP软件步骤
#安装扩展源
[[email protected] ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[[email protected] ~]# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[[email protected] ~]# yum -y localinstall webtatic-release.rpm epel-release-latest-7.noarch.rpm
[[email protected] ~]# yum makecache
#安装php72版本
[[email protected] ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache
#启动PHP服务
[[email protected] ~]# systemctl start php-fpm
[[email protected] ~]# systemctl enable php-fpm
3、安装MySQL
#安装MySQL扩展源
[[email protected] ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[[email protected] ~]# yum -y localinstall mysql80-community-release-el7-1.noarch.rpm
[[email protected] ~]# yum repolist enabled | grep "mysql.*-community.*"
#安装MySQL8.0
[[email protected] ~]# yum -y install mysql-community-server
#启动MySQL服务
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl restart mysqld
查看MySQL随机设置的root密码
[[email protected] ~]# grep "temporary password" /var/log/mysqld.log
修改MySQL root用户的登录密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Passw0rd!‘;
这里的密码必须要字母大小写,数字,字符。
二、配置Nginx实现动态请求转发至php
#拷贝一个虚拟主机模版
[[email protected] ~]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/wordpress.conf
[[email protected] ~]# vim /etc/nginx/conf.d/wordpress.conf
#将30-36行取消注释
#检测一下配置文件是否有错误
[[email protected] ~]# nginx -t
如果看到 syntax is ok 证明配置文件误错误
#重新加载一下nginx服务
[[email protected] ~]# nginx -s reload
三、测试PHP连接
#编辑一个测试页面
[[email protected] ~]# cat>/usr/share/nginx/html/wordpress/phpinfo.php<<-EOF
> <?php
> phpinfo();
> ?>
> EOF
#浏览器访问查看 http://wordpress.lhbbk.cn/phpinfo.php
四、部署WordPress
wordpress官网:https://cn.wordpress.org/
#下载WordPress中文软件包
[[email protected] ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
#解压wordpress软件包到/usr/share/nginx/html/下
[[email protected] ~]# tar -zxvf wordpress-4.9.4-zh_CN.tar.gz -C /usr/share/nginx/html/
#创建WordPress数据库
[[email protected] ~]# mysql -uroot -p
mysql> create database wordpress;
#浏览器输入http://blog.wordpress.lhbbk.cn 开始安装WordPress
#修改登录数据库的用户名,密码,默认是连接本地数据库。远程数据库则要填写数据库主机名 点击提交
#此处提示我们没有写的权限,我们需手动创建wp-config.php文件,文件内容已给提出,我们直接复制即可
#编辑wp-config.php文件
[[email protected] ~]# vim /usr/share/nginx/html/wordpress/wp-config.php
#接着在网页上点击现在安装,跳出一个页面,我们填写站点标题,用户名,密码,邮箱等信息,点击安装WordPress
#提示安装成功,我们点击登录即可
#WordPress登录成功,跳转到管理界面
#我们可以点击问文章写一篇文件,点击发布即可
#如果你在上传图片时提示你没有访问权限时执行以下命令为其目录授权
[[email protected] ~]# mkdir -p /usr/share/nginx/html/wordpress/wp-content/uploads/2018/09
[[email protected] ~]# chmod -R 777 /usr/share/nginx/html/wordpress/wp-content/uploads/
#我们在回到WordPress首页查看博客
原文地址:https://www.cnblogs.com/chenjiangfeng/p/9706512.html