Ubuntu development scripts

Install and configure Apache/PHP/MySQL/phpMyAdmin

[ installandconfigure download ]

This bash script is to be run as root and installs Apache, PHP, MySQL & phpMyAdmin. PHP is configured with E_ALL error reporting and Apache "modrewrite" is enabled. The last step creates a VirtualBox shared folder and configures it in /etc/fstab.

#!/bin/bash

#check if root
	if [ $EUID -ne 0 ]; then
		echo "run with sudo or as root"
		exit
	fi

#install
	echo "installing apache2"
	apt-get -q=2 -y install apache2; 

	echo "installing php5"
	apt-get -q=2 -y install php5;

	echo "installing mysql server"
	apt-get -q=2 -y install mysql-server;

	echo "installing phpmyadmin"
	apt-get -q=2 -y install phpmyadmin;

#configure apps
	echo "configuring php"
	cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
	sed 's/\(error_reporting = *\).*/\1E_ALL/' /etc/php5/apache2/php.ini | sed 's/\(display_errors = *\).*/\1On/' > /etc/php5/apache2/php.ini
	echo "configuring apache"
	a2enmod -q rewrite
	
#configure system
	echo "configuring vbox shared folders"
	mkdir -p /mnt/vbshare
	
	grep "vbshared /mnt/vbshare vboxsf" /etc/fstab > /dev/null
	if [ $? -ne 0 ]; then
		#echo "adding"
		echo "vbshared /mnt/vbshare vboxsf" >> /etc/fstab
	fi

	mount -a
	
	echo "done"

Add a site to apache, configures /etc/hosts

[ addsite download ]

This bash script adds a virtual-host with some default settings to "sites-available", enables the site and adds an entry to /etc/hosts.

#!/bin/bash

SITENAME=$1
SITEPATH=$2
	
#PATH="$HOME/bin:$PATH"
#check if root
	if [ $EUID -ne 0 ]; then
		echo "run with sudo or as root"
		exit
	fi
	
#check for 2 params
	if [ $# != 2 ]; then
		echo "Require 2 arguments"
		echo "usage: addsite sitename /path/to/documentroot"
		exit
	fi

#create config file
	echo "creating config file"
	echo "
	<VirtualHost *:80>
		ServerName $SITENAME

		DocumentRoot $SITEPATH	
		<Directory \"$SITEPATH/\">
			Options Indexes MultiViews
			AllowOverride All	
			Order allow,deny
			Allow from all
		
			php_value date.timezone America/Toronto
		</Directory>	
	</VirtualHost>" > /etc/apache2/sites-available/$SITENAME
	
#enable site
	a2ensite -q $SITENAME

#add to /etc/hosts if not already existing
	echo "adding to /etc/hosts"
	grep "127.0.0.1 $SITENAME" /etc/hosts > /dev/null
	if [ $? -ne 0 ]; then
		#echo "adding"
		echo "127.0.0.1 $SITENAME" >> /etc/hosts
	fi
	mkdir -p $SITEPATH
	
#restart apache
	apache2ctl graceful &>1

echo "done"