CentOS 7: Install Drupal

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 https to http in firewall-cmd's service argument.
  • 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

centos_install_mysql()
{
  sudo yum install -y mariadb-server php-mysqlnd
  sudo systemctl enable mariadb
  sudo systemctl start mariadb

  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
}

centos_install_drupal()
{
  sudo yum install -y epel-release
  sudo yum install -y 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
}

centos_install_apache()
{
  sudo yum install -y mod_ssl

  sudo sed -e 's/Require local/Require all granted/g' \
       -i /etc/httpd/conf.d/drupal7.conf

  sudo firewall-cmd --add-service=https --permanent
  sudo firewall-cmd --reload
  sudo systemctl enable httpd
  sudo systemctl restart httpd
}

centos_main()
{
  centos_install_mysql
  centos_install_drupal
  centos_install_apache
}

centos_main

2 Access to Drupal

Access to the following URL and setup Drupal.

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

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

https://<server>/drupal7/