Skip to content

Instantly share code, notes, and snippets.

@david-hammond
Last active May 20, 2021 03:47
Show Gist options
  • Save david-hammond/c6ce56cb4759066ff4938be385ef238d to your computer and use it in GitHub Desktop.
Save david-hammond/c6ce56cb4759066ff4938be385ef238d to your computer and use it in GitHub Desktop.
base database server setup
#!/bin/bash
sudo apt update
sudo apt upgrade -y
sudo apt install postgresql postgresql-contrib -y
#To allow database to be accessed remotely follow this https://linuxize.com/post/how-to-install-postgresql-on-ubuntu-18-04/
#you need to edit the follwoing 2 files using vim - the most difficult part, vim instructions here https://vim.rtorr.com/
#sudo vim /etc/postgresql/10/main/postgresql.conf
sudo sed -i s/"#listen_addresses = 'localhost'"/"listen_addresses = '*' "/g /etc/postgresql/12/main/postgresql.conf
#sudo vim /etc/postgresql/10/main/pg_hba.conf
sudo sed -i '96s@127.0.0.1/32@0.0.0.0/0@' /etc/postgresql/12/main/pg_hba.conf
sudo service postgresql restart
#follow instructions here to set up password
#sudo su - postgres -c "createuser guest"
#sudo -u postgres psql -c "alter user guest with encrypted password 'guest';"
#sudo -u postgres psql -c "GRANT CONNECT ON DATABASE postgres TO guest;"
#sudo -u postgres psql -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO guest;"
#sudo -u postgres psql -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO guest;"
sudo su - postgres -c "createuser admin"
sudo -u postgres psql -c "alter user admin with encrypted password 'admin';"
sudo -u postgres psql -c "ALTER USER admin WITH SUPERUSER;"
sudo apt install postgis postgresql-12-postgis-3
sudo su - postgres -c "createdb postgis_db -O admin"
sudo -u postgres psql -c "CREATE EXTENSION postgis;"
sudo -u postgres psql -c "CREATE EXTENSION postgis_raster;"
#setup apache and RStudio
sudo apt update
sudo apt upgrade
sudo apt install apache2 -y
sudo ufw allow 'Apache'
sudo apt install git r-base gdebi-core libcurl4-openssl-dev libssl-dev libxml2-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev -y
wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.4.1106-amd64.deb
sudo gdebi rstudio-server-1.4.1106-amd64.deb
sudo su - -c "R -e \"install.packages(c('devtools', 'tidyverse', 'ProjectTemplate', 'rio'), repos='http://cran.rstudio.com/')\""
sudo chmod 777 /var/www/html
mkdir /var/www/html/public_html
#samba share = https://linuxconfig.org/how-to-configure-samba-server-share-on-ubuntu-20-04-focal-fossa-linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment