Centos搭建wordpress个人博客

2021-04-06  本文已影响0人  一巴掌拍出两坨脂肪
版权声明:本文为作者原创书籍。转载请注明作者和出处,未经授权,严禁私自转载,侵权必究!!!

情感语录:业精于勤,荒于嬉;行成于思,毁于随!

1.安装Apache

yum install httpd

执行命令后有安装提示请输入 "y" ,安装完毕显示下面信息即成功。

  Installed:
  httpd.x86_64 0:2.4.6-89.el7.centos                                                                                                          

  Dependency Installed:  apr.x86_64 0:1.4.8-3.el7_4.1   apr-util.x86_64 0:1.5.2-6.el7   httpd- 
  tools.x86_64 0:2.4.6-89.el7.centos   mailcap.noarch 0:2.1.41-2.el7  
  Complete!

2.开启 Apache服务

systemctl start httpd

3.设置Apache开机启动

systemctl enable httpd

4.关闭防火墙

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

5.验证Apache是否安装成功

打开浏览器,输入你虚拟机或者服务器IP出现这个界面说明你的Apache安装成功了。


6.安装数据库Mysql
6.1安装依赖包

yum install libaio

6.2下载.rpm文件

rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

6.3安装Mysql

yum install mysql mysql-server mysql-libs mysql-server

下载提示信息请输入“y” 提示如下信息即安装成功

Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.7.26-1.el7.x86_64                                                                                 1/7 
Installing : mysql-community-libs-5.7.26-1.el7.x86_64                                                                                   2/7 
Installing : mysql-community-client-5.7.26-1.el7.x86_64                                                                                 3/7 
Installing : mysql-community-server-5.7.26-1.el7.x86_64                                                                                 4/7 
Installing : mysql-community-libs-compat-5.7.26-1.el7.x86_64                                                                            5/7 
Erasing    : 1:mariadb-5.5.60-1.el7_5.x86_64                                                                                            6/7 
Erasing    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                       7/7 
Verifying  : mysql-community-server-5.7.26-1.el7.x86_64                                                                                 1/7 
Verifying  : mysql-community-client-5.7.26-1.el7.x86_64                                                                                 2/7 
Verifying  : mysql-community-libs-5.7.26-1.el7.x86_64                                                                                   3/7 
Verifying  : mysql-community-libs-compat-5.7.26-1.el7.x86_64                                                                            4/7 
Verifying  : mysql-community-common-5.7.26-1.el7.x86_64                                                                                 5/7 
Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                       6/7 
Verifying  : 1:mariadb-5.5.60-1.el7_5.x86_64                                                                                            7/7 

Installed:
mysql-community-client.x86_64 0:5.7.26-1.el7  mysql-community-libs.x86_64 0:5.7.26-1.el7  mysql-community-libs-        
compat.x86_64 0:5.7.26-1.el7 
mysql-community-server.x86_64 0:5.7.26-1.el7 

Dependency Installed:
  mysql-community-common.x86_64 0:5.7.26-1.el7                                                                                                

Replaced:
  mariadb.x86_64 1:5.5.60-1.el7_5                                     mariadb-libs.x86_64 1:5.5.60-1.el7_5                                    

Complete!

6.4 开机默认启动Apache 和Mysql 服务

systemctl enable httpd.service
systemctl enable mysqld.service

6.5重启一下这两个服务

systemctl restart httpd.service
systemctl restart mysqld.service

测试Mysql是否安装成功:

mysql -u root -p

出现错误提示“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

1.关闭Mysql服务

 systemctl stop mysqld.service

2.修改配置文件无密码登录

vi /etc/my.cnf

最后加上

skip-grant-tables

3.启动Mysql

systemctl start mysqld.service

4.登陆Mysql

mysql -u root

5.修改密码

use mysql;

update mysql.user set authentication_string=password('zxy1546688949') where user='root' ;  

6.再次打开my.cnf 把那最后那句刚添加的skip-grant-tables再删掉

7.重启Mysql

systemctl restart mysqld.service

再次验证

mysql -u root -p
输入密码 zxy1546688949(你设置的密码)

出现下面这些代码,说明你的Mysql已经安装成功

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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.

6.6创建数据库

create database wordpress

提示错误信息:“ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

6.7 修改mysql 密码策略

首先,修改validate_password_policy参数的值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

validate_password_length(密码长度)参数默认为8,我们修改为1

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

完成之后再次执行修改密码语句即可成功

 mysql>  alter user 'root'@'localhost' identified by 'zxy1546688949';
 Query OK, 0 rows affected (0.00 sec)

再次创建数据即可成功

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

7.安装PHP以及相关组件,分别执行下面三条命令,安装提示请输入“y”

yum install php

yum install php-mysql

yum install php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

测试PHP是否安装成功 ,在/var/www/html下建立一个test.php文件:

 vi /var/www/html/test.php

文件内输入如下内容并wq 退出:

<?php
phpinfo();
?>

现在你在浏览器种输入 http://ip地址/test.php,出现如下即安装成功

  1. 下载自己喜欢的WordPress中文版,利用xftp上传压缩包到服务器var/www/html/下.或者wget下载

    wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz

解压并配置

tar xzvf wordpress-4.9.4-zh_CN.tar.gz
cd wordpress/

mv * /var/www/html/

cd /var/www/html/

chmod 777 -R wp-content

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

vim  wp-config.php   //修改成你数据库开始创建的信息,大致如下


  // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
  /** WordPress数据库的名称 */
  define('DB_NAME', 'wordpress');

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

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

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

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

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

启动httpd

systemctl restart httpd

浏览器输入 ip地址/wordpress/wp-admin/setup-config.php 会出现下图界面。


填写完成信息后并登陆进入wordpress


1561965486(1).jpg

接着配置FTP,让WordPress能够下载跟上传文件

依次执行如下命令:

yum install vsftpd -y 
systemctl restart vsftpd

firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload

注:如果提示防火墙没有运行,则使用 'systemctl start firewalld '开启防火墙,关闭防火墙 'systemctl stop firewalld'

新建用户,跟密码

useradd zzh
passwd zzh  // 输入两次密码即ok

最后一步修改配置文件:
vim /etc/php.ini

upload_max_filesize = 50M
post_max_size = 50M

systemctl restart httpd
上一篇 下一篇

猜你喜欢

热点阅读