如何在Pantheon上无缝集成Drupal?使用Composer轻松搞定!

在使用Pantheon托管Drupal网站时,我遇到了一个令人头疼的问题:如何正确配置数据库凭证、文件路径等,让我的网站能够无缝运行。最初,我尝试了手动配置,但这不仅耗时,而且容易出错。幸运的是,我发现了pantheon-systems/drupal-integrations这个库,它通过composer可以轻松解决这些问题。

可以通过一下地址学习composer学习地址

首先,你需要通过Composer安装pantheon-systems/drupal-integrations库。具体命令如下:

composer require pantheon-systems/drupal-integrations:^11.1

安装完成后,你需要在你的settings.php文件中启用Pantheon集成。添加以下代码:

include PantheonIntegrationsAssets::dir() . "/settings.pantheon.php";

这样,你的Drupal网站就能够自动注入Pantheon的数据库凭证,设置配置导入/导出目录、私有文件路径、临时文件路径和Twig缓存文件路径。此外,该库还会为Drupal建立一个安全的随机哈希盐,注入Pantheon服务提供者(如在缓存重建时清除边缘缓存),配置可信主机模式,并忽略大型缓存目录(例如node_modules和bower_components)。

需要注意的是,pantheon-systems/drupal-integrations的版本应与你的Drupal版本匹配。以下是版本对应表:

Drupal Version drupal-integrations Version
11.x ^11
10.x ^10
9.x ^9
8.x ^8

如果你使用的是早期版本的pantheon-systems/drupal-integrations,可能还会遇到脚手架(scaffolding)相关的问题。在Drupal 10.4及以后版本中,脚手架扩展已被弃用,如果你的站点仍在使用此功能,可能会看到以下错误消息:

Unable to download modules via the UI: Any packages other than the implicitly allowed packages are not allowed to scaffold files. See the scaffold documentation for more information. pantheon-systems/drupal-integrations
Your site cannot be automatically updated until further action is performed.  Any packages other than the implicitly allowed packages are not allowed to scaffold files. See the scaffold documentation for more information.  pantheon-systems/drupal-integrations

要解决这个问题,你需要更新到最新版本的pantheon-systems/drupal-integrations(对于Drupal 11站点应为11.1.0或更高版本,对于Drupal 10站点应为10.1.0或更高版本),并在你的composer.json文件中删除allowed-packages部分。接着,在你的settings.php文件中,将包含settings.pantheon.php文件的行替换为include-settings.php.tmpl文件的全部内容。

这些步骤可以通过Terminus自动完成(需要Terminus Composer插件):

$ terminus connection:set sftp $ terminus composer update $ terminus drush ev 'PantheonIntegrationsUtils::stopScaffolding();' $ terminus composer update $ terminus env:commit --message "Stop scaffolding Pantheon's Drupal integrations, and include directly from vendor instead."

使用pantheon-systems/drupal-integrations库和Composer,可以大大简化你在Pantheon上配置和集成Drupal的过程,提升效率,减少错误。希望这篇文章能帮你解决在Pantheon上运行Drupal网站时遇到的配置问题,让你的网站能够更加顺畅地运行。

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享