Installing Acquia Drupal on RedHat Enterprise Linux

The following is a two part script to configure RedHat Enterprise Linux for Drupal, and then create a Drupal site using the Acquia distribution. The script is not fully automated and will require some user interaction. Please note that the site should be registered in DNS to be accessible.

Part 1: Configure the Server

#
# Configure RedHat Server
#

# register server on RedHat Network
#
rhn_register

# remove unnecessery software
#
yum -y erase xinetd OpenIPMI
yum -y erase portmap nfs-utils yp-tools ypbind
yum -y erase wpa_supplicant NetworkManager NetworkManager-glib

# update yum and install apache, mysql, php
#
yum update
yum -y install httpd mod_ssl mysql mysql-server php php-mysql php-mbstring php-gd php-ldap php-xml

# upgrade to php 5.2
#
wget http://dev.centos.org/centos/5/CentOS-Testing.repo -O /etc/yum.repos.d/CentOS-Testing.repo
sed -i 's/$releasever/5/' /etc/yum.repos.d/CentOS-Testing.repo
yum -y --enablerepo=c5-testing update php*

# enable daemons
#
/sbin/chkconfig httpd on
/sbin/chkconfig mysqld on

# start and configure mysql
#
service mysqld start
/usr/bin/mysql_secure_installation

# configure apache
#
sed -i '/NameVirtualHost/s/^#//' /etc/httpd/conf/httpd.conf

#
# configure php
sed -i '/^memory_limit/s/32/128/' /etc/php.ini

# configure firewall
# 
# accept incoming for http and https
sed -i '/REJECT/ i\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' /etc/sysconfig/iptables 
sed -i '/REJECT/ i\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT' /etc/sysconfig/iptables 
# remove incoming ipp
sed -i '/--dport 631/s/^/# /' /etc/sysconfig/iptables
service iptables restart

Part 2: Create a Site

SITENAME="dev"
DOMAINNAME="example.com"
ACQUIAPATH="http://acquia.com/files/downloads/acquia-drupal-1.2.21.5181.tar.gz"
SITEDBNAME="devdb"
SITEDBUSER="dbuser"
SITEDBPASS="dbpassword123"

#
# Create acquia site
#

# add a site user
#
/usr/sbin/useradd $SITENAME
chmod o+rx /home/$SITENAME

# create /etc/hosts entry
#
echo "127.0.0.1 $SITENAME.$DOMAINNAME $SITENAME" >> /etc/hosts

# create apache virtual host file
#
cat > /etc/httpd/conf.d/vhost-$SITENAME.conf <<End-of-Block
<VirtualHost *:80>
	ServerName $SITENAME.$DOMAINNAME
	DocumentRoot /home/$SITENAME/public_html
	RewriteEngine On  
	RewriteOptions inherit
	ErrorLog logs/vhost-$SITENAME-error.log  
	CustomLog logs/vhost-$SITENAME-access.log common
	<Directory /home/$SITENAME/public_html>
		AllowOverride All
	</Directory>
</VirtualHost>
End-of-Block

# install acquia
#
curl $ACQUIAPATH | tar xzv -C /home/$SITENAME/public_html --strip-components=1
sed -i "/^\$db_url/s/username:password@localhost\/databasename/$SITEDBUSER:$SITEDBPASS@localhost\/$SITEDBNAME/" /home/$SITENAME/public_html/sites/default/settings.php
# Note: if acquia, files folder already exists; if drupal, create a new one
chmod 777 /home/$SITENAME/public_html/sites/default/files 

# create mysql databases
#
mysql -u root -p <<End-of-Block
CREATE DATABASE $SITEDBNAME;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON $SITEDBNAME.* to '$SITEDBUSER'@'localhost' IDENTIFIED BY '$SITEDBPASS';
FLUSH PRIVILEGES;
End-of-Block

# restart apache
#
service httpd restart

Part 3: Additional Info