Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6483d13

Browse files
committedOct 11, 2016
Allow user to select which port(s) to run Apache on.
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
1 parent 32ba78e commit 6483d13

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed
 

‎README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ Create contained environments within the VM via `init_python_env`
3131

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

4037
## Usage
4138
- 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!
@@ -55,7 +52,6 @@ Create contained environments within the VM via `init_python_env`
5552
- 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`
5653
- 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.`
5754
- don't force any ports for a DBMS'. Let user configure any ports in `config.yml`
58-
- update apache
5955
- update PostgreSQL
6056

6157
##### Bigger To Dos

‎Vagrantfile

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ Vagrant.configure(2) do |config|
140140
sudo chmod a+x /bin/setup_phppgadmin
141141
sudo cp /vagrant/bootstrap/setup_phppgadmin.sh /bin/setup_phppgadmin
142142
sudo sed -i 's/\r//' /bin/setup_phppgadmin
143+
144+
sudo touch /bin/update_apache_ports
145+
sudo chmod a+x /bin/update_apache_ports
146+
sudo cp /vagrant/bootstrap/update_apache_ports.sh /bin/update_apache_ports
147+
sudo sed -i 's/\r//' /bin/update_apache_ports
143148
144149
SHELL
145150

‎bootstrap/setup_phppgadmin.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
source /bin/colors
33
# INSTALL PHPPGADMIN
44
sudo apt-get install phppgadmin -y
5-
# configure Apache server to tell it where to find phppgadmin.
6-
echo 'Include /etc/apache2/conf.d/phppgadmin'| sudo tee --append /etc/apache2/apache2.conf
5+
# configure Apache server to tell it where to find phppgadmin. Only append once.
6+
if ! grep -Fxq "Include /etc/apache2/conf.d/phppgadmin" /etc/apache2/apache2.conf; then
7+
echo 'Include /etc/apache2/conf.d/phppgadmin'| sudo tee --append /etc/apache2/apache2.conf
8+
fi
79
# allow permission to access phppgadmin.
810
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
911
sudo sed -i 's/^#allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
1012
sudo sed -i 's/^# allow from all/allow from all/' /etc/apache2/conf.d/phppgadmin
1113
sudo service apache2 reload
1214
# enable user "postgres" to login
1315
sudo sed -i "s/\s*\$conf\['extra_login_security'\] = true;/ \$conf\['extra_login_security'\] = false;/" /etc/phppgadmin/config.inc.php
14-
# Update port 80 to port 8080
15-
sudo sed -i "s/\<Listen 80\>\s*/Listen 8080/" /etc/apache2/ports.conf
16-
sudo sed -i "s/:80>/:8080>/" /etc/apache2/sites-available/000-default.conf
17-
sudo /etc/init.d/apache2 restart
18-
19-
echo -e ${BGREEN}"phpPgAdmin accessible at: http://localhost:8080/phppgadmin/"${NIL}
16+
# # Update port 80 to port 8080
17+
# sudo sed -i "s/\<Listen 80\>\s*/Listen 8080/" /etc/apache2/ports.conf
18+
# sudo sed -i "s/:80>/:8080>/" /etc/apache2/sites-available/000-default.conf
19+
# sudo /etc/init.d/apache2 restart
20+
update_apache_ports
21+
echo -e ${BGREEN}"phpPgAdmin accessible at: http://localhost:${NIL}[YOUR_APACHE_PORT]${BGREEN}/phppgadmin/"${NIL}

‎bootstrap/update_apache_ports.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
source /bin/colors
3+
4+
function update_apache_ports(){
5+
echo -e "${BWHITE}Update Apache port ${CURRENT_PORT}?${NIL} [press ENTER to skip] : "
6+
read -p "Enter a Port Number to replace ${CURRENT_PORT}: " NEW_PORT
7+
valid='^[0-9]+$'
8+
9+
if [ -z ${NEW_PORT} ]; then
10+
continue
11+
fi
12+
13+
if ! [[ ${NEW_PORT} =~ $valid ]] ; then
14+
echo -e ${BRED}"Error: Please enter a valid value. ${NIL}"
15+
update_apache_ports
16+
else
17+
if [ ! -z ${NEW_PORT} ]; then
18+
sudo sed -i "s/\<Listen ${CURRENT_PORT}\>\s*/Listen ${NEW_PORT}/" /etc/apache2/ports.conf
19+
sudo sed -i "s/:${CURRENT_PORT}>/:${NEW_PORT}>/" /etc/apache2/sites-available/000-default.conf
20+
echo -e "${BGREEN}UPDATED PORT ${CURRENT_PORT} to ${NEW_PORT}!${NIL}"
21+
else
22+
echo -e "${BWHITE}skipped...${NIL}"
23+
fi
24+
fi
25+
}
26+
27+
# RUN THE SCRIPT
28+
# get Listening ports in file.
29+
GET_APACHE_PORTS=$(sudo sed -n '/^Listen [0-9]*/p' /etc/apache2/ports.conf)
30+
# remove "Listen" to create var with only Port #s.
31+
AVAILABLE_PORTS=$(echo $GET_APACHE_PORTS | sed -e 's/\<Listen\>//g')
32+
# store in an array.
33+
AVAILABLE_PORTS_ARRAY=($AVAILABLE_PORTS)
34+
35+
for CURRENT_PORT in "${AVAILABLE_PORTS_ARRAY[@]}"
36+
do
37+
update_apache_ports
38+
done
39+
# restart Apache to listen to new ports.
40+
sudo /etc/init.d/apache2 restart

0 commit comments

Comments
 (0)
Please sign in to comment.