OpenSUSE Leap 42: Drupalをインストールする

コンテンツマネージメントシステムのDrupalをインストールする手順を記載します。

1 Drupalをインストールする

  • httpsからhttpに変えるには、ファイアウォールの許可をapache2-sslからapache2に変更し、VirtualHostの443ポートを80ポートに変更します。
  • MYSQL_PASSWDはMySQLで使うrootユーザのパスワードで、DRUPAL_PASSWDはMySQLで使うdrupal7ユーザのパスワードです。
#!/bin/sh

set -e

[ -z "${MYSQL_PASSWD}" ] && \
  MYSQL_PASSWD=mysql
[ -z "${DRUPAL_PASSWD}" ] && \
  DRUPAL_PASSWD=drupal

opensuse_install_mysql()
{
  sudo zypper -n in mariadb
  sudo systemctl enable mysql
  sudo systemctl start mysql

  cat<<EOF | sudo mysql -u root
create database drupal7 character set utf8 collate utf8_general_ci;
grant all privileges on drupal7.* to drupal7@localhost
   identified by '${DRUPAL_PASSWD}';
exit
EOF
}

opensuse_install_drupal()
{
  O=http://download.opensuse.org
  A=${O}/repositories/server:/php:/applications/openSUSE_Leap_42.2/

  sudo zypper ar -f -n Applications ${A} Applications
  sudo zypper -n --gpg-auto-import-keys ref
  sudo zypper -n in drupal7

  sudo cp /etc/drupal7/default/default.settings.php \
       /etc/drupal7/default/settings.php
  echo "require_once('dbconfig.php');" | \
    sudo tee -a /etc/drupal7/default/settings.php

  cat <<EOF | sudo tee /etc/drupal7/default/dbconfig.php
<?php
\$dbs['mysql'] = array(
                      'driver' => 'mysql',
                      'database' => 'drupal7',
                      'username' => 'drupal7',
                      'password' => '${DRUPAL_PASSWD}',
                      'host' => 'localhost',
                      'port' => '',
                      'prefix' => ''
);
\$databases['default']['default'] = \$dbs['mysql'];
?>
EOF
}

opensuse_install_apache()
{
  sudo zypper -n in apache2
  sudo gensslcert

  sudo cp /etc/apache2/conf.d/drupal7.conf \
       /etc/apache2/conf.d/drupal7.conf.orig

  cat <<EOF | sudo tee /etc/apache2/conf.d/drupal7.conf
<VirtualHost _default_:443>
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl.crt/server.crt
  SSLCertificateKeyFile /etc/apache2/ssl.key/server.key

$(sed -e 's/Order allow,deny/Require all granted/g' \
      -e 's/[^"]Require all denied/#Require all denied/g' \
      -e 's/#Require all granted/Require all granted/g' \
      -e 's/^/  /g' \
      /etc/apache2/conf.d/drupal7.conf.orig)
</VirtualHost>
EOF

  for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 apache2-ssl\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2

  sudo a2enflag SSL
  for mod in ssl php5 rewrite headers; do
    sudo a2enmod ${mod}
  done
  sudo systemctl enable apache2
  sudo systemctl restart apache2
}

opensuse_main()
{
  opensuse_install_mysql
  opensuse_install_drupal
  opensuse_install_apache
}

opensuse_main

2 Drupalへアクセスする

以下のURLにアクセスしてDrupalをセットアップします。

https://<server>/drupal/install.php

セットアップ後は以下のURLにアクセスします。

https://<server>/drupal/