Automated Scripted Install for Drupal on CentOS7/RHEL7 Linux

To get an instance of Drupal running on a fresh and minimal install of CentOS7/RHEL7 is the goal. Here is an automated scripted install for Drupal on CentOS7/RHEL7 Linux. It is not all inclusive. It doesn’t take into accounts a MariaDB password or MariaDB hardening. Just a quick script to get things running rather quickly, preferably on a development environment. This script into account the changes to the services unique to the CentOS7 vs. CentOS6.

#!/bin/bash

#
# Description: This script will download, configure and install Drupal for CentOS/RHEL 7.x Linux.
#

set -e

# Install Pre-requisites
yum -y install mariadb-server httpd php php-mysql php-mbstring php-gd php-xml php-pear

# Clean URLS pre-requisite
sed -i '/<Directory "\/var\/www\/html">/,/<\/Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf

# Start Services
systemctl enable --now mariadb httpd

# MySQL Consider changing values from drupaldb, drupaluser, and password
mysql -e "CREATE DATABASE drupaldb CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -e "CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'password';"
mysql -e "GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"

# Download and install Drupal
cd /var/www/html
curl -O http://ftp.drupal.org/files/projects/drupal-7.39.tar.gz
tar --strip-components=1 -zxvf drupal-7.39.tar.gz
/bin/rm drupal-7.39.tar.gz

# Drupal Configuration
cd /var/www/html/sites/default/
cp default.settings.php settings.php

# Drupal Permissions and Context
chown -R apache:apache /var/www/html
chcon -R -t httpd_sys_rw_content_t /var/www/html/sites/

# Ready for the world. Open firewall ports
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

# Install Drush
pear channel-discover pear.drush.org
pear install drush/drush
drupal-first-site

Source(s)

  • https://www.rosehosting.com/blog/how-to-install-drupal-on-centosfedora/
  • https://www.drupal.org/project/drupal
  • https://www.drupal.org/documentation/install/download#drush
  • https://www.digitalocean.com/community/tutorials/how-to-install-drupal-on-a-virtual-server-running-centos-6–2
  • https://www.rosehosting.com/blog/how-to-install-drupal-7-on-centos-7-with-nginx-mariadb-and-php-fpm/
  • https://www.drupal.org/node/2132447
  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-SELinux_Contexts_Labeling_Files-Persistent_Changes_semanage_fcontext.html
  • https://www.howtoforge.com/centos-7-drupal-installation