wordpress 6.5.2版本安装记录

环境准备

鉴于工作中用到红帽系的服务器操作系统居多,本文选择Rocky Linux 8.9版本作为部署环境,Apache、MariaDB、PHP等均通过手动安装的方式。如果您不了解Linux系统,也不熟悉LAMP,那建议您还是选择虚拟主机提供商的预装服务。

计划安装的版本如下:

  • 操作系统:Rocky Linux 8.9
  • Apache:2.4.37
  • MariaDB:10.6
  • PHP:8.3

如果个人安装操作系统进行测试,建议关闭selinux、firewalld,命令如下:

# 临时修改selinux的模式为permissive
setenforce 0
# 建议修改/etc/selinux/config,修改为SELINUX=disabled,需要重启操作系统生效

# 关闭firewalld
systemctl stop firewalld
systemctl disable firewalld

Apache安装配置

安装

Apache安装相对简单,建议直接通过yum安装即可,安装命令如下:

yum install httpd

Rocky Linux 8.9默认安装的版本是2.4.37。

配置虚拟主机

创建运行账户,不建议使用apache账户运行

useradd wptest

创建虚拟主机目录为/home/wptest/www/html

# 创建目录
mkdir -p /home/wptest/www/html

#设置目录所有者和权限
chown wptest:wptest -R /home/wptest/www/html
chmod 755 -R /home/wptest/www/html

在/etc/httpd/conf.d目录下创建文件:wptest.conf,内容如下:

<VirtualHost *:80>
ServerAdmin  admin@mailabc.cn
ServerName  www.mailabc.cn
ServerAlias  www
DocumentRoot /home/wptest/www/html
<Directory "/home/wptest/www/html/">
    Options  FollowSymLinks
    AllowOverride  All
    Require  all  granted
</Directory>
ErrorLog /var/log/httpd/wptest_error.log
CustomLog /var/log/httpd/wptest_access.log combined
</VirtualHost>

修改httpd运行账户为wptest,修改/etc/httpd/conf/httpd.conf配置文件:

User wptest
Group wptest

配置httpd开机自启动

systemctl enable httpd
systemctl start httpd

直接在浏览器中访问http://your_ip/可以出现apache默认的界面即表示安装完成。

MariaDB安装配置

配置MariaDB yum源

MariaDB的yum源可以直接到官方获取:https://mariadb.org/download/?t=repo-config&d=Red+Hat+Enterprise+Linux+8&v=10.6&r_m=aliyun

也可以采用下面的内容:

# MariaDB 10.6 RedHatEnterpriseLinux repository list - created 2024-04-08 13:57 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/10.6/rhel/$releasever/$basearch
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/rhel/$releasever/$basearch
module_hotfixes = 1
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

在/etc/yum.repos.d 目录创建mariadb.repo文件,输入上面内容或者从官网获取的repo文件内容。然后执行下面命令建立缓存:

yum makecache

安装MariaDB

最后采用下面的命令进行安装即可:

yum install MariaDB-server MariaDB-client

配置MariaDB

首先启动服务,并设置开机自启动:

systemctl start mariadb
systemctl enable mariadb

默认情况下,初始安装后,root账号(此root账号非操作系统root账号,是指MariaDB的root账号)密码为空,需要给root账户设置一个密码(网上五花八门的方法,很多不靠谱,这里针对的是10.6版本的MariaDB),建议按照下面的方法执行:

# root账号登录MariaDB
mysql -u root

# 登录MariaDB之后,输入下面的命令修改root密码。下面命令中your_password换成你要改的密码
alter user root@localhost identified via mysql_native_password using password('your_password');

建议删除test数据库,登录数据库之后,执行如下命令:

drop database test;

为wordpress创建数据库和账户

创建名为wptestdb的数据库(后面配置wordpress会用到):

create database wptestdb;

授权wptest用户访问wptestdb数据库,并给wptest用户设置一个密码(需要修改下面your_password密码,后面配置wordpress会用到):

grant all on blogdb.* to mailabc@localhost identified by 'your_password';

安装配置PHP

配置PHP yum源

配置EPEL yum源,并手动导入remi的yum源:

yum install epel-release
rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-8.9.rpm

小技巧:可以进入 Index of /enterprise 这里找你需要的操作系统版本对应的yum源。

安装PHP8.3

按照下面命令安装:

yum install php83-php php83-php-mysqlnd php83-php-pecl-imagick php83-php-pecl-zip php83-php-gd php83-php-intl

小技巧:上面安装了很多php的插件,这些基本上都是能用到的,建议直接安装。要不然后面会有各种各样的小问题。

修改php-fpm的启动用户和组为wptest,这一步是和上面httpd配置相呼应。修改配置文件/etc/opt/remi/php83/php-fpm.d/www.conf 下面几个配置:

user wptest
group wptest

#这里如果不配置,wptest用户将无法读取/var/opt/remi/php83/run/php-fpm/www.sock 这个scoket文件。
listen.acl_users = wptest

小技巧:这一步很重要,我在这里踩坑,每次重启php-fpm服务后/var/opt/remi/php83/run/php-fpm/www.sock 文件权限都会变为root,导致wptest用户无法读取该文件。上面的配置是通过acl权限列表的方式,对该文件增加wptest用户的访问权限。

配置自启动

systemctl enable php83-php-fpm
systemctl start php83-php-fpm

测试php运行状态

在/home/wptest/www/html目录下创建phpinfo.php文件,内容如下:

<?php phpinfo(); ?>

然后在浏览器中访问该文件,如http://your_ip/phpinfo.php,如果正常返回php的版本信息页面说明配置成功。

至此,LAMP环境配置完成。

wordpress安装

下载最新版本

wget https://cn.wordpress.org/latest-zh_CN.zip

放到httpd虚拟主机目录下解压,示例中所在目录/home/wptest/www/html:

gunzip latest-zh_CN.zip

解压之后,需要把文件放到上面html直属目录。

配置

通过下面命令,创建wordpress的配置文件:

cp wp-config-sample.php wp-config.php

修改wp-config.php文件,需要定义:

  • DB_NAME:数据库名称,示例中对应wptestdb
  • DB_USER:访问数据库用户,示例中对应wptest
  • DB_PASSWORD:访问数据库用户对应的密码
/** The name of the database for WordPress */
define( 'DB_NAME', 'wptestdb' );
/** Database username */
define( 'DB_USER', 'wptest' );
/** Database password */
define( 'DB_PASSWORD', 'your_password' );
/** 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', '' );

此外,下面这些也建议修改,可以 https://api.wordpress.org/secret-key/1.1/salt/ 直接生成替换掉下面内容即可:

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

初始化

下面通过浏览器访问http://your_ip/进行初始化即可。

总结

至此,wordpress部署完成。后面有时间再介绍通过nginx做反向代理、部署https服务等。

实际部署过程中可能会遇到各种问题,但最终这些问题都是可以解决的,需要保持耐心。如果你也遇到了难题,可以留言探讨。

参考来源:wordpress 6.5.2版本安装记录 | MailABC邮件知识百科

  • 27
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值