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

王林
发布: 2025-04-24 20:06:42
原创
590人浏览过

在使用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 \Pantheon\Integrations\Assets::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 '\Pantheon\Integrations\Utils::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网站时遇到的配置问题,让你的网站能够更加顺畅地运行。

以上就是如何在Pantheon上无缝集成Drupal?使用Composer轻松搞定!的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号