Public IP address: 52.221.234.110
Site Url: 52.221.234.110.xip.io
Note: Only Google Login is available currently.
- Download Lightrail default keys.
- mv ~/Download/LightsailDefaultKey-ap-southeast-1.pem ~/.ssh/
- chmod 700 ~/.ssh/
- chmod 600 ~/.ssh/LightsailDefaultKey-ap-southeast-1.pem
- Connect to remote Server using ssh ubuntu@server -i ~/.ssh/LightsailDefaultKey-ap-southeast-1.pem
-
Log in to remote as ubuntu user with
ssh ubuntu@server -i ~/.ssh/LightsailDefaultKey-ap-southeast-1.pem
-
Add new user with
$ sudo adduser grader
-
Create grader file in sudoers.d folder and insert the following line
grader ALL=(ALL:ALL) ALL
-
In local machine, generate encryption key with
$ ssh-keygen -f ~/.ssh/linuxServer.rsa
-
Log in remote server as ubuntu and create file authorized_keys with
$ touch /home/grader/.ssh/authorized_keys
-
Copy content of the file in ~/.ssh/linuxServer.rsa.pub to authorized_keys
-
Set permission to the keys by entering the following code
$ sudo chmod 700 /home/grader/.ssh
$ sudo chmod 644 /home/grader/.ssh/authorized_keys
-
Change owner from ubuntu to grader with
$ sudo chown -R grader:grader /home/grader/.ssh
-
Set PasswordAuthentication field to no to enforce key-based authentication
$ sudo nano /etc/ssh/sshd_config
-
Set PermitRootLogin field to no to disable ssh login for user
$ sudo nano /etc/ssh/sshd_config
-
Run
$ sudo service ssh restart
-
Edit Port field in sshd_config file to 2200
$ sudo nano /etc/ssh/sshd_config
-
Go to server instance in lightsail site
-
Select Networking tab
-
Add Custom Application with TCP Protocol at port 2200 to Firewall
-
Add Custom Application with UDP Protocol at port 123 to Firewall
-
Remove port 20 from this firewall
-
Run
$ sudo service ssh restart
-
Connect to user grader by entering the following code in command line
$ ssh -i ~/.ssh/linuxServer.rsa -p 2200 grader@52.221.234.110
-
Configure ufw to allow connection for port 2200, port 80 and port 123
$ sudo ufw allow 2200/tcp
$ sudo ufw allow 80/tcp
$ sudo ufw allow 123/udp
$ sudo ufw enable
$ sudo apt-get update
$ sudo apt-get install python
$ sudo apt-get install python-pip
$ sudo pip install virtualenv
$ sudo apt-get install python-requests
$ sudo apt-get install python-oauth2client
$ sudo apt-get install python-psycopg2
$ pip install Flask
$ pip install httplib2 sqlalchemy
$ sudo apt-get install libpq-dev python-dev
$ sudo apt-get install postgresql postgresql-contrib
-
Install Apache2
sudo apt-get install apache2
-
Install mod_wsgi
sudo apt-get install python-setuptools libapache2-mod-wsgi
-
Restart Apache
sudo service apache2 restart
-
Create directory in /var/www with
sudo mkdir catalog
-
Git clone item-catalog from Linux-Serverlive branch to /var/www/catalog/
git clone https://github.com/Lancelee92/item-catalog.git
-
Rename project folder to
item_catalog
-
Rename main python file in project to init.py
-
Create a virtual host config file
$ sudo nano /etc/apache2/sites-available/catalog.conf
-
Insert the following code:
<VirtualHost *:80> ServerName 52.221.234.110 ServerAlias hostname 52.221.234.110.xip.io ServerAdmin admin@52.221.234.110 WSGIDaemonProcess catalog python-path=/var/www/catalog:/var/www/catalog/venv/lib/python2.7/site-packages WSGIProcessGroup catalog WSGIScriptAlias / /var/www/catalog/catalog.wsgi <Directory /var/www/catalog/item_catalog/> Order allow,deny Allow from all </Directory> Alias /static /var/www/catalog/item_catalog/static <Directory /var/www/catalog/item_catalog/static/> Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
-
Enable the virtual host with
$ sudo a2ensite catalog
-
Create catalog.wsgi file in /var/www/catalog/ and insert the following code
import sys import logging logging.basicConfig(Stream=sys.stderr) sys.path.insert(0, "/var/www/catalog/") from item_catalog import application application.secret_key = 'super_secret_key'
-
Restart Apache2 with
sudo service apache2 restart
-
Login with
sudo su - postgres
-
Connect PostgreSQL shell with
$ psql
-
Create new user with password
# CREATE USER catalog WITH PASSWORD 'password';
-
Allow Catalog user to CREATEDB
# ALTER USER catalog CREATEDB;
-
Create catalog database with catalog user
# CREATE DATABASE catalog WITH OWNER catalog;
-
Connect to catalog database with
# \c catalog
-
Revoke all rights from public with
# REVOKE ALL ON SCHEMA public FROM public;
-
Grant permission to catalog user
# GRANT ALL ON SCHEMA public TO catalog;
-
Exit with
# \q
-
Edit create_engine line in database_setup.py and init.py
create_engine('sqlite:///itemcatalog.db')create_engine('postgresql://catalog:password@localhost/catalog')
-
Run
$ python /var/www/catalog/item-catalog/database_setup.py
$ ssh -i ~/.ssh/linuxServer.rsa -p 2200 grader@52.221.234.110
to connect server
Use
$ sudo tail /var/log/apache2/error.log
to check log
How to deploy flask application
-
download and install virtualbox for your operating systems
-
download and install for your operating systems
-
go to fullstack-nanodegree-vm
-
download Vagrantfile in vagrant directory
-
Run
$ vagrant init
in item-catalog folder -
Replace Vagrantfile in the item-catalog folder
-
Run this code to start vagrant
$ vagrant up
$ vagrant ssh
- Run
& python database-setup.py
to set up the database - Run
& python catalog.py
to start the site - Browse the site at http://localhost:5000
Click on the following link to access the JSON Api.
For Item List APi, the link used depends on the category id
localhost:5000/categories/<int:category_id>/itemlist/JSON
- Home Page Api
- Author List Api
- Recently Added Api
- Item List Api