配置LNMP架构的wordpress,memcached centos7
安装MySQL
一开始,先咔咔一同安装 yum -y install wget /rpm /ps
centos7默认安装mariadb 检查是否安装了mariadb或者以及安装了MySQL
rpm -qa | grep mysql* # 查询是否安装了mysql
rpm -e --nodeps mysql* # 卸载mysql
rpm -qa | grep mariadb* # 查询是否安装了MariaDB
同样的方式卸载Mariadb
安装
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
解压
tar -xvf mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
安装所需要的包,yum安装多个包时,包1 \包2,用空格和斜杠
yum -y install
mysql-community-client-5.7.13-1.el7.x86_64.rpm
\mysql-community-common-5.7.13-1.el7.x86_64.rpm
\ mysql-community-devel-5.7.13-1.el7.x86_64.rpm
\ mysql-community-libs-5.7.13-1.el7.x86_64.rpm
\mysql-community-server-5.7.13-1.el7.x86_64.rpm
安装完后启动
systemctl start mysqld
systemctl status mysqld #查看状态
systemctl enable mysqld #设置开机自启
配置数据库
使用如下命令查看MySQL登录时的初始密码
grep “temporary password” /var/log/mysqld.log
使用初始密码登录MySQL,注意密码中含有某些特殊字符时,需要添加转义字符\或者"
mysql -uroot -p
密码
如果想要使用比较简单的密码,则需要首先调整密码验证策略,使用如下命令
mysql> set global validate_password_policy=LOW;
修改root用户的密码
mysql> alter user user() identified by “123456wj…”;
创建一个wordpress 数据库
mysql> create database wordpressdb;
查看数据库是否创建成功
show databases;
创建一个用户,密码设置为123456wj…
create user wordpressuser identified by ‘123456wj…’;
为用户授权,把数据库wordpressdb的所有权限赋给wordpressuser这个用户,@‘%‘的意思是指定登陆的终端,可以是localhost ,%表示所有
grant all on wordpressdb.* to ‘wordpressuser’@’%’ identified by ‘123456wj…’;
刷新权限
flush privileges;
切换数据库
use wordpressdb;
退出数据库
exit;
安装nginx
安装Nginx软件仓库
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装Nginx1.18
yum -y install nginx-1.18.0-2.el7.ngx
然后启动systenctl start nginx
安装配置php
yum -y install epel-release
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安装php相关插件
yum -y install php74-php php74-php-common php74-php-fpm php74-php-mysqlnd php74-php-pdo php74-php-cli php74-php-json php74-php-mbstring php74-php-sodium php74-php-pecl-imagick php74-php-xml php74-php-gd php74-php-pecl-mcrypt php74-php-pecl-zip
yum -y install php74-php-pecl-memcached.x86_64 /php74-php-pecl-memcache.x86_64
安装成功
启动php,不同版本的有不同的名,有可能是php-fpm,具体看你自己安的啥
systemctl start php74-php-fpm
配置PHP
修改PHP的配置文件“www.conf”
cd /etc/opt/remi/php74/php-fpm.d/ #进入PHP配置目录
cp -p www.conf www.conf.bak #备份配置文件
vim /etc/opt/remi/php74/php-fpm.d/www.conf #编辑配置文件www.conf
顺便把wordpressan安装目录中所有文件的用户和所属组修改一下
chown -R nginx:nginx /usr/data/wordpress
find /usr/data/wordpress -type d -exec chmod 755 {} ;
find /usr/data/wordpress -type f -exec chmod 644 {} ;
安装wordpress的准备工作
新建software与wordpress目录
mkdir /opt/softwaremkdir -p /usr/data/wordpresscd /opt/software #进入software目录
下载wordpress5.7到 /opt/software目录
wget -O wordpress5.7.tar.gz https://cn.wordpress.org/wordpress-5.7-zh_CN.tar.gz
解压缩wordpress安装包
复制
配置Nginx
编辑Nginx的配置文件
vim /etc/nginx/conf.d/default.conf
开启vim显示行号的功能,在非编辑状态输入 :set number 回车(set前面有一个冒号,不要漏掉)。
第9行Nginx的root目录修改为 /usr/data/wordpress 。此目录与wordpress程序所在的目录必须一致,否则无法成功配置wordpress,修改为你自己的wordpress目录。
第10行 添加index.php
删除第30至36行前面的#号注释符
第31行的root目录修改为 /usr/data/wordpress
第34行的/scripts$fastcgi_script_name; 改为
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name;
检查配置文件的配置是否正确,看到如下输出,代表配置没问题。
nginx -t
浏览器输入服务器地址
进行安装
输入wp-config-sample.php文件中配置的数据库名等信息,进行注册登录
配置memcached
搞完这些就弄好了
下面开始配置缓存memcached,插件软件咔咔一顿安装
之前用的repo是那个就用那个,以免后面会出错。如果后面报错remi没有那个包
先yum list |grep php,找到你安装的php版本对应的包名,复制替换一下包名,
如果后面又需要找配置文件的位置的
直接find / -name “文件名”,咔咔一顿找,如果由多个配置文件,你需要斟酌一下配置那个,实在不行直接
ln -s 路径/文件名 路径/文件名,咔咔一顿连接
下面正式开始
1.安装依赖库
yum --enablerepo=remi install libevent
这个意思就是指定remi安装存储库,进行下载,因为我之前用的这个玩意下载的php
2.安装memcached
yum --enablerepo=remi install memcached
3.启动
systemctl start memcached
启动了你以为就完了嘛,不不不,还要配置php,让php连上memcached
4.安装libmemcached
yum --enablerepo=remi install libmemcacehd
5.安装php-memcached
yum --enablerepo=remi install memcached
安装完过后,直接一通find找到memcached.so和memcache.so这两个文件,把下面几句写到php.ini文件最后
[memcached]
extension=路径/memcached.so#就是刚刚find的路径
[memcache]
extension= 路径/memcahce.so#同理
咔咔一顿操作就整完了。
最后用ps -ef | grep memcached 看看是否存在进程memcached
然后查看一下端口是否在listen
netstat -tunlp
接下来用你的物理机访问服务器,安装一个插件叫做use memcached,然后就可以看到
就证明装完了。
最后就是俺的踩坑合集
1.因为我熟悉的时mysql5.7,一开始安装了MySQL8.0各种报错,还安装8.0好几遍,最后还把虚拟机存储空间沾满了,不得不重新安装cnetos7系统,最后屈服了,还是安装了mysql5.7
2.安装配置php,启动php-fpm时,一直报错,装了好几遍php
最后发现按照版本改一下名字就可以启动了
3.然后就是报错各种文件不存在,找各种配置文件,这个还好就是直接find就可以,然后多个里面找出来
4.最后memcached各种包报错,各种不存在,最罪恶的根源就是一开始直接一个yum install ,各种版本的包就下下来了,但是后来启动不了,直接给我整不会了,最后全用remi那个repo好像可以自动匹配版本那个意思。
5.最后的最后一定要记住,你的安装位置,方便卸载重装!!!!