四时宝库

程序员的知识宝库

如何在Linux下使用WordPress快速建站

1.MySQL服务快速安装

通过yum安装指定版本的MySQL Server

##下载指定本版的mysql server源
[root@VM-0-12-centos ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
##导入到本地yum rpm源
[root@VM-0-12-centos ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
##查看本地mysql yum源
[root@VM-0-12-centos ~]# yum repolist enabled | grep "mysql.*-community.*"
##通过本地yum rpm源安装mysql server
[root@VM-0-12-centos ~]# yum install -y mysql-community-server

问题处理:

如果yum install -y mysql-community-server执行报如下错时:

....
Public key for mysql-community-common-5.7.42-1.el7.x86_64.rpm is not installed

 Failing package is: mysql-community-common-5.7.42-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
 

 ##可执行下面命名更新下源再安装
 [root@VM-0-12-centos ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
 [root@VM-0-12-centos ~]# yum install -y mysql-community-server
 ......
Dependency Installed:
  mysql-community-client.x86_64 0:5.7.42-1.el7                                                          mysql-community-common.x86_64 0:5.7.42-1.el7                                                         

Replaced:
  mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                                                          

Complete! 

安装成功后的配置工作:

##启动mysql服务
[root@VM-0-12-centos ~]# systemctl start mysqld
##开机启动mysql服务
[root@VM-0-12-centos ~]# systemctl enable mysqld

##修改root初始化密码
[root@VM-0-12-centos ~]# grep 'temporary password' /var/log/mysqld.log

##根据上面拿到的密码登录修改root密码
[root@VM-0-12-centos ~]# mysql -uroot -p 
Enter password: 
......
##修改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Xxxx!@#';
##设置root允许远程登陆,并刷新权限
mysql> update user set host="%" where user="root";
mysql> flush privileges;

2.PHP服务快速安装

通过yum安装php服务环境

##1.安装 EPEL 软件包
[root@VM-0-12-centos ~]#  yum install -y epel-release
##2.安装 remi 源(安装后在/etc/yum.repos.d/下就有php源了)
[root@VM-0-12-centos ~]#  yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
##3.安装 yum 扩展包
[root@VM-0-12-centos ~]#  yum install -y yum-utils
##4.安装及安装扩展
[root@VM-0-12-centos ~]#  yum install -y php74
[root@VM-0-12-centos ~]#  yum install -y php74-php-fpm php74-php-gd php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache
[root@VM-0-12-centos ~]#  yum install -y php74-php-devel
##5.查看php版本
[root@VM-0-12-centos ~]#  php74 -v
##6.启动服务并设置开机启动
[root@VM-0-12-centos ~]#  systemctl start php74-php-fpm
[root@VM-0-12-centos ~]#  systemctl enable php74-php-fpm
##7.设置php链接
[root@VM-0-12-centos ~]#  ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php
[root@VM-0-12-centos ~]#  php -v

其他按实际情况可操作的配置

##如果运行的是nginx而不是apache,修改
[root@VM-0-12-centos ~]#  vim /etc/opt/remi/php74/php-fpm.d/www.conf
找到:
user = apache
group = apache
修改为:
user = nginx
group = nginx

##为nginx开启php的session权限
#进入php目录
[root@VM-0-12-centos ~]#  cd /var/opt/remi/php74/lib/php/ 
#开启nginx保存session的权限
[root@VM-0-12-centos ~]#  chown -R nginx:nginx session 

--------------------------------------------------------
###php相关配置文件目录介绍:
/opt/remi/php74/root/usr/bin/php-config
/var/opt/remi/php74/lib/php/session
/etc/opt/remi/php74/php.ini
/etc/opt/remi/php74/php-fpm.d/www.conf
--------------------------------------------------------


##php卸载的命令
[root@VM-0-12-centos ~]#  yum remove php74*

3.Nginx服务快速安装

通过yum快速安装nginx

[root@VM-0-12-centos ~]# yum -y install nginx
##启动服务并设置开机启动
[root@VM-0-12-centos ~]# systemctl start nginx
[root@VM-0-12-centos ~]# systemctl enable nginx

可执行文件:/usr/sbin/nginx
配置文件目录: /etc/nginx/
日志文件目录:/var/log/nginx/
前端文件目录:/usr/share/nginx/html

4.wordpress的安装

配置mysql数据库

mysql> create database wp_db default character set utf8mb4 collate utf8mb4_unicode_ci;
mysql> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wpuser!@#';
mysql> GRANT ALL PRIVILEGES ON wp_db.* TO 'wpuser'@'localhost';
mysql> FLUSH PRIVILEGES;

下载解压wordpress安装包并配置:

## aigc-bot.com这个目录可以自定义名称,可以是你的网站域名或者其他

[root@VM-0-12-centos php]# mkdir -p /var/www/html/aigc-bot.com
[root@VM-0-12-centos php]# cd /var/www/html/
[root@VM-0-12-centos html]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
[root@VM-0-12-centos html]# tar -zxvf latest-zh_CN.tar.gz

[root@VM-0-12-centos html]# mv wordpress/* ./aigc-bot.com/
[root@VM-0-12-centos html]# ll wordpress/
total 0
[root@VM-0-12-centos html]# rm -rf wordpress/
[root@VM-0-12-centos html]# rm -rf latest-zh_CN.tar.gz
[root@VM-0-12-centos html]# cd ./aigc-bot.com/
[root@VM-0-12-centos aigc-bot.com]# mv wp-config-sample.php wp-config.php
[root@VM-0-12-centos aigc-bot.com]# vim wp-config.php
##修改相关数据库配置
......
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wp_db' );

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

/** Database password */
define( 'DB_PASSWORD', 'wpuser!@#' );

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

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

以上都完成部署之后,通过nginx 配置 80 端口服务映射到 /var/www/html/aigc-bot.com

则 通过浏览器可访问:ip/wp-admin 开启wordpress安装


发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言