安装环境

  • 操作系统 - CentOS 7.6
  • 主机名 - centos7.onitroad.com
  • IP 地址 - 192.168.1.100/24
在 CentOS 7 LAMP 服务器上安装 Wordpress

Wordpress (Wordpress.org) 是一个用 PHP 开发的免费的开源内容管理系统。

欢迎来到之路教程(on itroad-com)

安装 PHP 7.4

Wordpress 需要 PHP 7.4 或者更高版本,这在标准 yum 存储库中不可用。

因此,我们正在安装第三方 yum 存储库 Remi 以在 CentOS 7 上安装最新版本的 PHP。

但是,首先我们要安装 EPEL(企业 Linux 的另外软件包),因为 Remi 存储库依赖于 EPEL yum 存储库。

[root@centos7.onitroad.com ~]# yum install -y epel-release

使用 rpm 命令安装 Remi yum 存储库。

[root@centos7.onitroad.com ~]# rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

为 Remi yum 存储库构建缓存。

[root@centos7.onitroad.com ~]# yum makecache fast

从 Remi yum 存储库安装 PHP 7.4 和相关包。

[root@centos7.onitroad.com ~]# yum install -y php74-php php74-php-common php74-php-opcache php74-php-mcrypt php74-php-cli php74-php-gd php74-php-curl php74-php-mysqlnd

查看php是否安装成功

[root@centos7.onitroad.com ~]# php74 -v
PHP 7.4.0alpha2 (cli) (built: Jun 25 2019 09:01:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0alpha2, Copyright (c), by Zend Technologies

重新启动 httpd.service 使更改生效。

[root@centos7.onitroad.com ~]# systemctl restart httpd.service

安装 Apache 2.4 HTTP 服务器:

Apache 2.4 HTTP Server 在基本 yum 存储库中可用,因此,我们可以使用 yum 命令轻松安装它。

[root@centos7.onitroad.com ~]# yum install -y httpd

启用并启动 httpd.service 。

[root@centos7.onitroad.com ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@centos7.onitroad.com ~]# systemctl start httpd.service

在 Linux 防火墙中允许 HTTP 服务。

[root@centos7.onitroad.com ~]# firewall-cmd --permanent --add-service=http
success
[root@centos7.onitroad.com ~]# firewall-cmd --reload
success

在 CentOS 7 LAMP 服务器上安装 Wordpress

下载最新版本的 Wordpress。

[root@centos7.onitroad.com ~]# cd /tmp
[root@centos7.onitroad.com tmp]# wget https://wordpress.org/latest.tar.gz

将下载文件解压到 Apache 文档根目录。

[root@centos7.onitroad.com tmp]# tar xvf latest.tar.gz -C /var/www/html/
 
wordpress/wp-admin/post-new.php
wordpress/wp-admin/themes.php
wordpress/wp-admin/options-reading.php
wordpress/wp-trackback.php
wordpress/wp-comments-post.php

为 Wordpress 创建配置文件,如下所示。

[root@centos7.onitroad.com ~]# touch /var/www/html/wordpress/wp-config.php

调整文件权限和 SELinux 文件上下文。

[root@centos7.onitroad.com ~]# chown -R apache:apache /var/www/html/wordpress/
[root@centos7.onitroad.com ~]# restorecon -R /var/www/html/wordpress/

暂时将 SELinux 置于许可模式,以便 Wordpress 安装程序可以写入 wp-config.php 文件。

[root@centos7.onitroad.com ~]# setenforce 0

使用浏览器打开:

http://centos7.onitroad.com/wordpress/。

选择首选语言,然后单击继续。

阅读说明,然后单击 Let's go!。

提供我们在上一节中创建的数据库连接详细信息,例如数据库名称和用户。

单击提交。

点击运行安装。

在此页面中提供有关我们网站的详细信息。

单击安装 Wordpress。

WordPress 已安装。

点击登录进入登录页面。

为 Wordpress 创建 MariaDB 数据库和用户:

以 root 用户身份使用 mysql 命令连接到 MariaDB 数据库实例。

[root@centos7.onitroad.com ~]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.16-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)]>

根据 Wordpress 的要求创建数据库。

MariaDB [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 1 row affected (0.036 sec)

创建一个对 wordpress 数据库具有完全权限的用户。

MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY '123';
Query OK, 0 rows affected (0.003 sec)

重新加载权限表并退出。

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit
Bye

安装 MariaDB 10.3 服务器

MariaDB 5.x 软件包可通过标准 yum 存储库获得。
但是,Wordpress 需要 10.1 或者更高版本。
因此,我们将从 MariaDB yum 存储库在 CentOS 7 上安装 MariaDB 10.3 Server。

安装 MariaDB yum 存储库如下。

[root@centos7.onitroad.com ~]# cat >> /etc/yum.repos.d/mariadb.repo << EOF
> [mariadb]
> name=MariaDB
> baseurl=http://yum.mariadb.org/10.3/centos7-amd64
> gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
> gpgcheck=1
> enabled=1
> EOF

为 MariaDB yum 存储库构建缓存。

[root@centos7.onitroad.com ~]# yum makecache fast

现在,我们可以使用 yum 命令安装 MariaDB 10.3.

[root@centos7.onitroad.com ~]# yum install -y mariadb-server

安装程序已经启用了 MariaDB 服务,因此,我们只需要启动 MariaDB 服务。

[root@centos7.onitroad.com ~]# systemctl start mariadb.service

配置 MariaDB 服务器实例。

[root@centos7.onitroad.com ~]# 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
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] Y
 ... Success!
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!
日期:2020-09-17 00:16:39 来源:oir作者:oir