如何在Pantheon上無縫集成Drupal?使用Composer輕松搞定!

在使用Pantheon托管Drupal網(wǎng)站時,我遇到了一個令人頭疼的問題:如何正確配置數(shù)據(jù)庫憑證、文件路徑等,讓我的網(wǎng)站能夠無縫運行。最初,我嘗試了手動配置,但這不僅耗時,而且容易出錯。幸運的是,我發(fā)現(xiàn)了pantheon-systems/drupal-integrations這個庫,它通過composer可以輕松解決這些問題。

可以通過一下地址學(xué)習(xí)composer學(xué)習(xí)地址

首先,你需要通過Composer安裝pantheon-systems/drupal-integrations庫。具體命令如下:

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

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

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

這樣,你的Drupal網(wǎng)站就能夠自動注入Pantheon的數(shù)據(jù)庫憑證,設(shè)置配置導(dǎo)入/導(dǎo)出目錄、私有文件路徑、臨時文件路徑和Twig緩存文件路徑。此外,該庫還會為Drupal建立一個安全的隨機哈希鹽,注入Pantheon服務(wù)提供者(如在緩存重建時清除邊緣緩存),配置可信主機模式,并忽略大型緩存目錄(例如node_modules和bower_components)。

需要注意的是,pantheon-systems/drupal-integrations的版本應(yīng)與你的Drupal版本匹配。以下是版本對應(yīng)表:

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

如果你使用的是早期版本的pantheon-systems/drupal-integrations,可能還會遇到腳手架(scaffolding)相關(guān)的問題。在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站點應(yīng)為11.1.0或更高版本,對于Drupal 10站點應(yīng)為10.1.0或更高版本),并在你的composer.json文件中刪除allowed-packages部分。接著,在你的settings.php文件中,將包含settings.pantheon.php文件的行替換為include-settings.php.tmpl文件的全部內(nèi)容。

這些步驟可以通過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網(wǎng)站時遇到的配置問題,讓你的網(wǎng)站能夠更加順暢地運行。

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點贊14 分享