OpenSUSE Leap 15: Install Drupal for CMS

This article will describe installing Drupal which is a content management system.

1 Install Drupal

  • Changing open port of firewall from apache2-ssl to apache2 and port of VirtualHost from 443 to 80, you can connect via http.
  • MYSQL_PASSWD is password of root user in MySQL and DRUPAL_PASSWD is password of drupal7 user in MySQL.
#!/bin/sh -e


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

mysql_install()
{
  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
}

drupal_install()
{
  O=http://download.opensuse.org
  A=${O}/repositories/server:/php:/applications/openSUSE_Leap_15.0/

  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
}

apache_install()
{
  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/$(hostname -f)-server.crt
  SSLCertificateKeyFile /etc/apache2/ssl.key/$(hostname -f)-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

  sudo firewall-cmd --add-service=https --permanent
  sudo firewall-cmd --reload

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

drupal_main()
{
  mysql_install
  drupal_install
  apache_install
}

drupal_main

2 Access to Drupal

Access to the following URL and setup Drupal.

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

0001_DrupalInstall.png

After setup, access to the following URL and Drupal is displayed.

https://<server>/drupal/

0002_Drupal.png