Part of Udacity's Full Stack Web Developer Course
- Public IP: 13.127.198.27
- Port: 2200
- http://13.127.198.27/
- http://ec2-13-127-198-27.ap-south-1.compute.amazonaws.com/
- http://13.127.198.27.xip.io (This DNS name is required to add oauth to our application since google cannot accept IP address only for authentication. Visit this link for more info about xip.io)
To complete this project, you'll need a Linux server instance. We recommend using Amazon Lightsail for this. If you don't already have an Amazon Web Services account, you'll need to set one up. Once you've done that, here are the steps to complete this project.
- Login into Amazon Lightsail
- Once you are login into the site, click
Create instance
. - Choose
Linux/Unix
platform,OS Only
andUbuntu 16.04 LTS
. - Click the
Create
button to create the instance. - Wait for the instance to start up.
- Download private key from the SSH keys section in the Account section on Amazon Lightsail.
- Create a new file named lightsail_key.rsa under ~/.ssh folder on your local machine
- Copy and paste content from downloaded private key file to lightsail_key.rsa
- Set file permission as owner only :
$ chmod 600 ~/.ssh/lightsail_key.rsa
- SSH into the instance:
$ ssh -i ~/.ssh/lightsail_key.rsa ubuntu@13.127.198.27
- Run
sudo apt-get update
to update packages - Run
sudo apt-get upgrade
to install new versions of packages - check for future updates:
sudo apt-get dist-upgrade
- Run
sudo nano /etc/ssh/sshd_config
to edit the mentioned file - Change the port number from
22
to2200
. - Restart SSH:
sudo service ssh restart
.
- Run
$ sudo ufw status
to check firewall status - Run
$ sudo ufw default deny incoming
to set default firewall to deny all incomings - Run
$ sudo ufw default allow outgoing
to set default firewall to allow all outgoings - Run
$ sudo ufw allow 2200/tcp
to allow incoming TCP packets on port 2200 - Run
$ sudo ufw allow www
to allow incoming TCP packets on port 80 - Run
$ sudo ufw allow 123/udp
to allow incoming UDP packets on port 123 - Run
$ sudo ufw deny 22
to close port 22 - Run
$ sudo ufw enable
to enable firewall - Run
$ sudo ufw status
to check current firewall status - Update the firewall configuration on Amazon Lightsail website under Networking. Delete default SSH port 22 and add port 80, 123, 2200
- Open a new terminal and you can now ssh in via the new port 2200:
$ ssh -i ~/.ssh/lightsail_key.rsa ubuntu@13.127.198.27 -p 2200
- login as
ubuntu
, add user:sudo adduser grader
.
- Edits the sudoers file:
sudo visudo
. - add below line after 'root ALL=(ALL:ALL) ALL'
grader ALL=(ALL:ALL) ALL
- save the file and exit
- Run
ssh-keygen
on the local machine: - Enter file in which to save the key in the local directory
~/.ssh
.Two files will be generated (~/.ssh/grader_key
and~/.ssh/grader_key.pub
) - Run
cat ~/.ssh/grader_key.pub
and copy the contents of the file - Log in to the grader's virtual machine
- Create a new directory called
~/.ssh
(mkdir .ssh
) on the grader's virtual machine - Run
sudo nano ~/.ssh/authorized_keys
and paste the content into this file, save and exit - Give the permissions:
chmod 700 .ssh
andchmod 644 .ssh/authorized_keys
- Check in
/etc/ssh/sshd_config
file ifPasswordAuthentication
is set tono
- Restart SSH:
sudo service ssh restart
- On the local machine, run:
ssh -i ~/.ssh/grader_key -p 2200 grader@13.127.198.27
.
- Run
$ sudo dpkg-reconfigure tzdata
- Install Apache:
$ sudo apt-get install apache2
- Go to http://13.127.198.27/, if Apache is working correctly, a Apache2 Ubuntu Default Page will show up
- Install the mod_wsgi package:
$ sudo apt-get install libapache2-mod-wsgi python-dev
- Enable mod_wsgi:
$ sudo a2enmod wsgi
- Restart Apache:
$ sudo service apache2 restart
-
login as
grader
, Runsudo apt-get install postgresql
to install postgresql -
PostgreSQL should not allow remote connections. In the
/etc/postgresql/9.5/main/pg_hba.conf
file, you should see:local all postgres peer local all all peer host all all 127.0.0.1/32 md5 host all all ::1/128 md5
-
run
sudo su - postgres
-
Open PostgreSQL interactive terminal with
psql
-
Create the
catalog
user with a password and give them the ability to create databases:postgres=# CREATE ROLE catalog WITH LOGIN PASSWORD 'catalog'; postgres=# ALTER ROLE catalog CREATEDB;
-
Exit psql using
\q
. -
Switch back to the
grader
user:exit
. -
login as grader and create a new Linux user called
catalog
:sudo adduser catalog
-
Give to
catalog
user the permission to sudo. Run:sudo visudo
. -
add below line under
root ALL=(ALL:ALL) ALL grader ALL=(ALL:ALL) ALL
to give sudo previliges to catalog usercatalog ALL=(ALL:ALL) ALL
-
Save and exit using CTRL+X and confirm with Y.
-
While logged in as
catalog
, create a database:createdb catalog
. -
Exit psql:
\q
. -
Switch back to the
grader
user:exit
.
- Run
$ sudo apt-get install git
- Create dictionary:
$ mkdir /var/www/catalog
- CD to this directory:
$ cd /var/www/catalog
- Clone the catalog app:
$ sudo git clone 'URL OF YOUR REPO' catalog
- Change the ownership:
$ sudo chown -R ubuntu:ubuntu catalog/
- CD to
/var/www/catalog/catalog
- Change file project.py to init.py:
$ mv project.py __init__.py
- Change line
app.run(host='0.0.0.0', port=8000)
toapp.run()
in init.py file - Create a new project on Google API Console and download
client_scretes.json
file - Copy and paste contents of downloaded
client_scretes.json
to the file with same name under directory/var/www/catalog/catalog/client_secrets.json
- Install pip:
$ sudo apt-get install python-pip
- Install the following packages:
$ sudo pip install httplib2
$ sudo pip install requests
$ sudo pip install --upgrade oauth2client
$ sudo pip install sqlalchemy
$ sudo pip install flask
$ sudo apt-get install libpq-dev
$ sudo pip install psycopg2
- Create file:
$ sudo touch /etc/apache2/sites-available/catalog.conf
- Add the following to the file:
<VirtualHost *:80>
ServerName 13.127.198.27
ServerAdmin admin@13.127.198.27
WSGIScriptAlias / /var/www/catalog/catalog.wsgi
<Directory /var/www/catalog/catalog/>
Order allow,deny
Allow from all
Options -Indexes
</Directory>
Alias /static /var/www/catalog/catalog/static
<Directory /var/www/catalog/catalog/static/>
Order allow,deny
Allow from all
Options -Indexes
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
- Run
$ sudo a2ensite catalog
to enable the virtual host - Restart Apache:
$ sudo service apache2 reload
- Create file:
$ sudo touch /var/www/catalog/catalog.wsgi
- Add content below to this file and save:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/catalog/")
sys.path.insert(1,"/var/www/catalog/catalog")
from catalog import app as application
application.secret_key = 'super_secret_key'
- Restart Apache:
$ sudo service apache2 reload
- Replace lines in
__init__.py
,database_setup.py
, anddata.py
withengine = create_engine('postgresql://catalog:PASSWORD@localhost/catalog')
$ sudo a2dissite 000-defualt.conf
- Restart Apache:
$ sudo service apache2 reload
- Run
$ sudo python database_setup.py
- Run
$ sudo python lotsofitems.py
- Restart Apache:
$ sudo service apache2 reload
- Now follow the link to http://13.127.198.27/ the application should be runing online
- Amazon Lightsail for creating ubuntu instance
- Google API Console
- Udacity
- Apache
- Github
- Postgresql
- xip.io for DNS