Skip to content

Instantly share code, notes, and snippets.

@alexanno
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanno/459011bb84e9a48d2985 to your computer and use it in GitHub Desktop.
Save alexanno/459011bb84e9a48d2985 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
COLOR="\033[;35m"
COLOR_RST="\033[0m"
sudo apt-get update
sudo apt-get -y install python-software-properties build-essential curl
echo -e "${COLOR}--- Installing PHP5 ---${COLOR_RST}"
sudo apt-get install -y php5 php5-curl php5-pgsql
sudo apt-get install -y libapache2-mod-php5
sudo service apache2 restart
sudo ln -s /vagrant/ /var/www/vagrant
echo -e "${COLOR}--- Installing PostgreSQL ---${COLOR_RST}"
sudo touch /etc/apt/sources.list.d/pgdg.list
sudo chmod 777 /etc/apt/sources.list.d/pgdg.list
sudo echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
# Edit the following to change the name of the database user that will be created:
APP_DB_USER=sandkasse
APP_DB_PASS=sandkasse123
# Edit the following to change the name of the database that is created (defaults to the user name)
APP_DB_NAME=$APP_DB_USER
# Edit the following to change the version of PostgreSQL that is installed
PG_VERSION=9.4
POSTGIS_VERSION=2.1
export DEBIAN_FRONTEND=noninteractive
apt-get -y install "postgresql-$PG_VERSION" "postgresql-$PG_VERSION-postgis-$POSTGIS_VERSION" "postgresql-contrib-$PG_VERSION"
PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
PG_DIR="/var/lib/postgresql/$PG_VERSION/main"
# Edit postgresql.conf to change listen address to '*':
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
# Append to pg_hba.conf to add password auth:
echo "host all all all md5" >> "$PG_HBA"
# Restart so that all new config is loaded:
service postgresql restart
cat << EOF | su - postgres -c psql
-- Create the database user:
CREATE USER $APP_DB_USER WITH SUPERUSER PASSWORD '$APP_DB_PASS';
-- Create the database:
CREATE DATABASE $APP_DB_NAME WITH OWNER $APP_DB_USER;
CREATE SCHEMA $APP_DB_NAME;
CREATE extension postgis;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment