LAMP搭建wordpress并使用reids加速网页

L	linux
A	apache hhtpd
M	mysql/maridb
P	PHP

1、 安装php

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum install -y --enablerepo=remi --enablerepo=remi-php72 php php-opcache php-devel php-mysqlnd php-gd php-redis

2、 安装mysql5.7

2.1、搭建mysql源
cd /etc/yum.repos.d

vim mysql.repo

powershell 复制代码
[mysql]
name=mysql
baseurl=http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
enabled=1
gpgcheck=0
2.2、安装mysql
yum -y install mysql mysql-server
2.3、启动并自启mysql
systemctl enable mysqld --now
systemctl status mysqld
powershell 复制代码
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-09-07 13:26:43 CST; 50s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 8682 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 8632 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 8686 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─8686 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 07 13:26:37 ecs-1cee systemd[1]: Starting MySQL Server...
Sep 07 13:26:43 ecs-1cee systemd[1]: Started MySQL Server.
cat /var/log/mysqld.log | grep pass
powershell 复制代码
2023-09-07T06:47:10.572362Z 1 [Note] A temporary password is generated for root@localhost: /#7BEsP?dh1P	# mysql启动日志里面会包含临时密码
mysql -uroot -p'/#7BEsP?dh1P'	
powershell 复制代码
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.43

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'o*zu+1FzyG3';		#修改密码为o*zu+1FzyG3 
Query OK, 0 rows affected (0.00 sec)

[root@ecs-1cee yum.repos.d]# mysql -uroot -p'o*zu+1FzyG3'	#使用新密码登录
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database wordpress default character set utf8 collate utf8_general_ci		#创建wordpress数据库,字符集是utf8
    -> ;
Query OK, 1 row affected (0.00 sec)

3、 安装部署httpd服务

3.1、安装httpd服务
yum -y install httpd
3.2、启动并自启
systemctl enable httpd --now
systemctl status httpd
powershell 复制代码
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-09-07 13:35:48 CST; 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 8774 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
           ├─8774 /usr/sbin/httpd -DFOREGROUND
           ├─8775 /usr/sbin/httpd -DFOREGROUND
           ├─8776 /usr/sbin/httpd -DFOREGROUND
           ├─8777 /usr/sbin/httpd -DFOREGROUND
           ├─8778 /usr/sbin/httpd -DFOREGROUND
           └─8779 /usr/sbin/httpd -DFOREGROUND

Sep 07 13:35:48 ecs-1cee systemd[1]: Starting The Apache HTTP Server...
Sep 07 13:35:48 ecs-1cee httpd[8774]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the...is message
Sep 07 13:35:48 ecs-1cee systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

4、 部署WordPress

4.1、下载WordPress

官网下载地址:https://cn.wordpress.org/download/

cd /opt
wget https://cn.wordpress.org/latest-zh_CN.zip
4.2、部署WordPress
unzip latest-zh_CN.zip
cp -r wordpress/ /var/www/html/
cd 	/var/www/html/wordpress
cp wp-config-sample.php wp-config.php

vi wp-config.php

powershell 复制代码
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', 'o*zu+1FzyG3' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
chmod -R 777 /var/www/html/
systemctl restart httpd
4.3、访问wordpress
114.115.151.96/wordpress		#根据实际的IP或者域名进行访问


以下内容均可自定义

站点: wordpress
用户名:admin
密码:admin
您的电子邮箱地址:111@qq.com
最后点击安装WordPress
4.2、查看网页加载时间
  • 浏览器页面按"F12"键,勾选"Disable cache"(停用缓存)选
    项,查看页面加载时间。刷新 WordPress 界面,待其完全加载完成,可以在页面下方看到加
    载时间为31.18秒

5、部署redis

5.1、安装redis
yum -y install redis
5.2、启动自启
systemctl enable redis --now
systemctl status redis
powershell 复制代码
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Thu 2023-09-07 15:23:24 CST; 1min 59s ago
 Main PID: 22558 (redis-server)
   CGroup: /system.slice/redis.service
           └─22558 /usr/bin/redis-server 127.0.0.1:6379

Sep 07 15:23:24 ecs-6822 systemd[1]: Starting Redis persistent key-value database...
Sep 07 15:23:24 ecs-6822 systemd[1]: Started Redis persistent key-value database

5.3、redis配置密码

vim /etc/redis.conf
powershell 复制代码
  requirepass 123456
  bind 0.0.0.0
systemctl restart redis
5.3、在 wp-config.php 配置中配置redis连接信息
cd /var/www/html/wordpress/

vi wp-config.php

powershell 复制代码
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', 'o*zu+1FzyG3' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/*redis config*/
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', '6379');
define('WP_REDIS_PASSWORD', '123456');

redis连接信息一定要放到数据库连接信息后面才能生效

配置一下wordpress目录权限

cd  /var/www/html/wordpress

放到最下面了

vi wp-config.php

powershell 复制代码
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);

重启启动httpd服务并安装redis插件

systemctl restart httpd

点击启用


如下图,已经连接上了reids

5.4、访问网页测试浏览速度

可以发现访问速度明显提升了很多

!!!到这里使用LAMP建WordPress并使用redis加速网页就已经实现了

相关推荐
Shepherd06191 小时前
【Jenkins实战】Windows安装服务启动失败
运维·jenkins
Biomamba生信基地2 小时前
Linux也有百度云喔~
linux·运维·服务器·百度云
new_abc2 小时前
Ubuntu 22.04 ftp搭建
linux·运维·ubuntu
flying robot2 小时前
RPM的使用
linux
鹿鸣天涯2 小时前
‌华为交换机在Spine-Leaf架构中的使用场景
运维·服务器·网络
小白也有IT梦2 小时前
域名绑定服务器小白教程
运维·nginx
有梦想的咕噜3 小时前
Secure Shell(SSH) 是一种网络协议
运维·网络协议·ssh
dntktop3 小时前
免费,WPS Office教育考试专用版
运维
苹果醋33 小时前
C语言 strlen 函数 - C语言零基础入门教程
java·运维·spring boot·mysql·nginx