Take a baseline installation of a Linux distribution on a virtual machine and prepare it to host your web applications, to include installing updates, securing it from a number of attack vectors and installing/configuring web and database servers.
-
IP address: 54.82.201.241
-
Accessible SSH port: 2200
-Accessible using : ssh grader@54.82.201.241 -p 2200
- Create new user named grader and give it the permission to sudo
- Run
$ sudo adduser graderto create a new user named grader - Create a new file in the sudoers directory with
sudo nano /etc/sudoers.d/grader - Add the following text
grader ALL=(ALL:ALL) ALL
- Update all currently installed packages
- Download package lists with
sudo apt-get update - Fetch new versions of packages with
sudo apt-get upgrade
- Change SSH port from 22 to 2200 "I tried but could not do it"
- Run
sudo nano /etc/ssh/sshd_config - Change the port from 22 to 2200
- Confirm by running
ssh -i ~/.ssh/udacity_key.rsa -p 2200 root@35.167.27.204
- Configure the Uncomplicated Firewall (UFW) to only allow incoming connections for SSH (port 2200), HTTP (port 80), and NTP (port 123)
sudo ufw allow 2200/tcpsudo ufw allow 80/tcpsudo ufw allow 123/udpsudo ufw enable
- Configure the local timezone to UTC
- Run
sudo dpkg-reconfigure tzdataand then choose UTC
- Configure key-based authentication for grader user
- Run this command
cp /root/.ssh/authorized_keys /home/grader/.ssh/authorized_keys
- Install Apache
sudo apt-get install apache2
- Install mod_wsgi
- Run
sudo apt-get install libapache2-mod-wsgi python-dev - Enable mod_wsgi with
sudo a2enmod wsgi - Start the web server with
sudo service apache2 start
- Clone the Catalog app from Github
- Install git using:
sudo apt-get install git cd /var/wwwsudo mkdir catalog- Change owner of the newly created catalog folder
sudo chown -R grader:grader catalog cd /catalog- Clone your project from github `git clone https://github.com/iliketomatoes/catalog.git catalog'
- Create a catalog.wsgi file, then add this inside:
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/catalog/")
from catalog import app as application
application.secret_key = 'supersecretkey'
- Rename application.py to init.py
mv application.py __init__.py
- Install virtual environment
- Install the virtual environment
sudo pip install virtualenv - Create a new virtual environment with
sudo virtualenv venv - Activate the virutal environment
source venv/bin/activate - Change permissions
sudo chmod -R 777 venv
- Install Flask and other dependencies
- Install pip with
sudo apt-get install python-pip - Install Flask
pip install Flask - Install other project dependencies
sudo pip install httplib2 oauth2client sqlalchemy psycopg2 sqlalchemy_utils
- Update path of client_secrets.json file
nano __init__.py- Change client_secrets.json path to
/var/www/catalog/catalog/client_secrets.json
- Configure and enable a new virtual host
- Run this:
sudo nano /etc/apache2/sites-available/catalog.conf - Paste this code:
<VirtualHost *:80>
ServerName 54.82.201.241
ServerAdmin admin@54.82.201.241
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/catalog/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/catalog/catalog/static
<Directory /var/www/catalog/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
sudo a2ensite catalog
- Install and configure PostgreSQL
sudo apt-get install libpq-dev python-devsudo apt-get install postgresql postgresql-contribsudo su - postgrespsqlCREATE USER catalog WITH PASSWORD 'password';ALTER USER catalog CREATEDB;CREATE DATABASE catalog WITH OWNER catalog;\c catalogREVOKE ALL ON SCHEMA public FROM public;GRANT ALL ON SCHEMA public TO catalog;\qexit
- Restart Apache
sudo service apache2 restart
-
Special thanks to stueken who wrote a really helpful README in his repository.
-
Visit site at http://54.82.201.241