如何在 Debian 9 上使用 Apache 安装和配置 Drupal如何在 Debian 9 上使用 Apache 安装和配置 Drupal如何在 Debian 9 上使用 Apache 安装和配置 Drupal如何在 Debian 9 上使用 Apache 安装和配置 Drupal
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 9 上使用 Apache 安装和配置 Drupal

本教程适用于这些操作系统版本

  • Debian 11(Bullseye)
  • Debian 9(Stretch)

在此页

  1. 要求
  2. 1 入门
  3. 2 安装 LAMP 服务器
  4. 3 安装和配置 MariaDB
  5. 4 安装和配置 Drupal
  6. 5 访问 Drupal 网络界面
  7. 结论

Drupal 是一个免费的开源内容管理系统,可用于创建在线内容、网站和用户社区。它用 PHP 语言编写,使用 MySQL 作为数据库后端,并在 GNU 通用公共许可证下分发。 Drupal 附带超过 17,000 个插件来定制其功能。 Drupal 在所有 Web 服务器上运行,包括 Apache、Nginx、IIS、Lighttpd 以及作为后端数据库的 MySQL、MariaDB、MongoDB、SQLite、MS SQL Server、PostgreSQL 等。

在本文中,我们将演示如何在 Debian 9 服务器上安装 Drupal 8。

要求

  • 在您的系统上运行 Debian 9 的服务器。
  • Apache 2.x、MySQL 或带有 PDO 的 MariaDB。
  • 在您的服务器上设置了 sudo 权限的非根用户。

1 入门

首先,建议使用最新的稳定版本更新您的系统。您可以通过运行以下命令来执行此操作:

sudo apt-get update -y
sudo apt-get upgrade -y

更新系统后,您需要将一些必需的软件包安装到系统中。您可以通过运行以下命令来安装所有这些:

sudo apt-get install wget git unzip nano -y

2 安装LAMP服务器

在开始安装 Drupal 之前,您需要在服务器上安装和配置 LAMP 服务器(Apache、PHP 和 MySQL)。

首先,使用以下命令开始安装 Apache Web 服务器:

sudo apt-get install apache2 -y

安装完成后,您需要启动 Apache 服务并使其在下次系统启动时自动启动。为此,请运行以下命令:

sudo systemctl start apache2
sudo systemctl enable apache2

接下来,通过运行以下命令安装带有所需模块的 PHP:

sudo apt-get install php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-mcrypt php7.0-intl php7.0-mysql php7.0-curl php7.0-gd php7.0-soap php7.0-xml php7.0-zip -y

接下来,您需要对 php.ini 文件进行一些更改:

sudo nano /etc/php/7.0/cli/php.ini

如下所示更改行:

memory_limit = 512M
date.timezone = UTC
cgi.fix_pathinfo=0
upload_max_filesize = 100M
post_max_size = 100M

完成后,保存并关闭文件。

3 安装和配置 MariaDB

Drupal 需要 MariaDB/MySQL 作为数据库后端,因此您需要安装它。您可以通过运行以下命令来安装它:

sudo apt-get install mariadb-server -y

安装完成后,启动MariaDB服务,并通过运行以下命令使其在系统启动时自动启动:

sudo systemctl start mysql
sudo systemctl enable mysql

接下来,您需要为数据库设置安全性。您可以运行以下命令来保护 MariaDB 数据库:

sudo mysql_secure_installation

此脚本设置 root 密码,禁用远程 root 登录,删除测试数据库并删除匿名用户,如下所示:

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.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n

 ... skipping.

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!

保护数据库后,Drupal 需要一个空的 MySQL 数据库。因此,您需要为 Drupal 安装创建一个 MySQL 数据库和用户。

首先,使用以下命令登录 MySQL shell:

mysql -u root -p

在询问时输入 root 密码,然后使用以下命令为 Drupal 创建数据库:

MariaDB [(none)]>CREATE DATABASE drupaldb;

接下来,使用以下命令为 drupal 数据库创建用户并授予 drupal 数据库权限:

MariaDB [(none)]>GRANT ALL PRIVILEGES on drupaldb.* to 'drupal'@'localhost' identified by 'password';

接下来,运行 FLUSH PRIVILEGES 命令重新加载权限:

MariaDB [(none)]>FLUSH PRIVILEGES;

最后,使用以下命令退出 MariaDB 控制台:

MariaDB [(none)]>\q

4 安装和配置 Drupal

首先,你需要从他们的官网下载最新稳定版的Drupal,否则你可以直接使用wget命令下载,如下:

wget https://ftp.drupal.org/files/projects/drupal-8.3.4.zip

然后,解压下载的 zip 文件并将解压的 Drupal 目录移动到 Apache 根目录:

unzip drupal-8.3.4.zip
sudo mv drupal-8.3.4 /var/www/html/drupal

接下来,您需要更改 drupal 目录的一些权限:

sudo chown -R www-data:www-data /var/www/html/drupal
sudo chmod -R 777 /var/www/html/drupal

接下来,您需要为 drupal 创建一个 Apache 虚拟主机文件。为此,在 /etc/apache2/sites-available/ 目录中创建一个新的 drupal.conf 文件:

sudo nano /etc/apache2/sites-available/drupal.conf

添加以下行:

<VirtualHost *:80>
ServerAdmin 
DocumentRoot /var/www/html/drupal
ServerName 192.168.15.189
ServerAlias www.example.com
<<Directory "/var/www/html/drupal/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/drupal-error_log
CustomLog /var/log/apache2/drupal-access_log common
</VirtualHost>

完成后保存并关闭文件,然后使用以下命令启用虚拟主机:

sudo a2ensite drupal

您还需要激活重写模块。

sudo a2enmod rewrite

最后,使用以下命令重新启动 Apache 服务以应用此更改:

sudo systemctl restart apache2

5 访问 Drupal Web 界面

现在一切都已安装和配置。接下来,您需要允许 Drupal 通过 UFW 防火墙。默认情况下,UFW 防火墙在 Debian 9 中是禁用的,因此您需要先启用它。

sudo ufw enable

然后,通过运行以下命令允许端口 80 通过 UFW 防火墙:

sudo ufw allow 80

最后,打开您的网络浏览器并导航至 URL http://192.168.15.189 以启动 Drupal 网络安装程序。您应该会看到以下页面:

选择英语语言并单击“保存并继续”按钮,您应该会看到下图:

选择安装配置文件并单击“保存并继续”按钮,然后验证所有要求并单击“保存并继续”按钮。您应该看到下图:

在“数据库配置”页面中,提供所有必需的数据库详细信息,如数据库名称、数据库用户名和密码、数据库主机,然后单击“保存并继续”按钮,您应该会看到下图:

在 Drupal 站点配置页面中,提供您的站点名称、管理员用户名和密码,然后单击保存并继续按钮开始安装 Drupal。安装 Drupal 后,您应该会在下图中看到 Drupal 仪表板:

结论

恭喜!您已经在 Debian 9 服务器上成功安装并配置了 Drupal。我希望您现在可以使用 Drupal 轻松创建自己的网站。您可以访问 Drupal 文档页面 https://www.drupal.org/docs/8 了解更多详细信息。

©2015-2025 艾丽卡 support@alaica.com