ElementaryOS 0.4: Install Drupal for CMS

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

1 Install Drupal

  • This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
  • If you use http instead of https, change 443 to 80 and delete SSLXXX directive in /etc/apache2/sites-available/drupal.conf.
  • MYSQL_PASSWD is password of root user in MySQL and DRUPAL_PASSWD is password of drupal7 user in MySQL.
#!/bin/sh

set -e

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

drupal_install_postfix()
{
  cat <<EOF | sudo debconf-set-selections
postfix postfix/main_mailer_type select No configuration
EOF
  sudo apt install -y postfix

  cat <<EOF | sudo tee /etc/postfix/main.cf
compatibility_level = 2
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix/sbin
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = localhost
inet_interfaces = all
mydestination = localhost
local_recipient_maps = unix:passwd.byname \$alias_maps
unknown_local_recipient_reject_code = 550
mynetworks_style = subnet
mynetworks = 127.0.0.0/8
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
smtpd_banner = \$myhostname ESMTP \$mail_name (Ubuntu)
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd \$daemon_directory/\$process_name \$process_id & sleep 5
sendmail_path = /usr/sbin/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
inet_protocols = ipv4
EOF

  sudo newaliases
  sudo systemctl enable postfix
  sudo systemctl restart postfix
}

drupal_install_mysql()
{
  cat <<EOF | sudo debconf-set-selections
mysql-server-${MYSQL_VERSION} mysql-server/root_password password ${MYSQL_PASSWD}
mysql-server-${MYSQL_VERSION} mysql-server/root_password_again password ${MYSQL_PASSWD}
EOF
  sudo apt install -y mysql-server
}

drupal_install_drupal()
{
  cat <<EOF | sudo debconf-set-selections
drupal7 drupal7/dbconfig-install boolean true
drupal7 drupal7/mysql/admin-pass password ${MYSQL_PASSWD}
drupal7 drupal7/password-confirm password ${MYSQL_PASSWD}
drupal7 drupal7/mysql/app-pass password ${DRUPAL_PASSWD}
drupal7 drupal7/app-password-confirm password ${DRUPAL_PASSWD}
EOF
  sudo apt install -y drupal7
}

drupal_install_apache()
{
  sudo apt install -y apache2 libapache2-mod-php

  sudo mv /etc/apache2/conf-available/drupal7.conf \
       /etc/apache2/conf-available/drupal7.conf.orig
  cat <<EOF | sudo tee /etc/apache2/conf-available/drupal7.conf
<VirtualHost _default_:443>
  SSLEngine on
  SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

$(sed -e 's/^/  /g' /etc/apache2/conf-available/drupal7.conf.orig)
</VirtualHost>
EOF

  sudo a2enmod php7.0
  sudo a2enmod ssl
  sudo a2enconf drupal7
  sudo systemctl enable apache2
  sudo systemctl restart apache2
}

drupal_main()
{
  drupal_install_postfix
  drupal_install_mysql
  drupal_install_drupal
  drupal_install_apache
}

drupal_main

2 Access to Drupal

Access to the following URL and setup Drupal. Accept this page's certification to browser.

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

0001_DrupalInstall.png

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

https://<server>/drupal7/

0002_Drupal.png