Skip to content

Commit

Permalink
Allow user to select which port(s) to run Apache on.
Browse files Browse the repository at this point in the history
Loops through "Listen"s in /etc/apache2/ports.conf and let's user
configure each available port.
Also update VirtualHosts /etc/apache2/sites-available/000-default.conf
  • Loading branch information
ccurtin committed Oct 11, 2016
1 parent 32ba78e commit 6483d13
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ Create contained environments within the VM via `init_python_env`

#### PostgreSQL Notes
- Defaults to latest stable version PostgreSQL
- Default settings run Apache on port 8080, needed for phpPgAdmin web interface.
- To change the port(s) Apache runs on edit the following:
- `sudo vim /etc/apache2/ports.conf`
- `sudo vim /etc/apache2/sites-available/000-default.conf`
- Then restart Apache `sudo /etc/init.d/apache2 restart`
- Apache is required for phpPgAdmin web interface.
- To change the port(s) Apache runs on, run the command `update_apache_ports`

## Usage
- VirtualEnv is _not_ a VM container, it is simply to create self-contained python environments. Think of it as a sandbox, not a full fledged VM. Plus, we already have the VM!
Expand All @@ -55,7 +52,6 @@ Create contained environments within the VM via `init_python_env`
- in `manage_django_db_postgres` when installing psycopg2, need to first automatically install the _correct_ version of the `python-dev` package. Note to self: grab `which python` and loop through versions, popping off version number until match is met. Use method `check_package`
- when selecting a DBMS for project, also accept a DBMS version number for each. eg: `"Select which engine you'd like to use: 1,2,4,5,6"; user selects #1 postgresql and then prompt them for version to install; create warnings if DMBS already installed.`
- don't force any ports for a DBMS'. Let user configure any ports in `config.yml`
- update apache
- update PostgreSQL

##### Bigger To Dos
Expand Down
5 changes: 5 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ Vagrant.configure(2) do |config|
sudo chmod a+x /bin/setup_phppgadmin
sudo cp /vagrant/bootstrap/setup_phppgadmin.sh /bin/setup_phppgadmin
sudo sed -i 's/\r//' /bin/setup_phppgadmin
sudo touch /bin/update_apache_ports
sudo chmod a+x /bin/update_apache_ports
sudo cp /vagrant/bootstrap/update_apache_ports.sh /bin/update_apache_ports
sudo sed -i 's/\r//' /bin/update_apache_ports
SHELL

Expand Down
18 changes: 10 additions & 8 deletions bootstrap/setup_phppgadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
source /bin/colors
# INSTALL PHPPGADMIN
sudo apt-get install phppgadmin -y
# configure Apache server to tell it where to find phppgadmin.
echo 'Include /etc/apache2/conf.d/phppgadmin'| sudo tee --append /etc/apache2/apache2.conf
# configure Apache server to tell it where to find phppgadmin. Only append once.
if ! grep -Fxq "Include /etc/apache2/conf.d/phppgadmin" /etc/apache2/apache2.conf; then
echo 'Include /etc/apache2/conf.d/phppgadmin'| sudo tee --append /etc/apache2/apache2.conf
fi
# allow permission to access phppgadmin.
sudo sed -i 's/^allow from 127.0.0.0\/255.0.0.0 ::1\/128/# allow from 127.0.0.0\/255.0.0.0 ::1\/128/' /etc/apache2/conf.d/phppgadmin
sudo sed -i 's/^#allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
sudo sed -i 's/^# allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
sudo service apache2 reload
# enable user "postgres" to login
sudo sed -i "s/\s*\$conf\['extra_login_security'\] = true;/ \$conf\['extra_login_security'\] = false;/" /etc/phppgadmin/config.inc.php
# Update port 80 to port 8080
sudo sed -i "s/\<Listen 80\>\s*/Listen 8080/" /etc/apache2/ports.conf
sudo sed -i "s/:80>/:8080>/" /etc/apache2/sites-available/000-default.conf
sudo /etc/init.d/apache2 restart

echo -e ${BGREEN}"phpPgAdmin accessible at: http://localhost:8080/phppgadmin/"${NIL}
# # Update port 80 to port 8080
# sudo sed -i "s/\<Listen 80\>\s*/Listen 8080/" /etc/apache2/ports.conf
# sudo sed -i "s/:80>/:8080>/" /etc/apache2/sites-available/000-default.conf
# sudo /etc/init.d/apache2 restart
update_apache_ports
echo -e ${BGREEN}"phpPgAdmin accessible at: http://localhost:${NIL}[YOUR_APACHE_PORT]${BGREEN}/phppgadmin/"${NIL}
40 changes: 40 additions & 0 deletions bootstrap/update_apache_ports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
source /bin/colors

function update_apache_ports(){
echo -e "${BWHITE}Update Apache port ${CURRENT_PORT}?${NIL} [press ENTER to skip] : "
read -p "Enter a Port Number to replace ${CURRENT_PORT}: " NEW_PORT
valid='^[0-9]+$'

if [ -z ${NEW_PORT} ]; then
continue
fi

if ! [[ ${NEW_PORT} =~ $valid ]] ; then
echo -e ${BRED}"Error: Please enter a valid value. ${NIL}"
update_apache_ports
else
if [ ! -z ${NEW_PORT} ]; then
sudo sed -i "s/\<Listen ${CURRENT_PORT}\>\s*/Listen ${NEW_PORT}/" /etc/apache2/ports.conf
sudo sed -i "s/:${CURRENT_PORT}>/:${NEW_PORT}>/" /etc/apache2/sites-available/000-default.conf
echo -e "${BGREEN}UPDATED PORT ${CURRENT_PORT} to ${NEW_PORT}!${NIL}"
else
echo -e "${BWHITE}skipped...${NIL}"
fi
fi
}

# RUN THE SCRIPT
# get Listening ports in file.
GET_APACHE_PORTS=$(sudo sed -n '/^Listen [0-9]*/p' /etc/apache2/ports.conf)
# remove "Listen" to create var with only Port #s.
AVAILABLE_PORTS=$(echo $GET_APACHE_PORTS | sed -e 's/\<Listen\>//g')
# store in an array.
AVAILABLE_PORTS_ARRAY=($AVAILABLE_PORTS)

for CURRENT_PORT in "${AVAILABLE_PORTS_ARRAY[@]}"
do
update_apache_ports
done
# restart Apache to listen to new ports.
sudo /etc/init.d/apache2 restart

0 comments on commit 6483d13

Please sign in to comment.