Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccabanero/6471878 to your computer and use it in GitHub Desktop.
Save ccabanero/6471878 to your computer and use it in GitHub Desktop.
AWS - Notes for installing Apache - PostgreSQL - PostGIS - PHP (LAPPP) on an AWS EC2 Ubuntu 12.04.2 Server for development.
-------------------------------------------------------------------------------------------------------------------------------
DESCRIPTION:
Notes for installing Apache - PostgreSQL - PostGIS - PHP (LAPPP) on an AWS EC2 Ubuntu 16.x Server for development.
-------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------
PART 1: Stand Up an Ubuntu 16.x server on AWS EC2
---------------------------------------------------------
1. Below are notes for creating a new Ubuntu EC2 server with an Elastic IP
In the AWS EC2 console, choose 'Launch Instance'
Choose Ubuntu Server 12.04.2 LTS
Instance Details:
Number of Instances: 1
Instance Type: T1 Micro (t1.micro, 613 MB)
Launch Instance: (default)
RAM Disk ID: (default)
Monitoring: (default)
0 EBS Volumes: (default)
Key: Name | Value: TileStream-Ubuntu
Create a new Key Pair
Download the key pair - this file will be used each time we connect to this server
Create a Security Group with Inbound Rules
SSH - 22 (needed for connecting to server via SSH)
HTTP - 80
Postgres - 5432
Issue an Elastic IP
Go to EC2 --> Network & Security --> Elastic IPs --> Allocate New Address
Right-click on the IP address and associated with your Ubuntu server
2. Connecting to your Ubuntu Server using Mac OSX Terminal as an SSH client
Open Mac OSX Terminal
cd to the location of your .pem file
In Terminal ...
chmod 400 [name of pem file]
ssh -i [name of your pem flie].pem ubuntu@[your elastic ip]
for example: ssh -i tileStream.pem ubuntu@1.2.3.4
----------------------------------------------------------
PART 2: Install Apache
----------------------------------------------------------
1. Update Ubuntu
In Terminal ...
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
2. Install Apache Web Server
In Terminal ...
sudo apt-get install apache2
3. Confirm the web server is working properly
Open a web browser and go to your URL … http://[your elastic ip]
You will see the response 'It works!'
4. Upload your web app
a. SSH connect to EC2 and create a target directory.
ssh -i my.pem ubuntu@1.2.3.4
mkdir site
cmd + d
b. SCP files from Mac to EC2 server
cd to directory with .pem file
scp -i my.pem ~/webapp/dist/* ubuntu@1.2.3.4:~/site
c. SSH connect to EC2 and move from site folder to html folder
ssh -i my.pen ubuntu@1.2.3.4
rsync -r site/ /var/www/html
Open a web browser and go to your URL … http://[your elastic ip]/[your web folder]/[your html file].html
----------------------------------------------------------
PART 3: Install Postgres and Postgis
----------------------------------------------------------
1. Install Postgres with Postgis
Connect to your EC2 server. In Terminal …
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install postgresql-9.1-postgis
Set the postgres user password. In Terminal …
sudo passwd postgres
[enter new password]
[retype new password]
You will be informed that the password was successfully updated. In Terminal ...
Setting the postgres password via psql. In Terminal ...
sudo -s -u postgres
psql
\password postgres
<Enter new password:>
<Enter it again:>
\q
2. Update the postgresql.conf file
In Terminal ...
cd /etc/postgresql/9.1/main
sudo vim postgresql.conf
Uncomment #listen_address ...
Move cursor over #listen_addresses
Shift + I (i.e. insert)
Move cursor and delete '#' and enter '*' in place of 'localhost'
To get out of insert mode hit 'esc'
Save changes. In Terminal …
:w
Hit [Enter]
Exit vim. In Terminal …
:x
Hit [Enter]
3. Update the pg_hba.conf file
In Terminal …
sudo vim pg_hba.conf
Change the entry for # IPv4 local connections appropriately:
For example: host all all 0.0.0.0/0 md5
4. Restart postgres
In Terminal …
cd ~
sudo /etc/init.d/postgresql restart
5 On your workstation, assuming you have a pgAdmin client, connect to your database. Note the Security Group you used on your EC2 server should have port 5432 open (default port for Postgres).
----------------------------------------------------------
PART 4: Install PHP
----------------------------------------------------------
1. Install PHP.
In Terminal ...
sudo apt-get install php5-pgsql
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
2. Upload a test .php file to confirm all is working properly.
@simondedjo
Copy link

simondedjo commented Dec 7, 2016

Hi ccabanero,
Thank you for the set-up code. I am having trouble on Part 2: 4 when accessing the test.html in the browser.
I got:
Not Found

The requested URL /test/test.html was not found on this server.

Apache/2.4.18 (Ubuntu) Server at ec2-35-165-79-192.us-west-2.compute.amazonaws.com Port 80

Can you please help ?

@ccabanero
Copy link
Author

@simondedjo - I just updated part 2 - hopefully you already figured this out!!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment