OpenSUSE Leap 42: Install Drupal

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

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 Access to Drupal

Access to the following URL and setup Drupal.

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

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

https://<server>/drupal/