配置阿里网络源

删除centos7自带的yum源文件

1
rm -rf /etc/yum.repos.d/*

将CentOS-Base.repo和epel.repo上传到root目录下

1
2
3
mv /root/CentOS-Base.repo /etc/yum.repos.d/
mv /root/epel.repo /etc/yum.repos.d/
yum repolist

安装Apache

执行如下命令,安装Apache服务及其扩展包

1
yum -y install httpd mod_ssl mod_perl mod_auth_mysql

执行如下命令,查看Apache是否安装成功。

1
httpd -v

返回结果如下所示,表示您已成功安装Apache。

1
2
3
4
[root@localhost ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 5 2023 17:18:30
[root@localhost ~]#

执行如下命令,启动Apache服务。

1
systemctl start httpd.service

关闭防火墙和临时关闭seliunx

1
2
systemctl stop firewalld
setenforce 0

浏览器的址栏中,访问http://<ip地址>

QQ截图2023042020sa145as

若返回页面如下图所示,说明Apache服务启动成功。

安装MariaDB

1
yum install -y mariadb-server

启动MariaDB Server

1
systemctl start mariadb

执行如下命令,查看MariaDB Server运行状态

1
systemctl status mariadb

执行如下命令,设置数据库root用户的初始密码

1
mysqladmin -u root -p password

返回如下结果,由于您是第一次设置数据库密码,因此在出现Enter Password提示符的时,直接回车即可。

1
2
[root@localhost ~]# mysqladmin -u root -p password
Enter password:

返回如下结果,输入新密码为123456789,回车后再次输入123456789即可。(输入的密码不会显示出来,这是正常的,没有出错)

1
2
3
4
[root@localhost ~]# mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:

执行如下命令,连接数据库并赋予权限

1
mysql -uroot -p123456789
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@localhost ~]# mysql -uroot -p123456789
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456789' with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456789' with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit;
Bye
[root@localhost ~]#

安装php

PHP是一种广泛使用的通用开源脚本语言,适合于Web网站开发,它可以嵌入HTML中

执行如下命令,安装PHP。

1
yum -y install php php-mysql gd php-gd gd-devel php-xml php-common php-mbstring php-ldap php-pear php-xmlrpc php-imap

执行如下命令,创建PHP测试页面

1
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

执行如下命令,重启Apache服务。

1
systemctl restart httpd

在浏览器的地址栏中,访问http://<ip地址>/phpinfo.php

QQ截图20230420201845as

安装和配置WordPress

执行如下命令,安装WordPress。

1
yum -y install wordpress

修改WordPress配置文件

1
2
3
4
5
# 进入/usr/share/wordpress目录。
cd /usr/share/wordpress
# 修改路径。
ln -snf /etc/wordpress/wp-config.php wp-config.php
# 查看修改后的目录结构

执行如下命令,移动wordpress文件到Apache根目录。

1
mv /usr/share/wordpress/* /var/www/html/

修改wp-config.php配置文件

原wp-config.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** MySQL database username */
define( 'DB_USER', 'username_here' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );

/** MySQL 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', '' );
...
1
vi /var/www/html/wp-config.php

修改后wp-config.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', '123456789' );

/** MySQL 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', '' );
...

执行如下命令,重启Apache服务。

1
systemctl restart httpd

测试WordPress

在浏览器地址栏中,访问http://<ip地址>/

QQ截图20230420201845