超级详细的CentOS搭建个人网站(WordPress)

写在前面

因为之前写的文章存在很多错误,在加之自己的服务器重装了系统,特地边做边写了这篇文章。过程真的超级详细

准备

CentOS系统(我是CentOS7.6)
wordpress 安装包 ( 复制这个链接到迅雷下载
Xshell 和Xftp (没有的可以参考我之前的文章Xshell免费版下载

软件安装

更新软件目录

yum -y update

重启

安装httpd

安装httpd(看见Complete!即为下载成功)

yum -y install httpd

查看是否安装

 rpm -qa | grep httpd

开机自启

 systemctl enable httpd

启动httpd

systemctl start httpd.service

查看http状态

systemctl status httpd.service

在这里插入图片描述
打开网页检测一下
在这里插入图片描述

安装MariaDB

(MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB)
检测有没有mariadb

rpm -qa | grep mariadb

卸载maridb

rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64

检查一下
在这里插入图片描述

rpm -qa | grep mariadb 

安装mariadb

yum -y install mariadb-server

开机启动

systemctl enable  mariadb.service

启动mariadb

systemctl start mariadb.service

初始化配置

 mysql_secure_installation
[root@iZbp130c4bdxfhinub38n6Z ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): (直接回车)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y (是否设置root密码:是)
New password: (输入你的密码)
Re-enter new password: (确认密码)
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y(是否移除匿名用户:是)
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n(是否禁止远程登录:否)
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y(是否删除测试数据库:是)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y(重新载入:是)
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@iZbp130c4bdxfhinub38n6Z ~]# 

创建wordpress数据库
登录数据库

 mysql -u root -p 

创建数据库(创建一个名字为wordpress的字符集为utf8的数据库)

 create database wordpress character set utf8;

添加一个wordpress的用户(添加一个名字为root密码为12345的用户)

 grant all privileges on wordpress.* to 'root'@'localhost' identified by '123456';

刷新数据库权限信息

 flush privileges;

退出

 exit

在这里插入图片描述

安装php

清除历史php

 yum -y remove php*

安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包。
php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtatic。如果跳过epel-release的话,安装webtatic的时候,会有错误爆出。

修改yum源

yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

在这里插入图片描述
安装php7.2(一路y)

 yum install php72w

安装PHP宇宙无敌豪华版拓展(最重要的是php72w-mysqlnd php72w-cli php72w-fpm )

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

测试php
在Apache网页目录下创建一个以.php结尾的php文件并重启httpd服务

 vim /var/www/html/test.php

输入

 <?php
     phpinfo();
     ?>

重启httpd

 systemctl restart httpd.service

浏览器进ip/test.php
在这里插入图片描述
在这里插入图片描述

安装wordpress

新建文件夹

 mkdir /var/blog

把wordpress上传到blog里面并解压

 tar -zxvf latest-zh_CN.tar.gz

删除安装包

 rm latest-zh_CN.tar.gz

修改httpd配置文件

vim /etc/httpd/conf/httpd.conf

加上

 <VirtualHost *:80>
     ServerName 域名或ip
     DocumentRoot "/var/blog/wordpress"
     <Directory "/var/blog/wordpress">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order deny,allow
     Allow from all
     Require all granted
     </Directory>
     ErrorLog logs/blog-error.log
     CustomLog logs/blog-access.log common
     </VirtualHost>

配置wordpress(也可以在网页里面改)

cd /var/blog/wordpress
cp wp-config-sample.php  wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define( 'DB_NAME', '数据库名称(wordpress)' );

/** MySQL数据库用户名 */
define( 'DB_USER', '用户名(root)' );

/** MySQL数据库密码 */
define( 'DB_PASSWORD', '123456' );

/** MySQL主机 */
define( 'DB_HOST', 'localhost' );

/** 创建数据表时默认的文字编码 */
define( 'DB_CHARSET', 'utf8' );

/** 数据库整理类型。如不确定请勿更改 */
define( 'DB_COLLATE', '' );

重启httpd

systemctl restart httpd.service

然后

打开网页

nice!!!!!

大家可以到我搭建的博客看一下:http://flagzhang.fun/

一些安装wordpress之后会遇到的问题

FTP问题

在这里插入图片描述

 vim var/blog/wordpress/wp-config.php

加上

 define("FS_METHOD","direct");
     define("FS_CHMOD_DIR", 0777);
     define("FS_CHMOD_FILE", 0777);

文件权限

参考 https://www.wpdaxue.com/wordpress-file-read-and-write-permission.html

更新时无法创建目录

改apache权限

 chown -R apache:apache /var/blog/wordpress 

429 Too Many Requests

参考 https://www.wpdaxue.com/wordpress-org-429-too-many-requests.html

发布了6 篇原创文章 · 获赞 2 · 访问量 1671

猜你喜欢

转载自blog.csdn.net/qq_25504829/article/details/104254788