1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Acquia Cloud PlatformでDrupalマルチサイトを起動する

Last updated at Posted at 2022-05-12

Acquia Cloud Platform上でDrupal 9マルチサイトを起動する覚書メモ。

次のURLのような、サブディレクトリでマルチサイトを作成することを想定する。

  • ***.com/site1
  • ***.com/site2
  • ...

Docker+Landoでローカル環境の設定

空のディレクトリを作成して移動しておく。

$ mkdir ace-povjapan-multisite && cd ace-povjapan-multisite

ディレクトリ直下にLandoの設定ファイルを作成する。

$ lando init

? From where should we get your app\'s codebase? current working directory # コードベースの場所を指定
? What recipe do you want to use? acquia                # レシピを選択
? Select an Acquia Cloud Platform API token ******      # Acquia Cloud Platform APIトークンを選択。作成してなければ作成
? Which site? *****                                     # デプロイする対象のAcquia Cloud Platformのアプリケーションを選択

実行が完了すると .lando.ymlファイルが作成される。マルチサイト用のデータベースを追加するために、設定ファイルに次の行を追加する。

.lando.yml
...省略...
  ah_site_group: povjapan2
  php: '7.4'

# ここから
services:
  site1_db:
    type: mysql:5.7
    portforward: 33068
# ここまで

設定ファイルの内容を反映させるためにLando環境を再構築する。

$ lando rebuild -y

Acquia CLIでDrupalプロジェクトを作成。Acquia CLIを使わない場合は composer create-project acquia/drupal-recommended-project でも同様のことができる。

$ acli new tmp && cp -r tmp/. . && rm -rf tmp

acquia/drupal-minimal-project is the most minimal application that will run on the Cloud Platform.

 Choose a starting project [acquia/drupal-recommended-project]:
  [0] acquia/drupal-recommended-project
  [1] acquia/drupal-minimal-project

 > 0    # 0番を選択

...省略...

New 💧 Drupal project created in /path/to/ace-povjapan-multisite. 🎉

Acquia BLTをインストールする。BLTは今回マルチサイトの設定の際に利用する。(BLT無くても設定可)

$ rm -rf vendor composer.lock
$ composer require acquia/blt:~12.0 --no-update
$ composer update

次のコマンドでマルチサイトを生成する。このコマンドによって、コードベース上にマルチサイト用のディレクトリを作成したり設定ファイルを追加してくれる。

$ vendor/bin/blt recipes:multisite:init

This will generate a new site in the docroot/sites directory.
 Site machine name (e.g. 'example') site1                                       # docroot/sites下に作成するディレクトリ名を指定
 Local domain name [http://local.site1.com] povjapan-multisite.lndo.site/site1 # ローカル環境のドメイン名を指定
 Would you like to configure the local database credentials? (y/n)              # ローカル環境のデータベースのクレデンシャルを設定するか
 Local database name [site1] database                                           # ローカル環境のデータベース名を指定
 Local database user [site1] mysql                                              # ローカル環境のデータベースのユーザー名を指定
 Local database password [site1] mysql                                          # ローカル環境のデータベースのパスワードを指定
 Local database host [localhost] site1_db                                       # ローカル環境のデータベースのホスト名を指定
 Local database port [3306]                                                     # ローカル環境のデータベースのポート番号を指定
 Default remote drush alias [site1.remote]                                      # リモートのDrushエイリアス名を指定
 Default local drush alias [site1.local]                                        # ローカルのDrushエイリアス名を指定

実行が完了すると、docroot/sites/site1ディレクトリ内に設定ファイル諸々と、drush/sites/site1.site.ymlファイルが作成される。コマンド実行時に入力したデータベースのクレデンシャルはdocroot/sites/site1/settings/local.settings.php に自動的に入力されていることが分かる。

docroot/sites/site1/settings/local.settings.php
/**
 * Database configuration.
 */
$databases['default']['default'] = [
  'database' => $db_name,
  'username' => 'mysql',
  'password' => 'mysql',
  'host' => 'site3_db',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
];

docroot/sites/sites.phpファイルを作成し、次の行を追加する。

docroot/sites/sites.php
<?php
$sites['povjapan-multisite.lndo.site.site1'] = 'site1';

Drushコマンドでサイトをインストールする。

$ lando drush @site1.local site:install standard --locale=ja -y

povjapan-multisite.lndo.site/site1 にアクセスしてDrupalサイトが起動するか確認。

Acquia Cloud Platformにマルチサイトをデプロイする

Acquia Cloud Platformの管理画面にログインして、対象のアプリケーションの画面に移動する。ActionsボタンからAdd Databaseをクリック。

Screen Shot 0004-05-09 at 14.06.23.png

データベース名をsite1と入力して、Dev, Stage, Prodの全環境にデータベースを作成する。

Screen Shot 0004-05-09 at 14.08.35.png

各マルチサイト下のsettings.phpに、Acquia Cloud Platformのデータベースに接続するためのrequirement文を追加する。requirement文はAcquia Cloud Platform管理画面のアプリケーションページ > Dev環境のページ > Database から確認可。

Screen_Shot_0004-05-09_at_14_15_44.png

docroot/sites/site1/settings.php

# データベースの接続情報は、BLTのrequire文よりも前に貼り付ける。
if (file_exists('/var/www/site-php')) {
  require '/var/www/site-php/***/site1-settings.inc';
}

require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";

docroot/sites/sites.phpに、$sites配列にAcquia Cloud Platform環境の値を追加する。

docroot/sites/sites.php
<?php
$sites['povjapan-multisite.lndo.site.site1'] = 'site1'; // local
$sites['***dev.prod.acquia-sites.com.site1'] = 'site1'; // dev
$sites['***stg.prod.acquia-sites.com.site1'] = 'site1'; // stg
$sites['***.prod.acquia-sites.com.site1'] = 'site1'; // prod

docrootディレクトリに移動して、シンボリックリンクを作成する。

$ cd docroot
$ ln -s ../docroot site1

コードベースをコミットしたら、アーティファクトを作成してデプロイする。

$ acli push:artifact

Acquia Cloud PlatformのDev環境にSSH接続して、docroot/sites/site1 ディレクトリに移動してからDrushコマンドにてサイトをインストールする。

$ acli remote:ssh ***.dev

Acquia$ cd /var/www/html/***.dev/docroot/sites/site1
Acquia$ drush site:install standard --locale=ja -y

***dev.prod.acquia-sites.com/site1 にアクセスして、Drupalサイトが閲覧できるか確認。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?