网站搜索

如何在 FreeBSD 中使用 FAMP Stack 安装 WordPress


在本教程中,我们将学习如何在 FreeBSDFAMP 堆栈中安装 WordPressFAMP 堆栈是缩写词,代表 FreeBSD Unix 操作系统、Apache HTTP 服务器(一种流行的开源 Web 服务器)、 >MariaDB关系数据库管理系统(目前由社区维护的MySQL数据库分支),以及在服务器端运行的PHP动态编程语言。

WordPress 是世界上最著名的 CMS 框架,用于构建简单的博客或专业网站。

要求

  1. FreeBSD 安装指南

第 1 步:在 FreeBSD 中安装 FAMP Stack

1. 为了在您的场所部署 WordPress 网站,您需要确保在 FreeBSD 中安装并运行以下 FAMP 组件。

在 FreeBSD 中需要安装的第一个服务是 Apache HTTP 服务器。要通过官方 FreeBSD ports 存储库安装 Apache 2.4 HTTP 服务器二进制包,请在服务器控制台中发出以下命令。

pkg install apache24

2. 接下来,通过执行以下命令在 FreeBSD 中启用并启动 Apache HTTP 守护进程。

sysrc apache24_enable="yes"
service apache24 start

3. 打开浏览器并通过 HTTP 协议导航到服务器的 IP 地址或 FQDN,以查看 Apache 默认网页。您的浏览器中应显示“它有效!”消息。

http://yourdomain.tld

4. 接下来,通过发出以下命令在您的服务器中安装具有以下所需扩展的 PHP 7.1 版本。我们的 WordPress 网站将部署在此 PHP 版本之上。

pkg install php71 php71-mysqli mod_php71 php71-mbstring php71-gd php71-json php71-mcrypt php71-zlib php71-curl

5. 下一步,使用以下内容为 Apache Web 服务器创建 php.conf 配置文件。

nano /usr/local/etc/apache24/Includes/php.conf

将以下配置添加到 php.conf 文件中。

<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
</IfModule>

6. 保存并关闭此文件并重新启动 Apache 守护程序,以便通过发出以下命令应用更改。

service apache24 restart

7. 最后一个缺少的组件是 MariaDB 数据库。要在 FreeBSD 中安装最新版本的 MariaDB 数据库服务器,请执行以下命令。

pkg install mariadb102-client mariadb102-server

8. 接下来,通过运行以下命令在 FreeBSD 中启用 MariaDB 服务并启动数据库守护进程。

sysrc mysql_enable="YES"
service mysql-server start

9.下一步,执行mysql_secure_installation脚本以保护MariaDB。使用以下脚本输出示例来保护 MariaDB 数据库。

/usr/local/bin/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!

10.最后,在MariaDB服务器中创建WordPress安装数据库。要创建数据库,请登录 MariaDB 控制台并发出以下命令。

为此数据库选择一个描述性名称,创建数据库用户和密码来管理该数据库。

mysql -u root -p
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all privileges on wordpress.* to 'user_wordpress'@'localhost' identified by 'password';
MariaDB [(none)]> flush privileges;

第 2 步:在 FreeBSD 中安装 WordPress

11. 要在 FreeBSD 中安装最新版本的 WordPress,请转到 WordPress 下载页面并借助 wget 实用程序获取最新的可用 traball 版本。

通过发出以下命令解压缩 tarball 并将所有 WordPress 安装文件复制到 Apache 文档根目录。

wget https://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
cp -rf wordpress/* /usr/local/www/apache24/data/

12. 接下来,通过发出以下命令授予 Apache www 组对 WordPress 安装目录的写入权限。

chown -R root:www /usr/local/www/apache24/data/
chmod -R 775 /usr/local/www/apache24/data/

13.现在,开始安装WordPress。打开浏览器并通过 HTTP 协议导航到您的服务器 IP 地址或域名。在第一个屏幕中,点击Let's go!按钮开始安装过程。

14. 接下来,添加 MySQL 数据库名称、用户和密码,然后点击提交按钮继续,如下面的屏幕截图所示。

15.在下一个屏幕上,WordPress安装程序将通知您它可以成功连接到MySQL数据库。点击运行安装按钮来安装数据库架构。

16. 在下一个屏幕中,选择您的网站标题和用户名以及强密码来管理 WordPress 网站。另外,添加您的电子邮件地址并点击安装 WordPress 按钮以完成安装过程。

17.安装过程完成后,将显示一条消息,通知您 WordPress CMS 已成功安装。在此页面上,您还可以找到登录网站管理面板所需的凭据,如下图所示。

18.最后,使用上一步中提供的凭据登录 WordPress 管理仪表板,您现在可以开始为您的网站添加新帖子。

19.为了访问您的网站前端页面,请导航到您的服务器 IP 地址或域名,您将在其中看到名为“Hello World!”的默认帖子,如图所示在下图中。

http://yourdomain.tld

恭喜!您已在 FreeBSD 中的 FAMP 堆栈下成功安装了 WordPress 内容管理系统。