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加速网页就已经实现了

相关推荐
笨鸟要努力2 小时前
Ubuntu 全盘备份
linux·运维·ubuntu
ChironW2 小时前
Ubuntu 22.04 离线环境下完整安装 Anaconda、CUDA 12.1、NVIDIA 驱动及 cuDNN 8.9.3 教程
linux·运维·人工智能·深度学习·yolo·ubuntu
池以遇3 小时前
云原生高级——nginx
运维·nginx·云原生
你无法关注此用户3 小时前
CentOS7搭建安全FTP服务器指南
运维·服务器
TG_yunshuguoji3 小时前
阿里云国际DDoS高防:添加网站配置指南
运维·后端·阿里云
轻松Ai享生活3 小时前
linux 日志详解
linux
小白的代码日记4 小时前
Linux常用指令
linux·运维·服务器
月舞之剑4 小时前
linux离线安装nodejs
linux·node.js
维尔切4 小时前
Linux中Https配置与私有CA部署指南
linux·运维·https
小熊h4 小时前
【自动化备份全网服务器数据项目】
linux·服务器·自动化·备份数据