Permalink
Browse files

Restructure of Provisioning Script & Improvements

* Separated the different sections of the provisioning script into different functions.
* Apache is now set to run as the vagrant user to reduce file permission errors.
* `htdocs` has been renamed `src` to better fit a web application project.
* The default webroot and virtual host are no long used, in favor of a new vhost config which points to the /vagrant/src
* mod_rewrite is enabled by default.
* Override all is now enabled by default.
  • Loading branch information...
mattandersen committed Jul 18, 2015
1 parent 3719e67 commit 9b381a46ae0988909bc38ccaff8e28573bc7bc35
Showing with 88 additions and 37 deletions.
  1. +0 −2 Vagrantfile
  2. +88 −35 provision.sh
  3. 0 {htdocs → src}/index.php
View
@@ -11,8 +11,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network "forwarded_port", guest: 80, host: 8888
config.vm.network "forwarded_port", guest: 3306, host: 8889
config.vm.synced_folder "htdocs", "/var/www/html"
config.vm.provision "shell", path: "provision.sh"
# config.vm.provider "virtualbox" do |vb|
View
@@ -1,65 +1,118 @@
#!/bin/bash
apache_config_file="/etc/apache2/envvars"
apache_vhost_file="/etc/apache2/sites-available/vagrant_vhost.conf"
php_config_file="/etc/php5/apache2/php.ini"
xdebug_config_file="/etc/php5/mods-available/xdebug.ini"
mysql_config_file="/etc/mysql/my.cnf"
default_apache_index="/var/www/html/index.html"
# This function is called at the very bottom of the file
main() {
update_go
# Update the server
apt-get update
apt-get -y upgrade
if [[ -e /var/lock/vagrant-provision ]]; then
exit;
fi
if [[ -e /var/lock/vagrant-provision ]]; then
cat 1>&2 << EOD
################################################################################
# Everything below this line should only need to be done once
# To re-run full provisioning, delete /var/lock/vagrant-provision and run
#
# $ vagrant provision
#
# From the host machine
################################################################################
EOD
exit
fi
network_go
tools_go
apache_go
php_go
mysql_go
touch /var/lock/vagrant-provision
}
update_go() {
# Update the server
apt-get update
apt-get -y upgrade
}
network_go() {
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')
sed -i "s/^${IPADDR}.*//" /etc/hosts
echo ${IPADDR} ubuntu.localhost >> /etc/hosts # Just to quiet down some error messages
}
tools_go() {
# Install basic tools
apt-get -y install build-essential binutils-doc git
}
apache_go() {
# Install Apache
apt-get -y install apache2
sed -i "s/^\(.*\)www-data/\1vagrant/g" ${apache_config_file}
chown -R vagrant:vagrant /var/log/apache2
cat << EOF > ${apache_vhost_file}
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /vagrant/src
LogLevel debug
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
<Directory /vagrant/src>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')
sed -i "s/^${IPADDR}.*//" /etc/hosts
echo $IPADDR ubuntu.localhost >> /etc/hosts # Just to quiet down some error messages
a2dissite 000-default
a2ensite vagrant_vhost
# Install basic tools
apt-get -y install build-essential binutils-doc git
a2enmod rewrite
# Install Apache
apt-get -y install apache2
apt-get -y install php5 php5-curl php5-mysql php5-sqlite php5-xdebug
service apache2 reload
update-rc.d apache2 enable
}
sed -i "s/display_startup_errors = Off/display_startup_errors = On/g" ${php_config_file}
sed -i "s/display_errors = Off/display_errors = On/g" ${php_config_file}
php_go() {
apt-get -y install php5 php5-curl php5-mysql php5-sqlite php5-xdebug
cat << EOF > ${xdebug_config_file}
sed -i "s/display_startup_errors = Off/display_startup_errors = On/g" ${php_config_file}
sed -i "s/display_errors = Off/display_errors = On/g" ${php_config_file}
cat << EOF > ${xdebug_config_file}
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_host=10.0.2.2
EOF
service apache2 reload
}
# Install MySQL
echo "mysql-server mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-client mysql-server
sed -i "s/bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" ${mysql_config_file}
mysql_go() {
# Install MySQL
echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
apt-get -y install mysql-client mysql-server
# Allow root access from any host
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION" | mysql -u root --password=root
echo "GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION" | mysql -u root --password=root
sed -i "s/bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" ${mysql_config_file}
# Restart Services
service apache2 restart
service mysql restart
# Allow root access from any host
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION" | mysql -u root --password=root
echo "GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION" | mysql -u root --password=root
# Cleanup the default HTML file created by Apache
rm /var/www/html/index.html
service mysql restart
update-rc.d apache2 enable
}
touch /var/lock/vagrant-provision
main
exit 0
File renamed without changes.

0 comments on commit 9b381a4

Please sign in to comment.