You will take a baseline installation of a Linux server and prepare it to host your web applications. You will secure your server from a number of attack vectors, install and configure a database server, and deploy one of your existing web applications onto it.
Log-in to server as ssh [email protected] -i ~/.ssh/myudacitykey.pem
-
$ sudo adduser grader
-
Give User permission to sudo:
$ sudo nano /etc/sudoers.d/grader
Add: grader ALL=(ALL) NOPASSWD:ALL
-
$ sudo apt-get update
-
$ sudo apt-get upgrade
-
$ sudo nano /etc/ssh/sshd_config
. Edit Port Line from 22 to 2200. -
Disable root login. Change to ‘no’ for PermitRootLogin
-
$ sudo service ssh restart.
-
To generate key pair, locally (not connect with server ssh yet) :
ssh-keygen -f ~/.ssh/graderkey
-
Log in as Grader :
$ sudo su - grader
-
Create directory:
mkdir .ssh
-
Create new file within above directory to store public keys :
touch .ssh/authorized_keys
-
Get key from local:
cat .ssh/graderkey.pub
. Copy -
Open file and paste key into:
nano .ssh/authorized_keys
-
Set permission :
chmod 700 .ssh
-
And then
chmod 644 .ssh/authorized_keys
-
Back to grader server:
$ sudo nano /etc/ssh/sshd_config
-
Look for this line : PasswordAuthentication. Change ‘yes’ to ‘no’. SAVE
-
Restart to run as new configuration:
$ sudo service ssh restart
grader user now can log in as ssh [email protected] -p 2200 -i ~/.ssh/graderkey
Project requirements need the server to only allow incoming connections for SSH (port 2200), HTTP (port 80), and NTP (port 123).
1. $ sudo ufw default deny incoming
2. $ sudo ufw default allow outgoing
3. $ sudo ufw allow 2200/tcp
4. $ sudo ufw allow 80/tcp
5. $ sudo ufw allow 123/udp
6. $ sudo ufw enable.
Run $ sudo dpkg-reconfigure tzdata
and then choose None of the above
and choose UTC
.
1. $ sudo apt-get install apache2
2. $ sudo apt-get install libapache2-mod-wsgi python-dev
3. sudo a2enmod wsgi
-
$ sudo apt-get install libpq-dev python-dev
-
$ sudo apt-get install postgresql postgresql-contrib
-
Login as user "postgres"
$ sudo su - postgres
-
Get into postgreSQL shell:
psql
-
CREATE USER catalog WITH PASSWORD 'udacity';
-
ALTER USER catalog CREATEDB;
-
CREATE DATABASE catalog WITH OWNER catalog;
-
To connect to db:
\c catalog
-
REVOKE ALL ON SCHEMA public FROM public;
-
GRANT ALL ON SCHEMA public TO catalog;
-
To quit
\q
andCTRL + D
-
$ sudo apt-get install git
-
cd /var/www
-
$ sudo mkdir catalog
-
$ sudo chown -R grader:grader catalog
to change owner -
Cd catalog
-
Clone project into above direction:
git clone https://github.com/Rachelspdo/Build-Catalog.git catalog
-
cd catalog
-
Rename application.py to
__init__.py
using$ sudo mv application.py __init__.py
-
Edit
database_setup.py, lotsofmenus.py, __init__.py
by$ sudo nano database_setup/lotsofmenus.py/__init__.py
and change engine = create_engine('sqlite:///restaurantmenuwithusers.db') to engine = create_engine('postgresql://catalog:udacity@localhost/catalog') -
python lotsofmenus.py
to import sample data to site
-
$ sudo apt-get install python-pip
-
Install the virtual environment:
$ sudo pip install virtualenv
-
Create a new virtual environment:
$ sudo virtualenv venv
-
To activate the virutal environment:
source venv/bin/activate
-
Change permissions to the virtual environment folder:
$ sudo chmod -R 777 venv
-
Install Flask:
$ sudo pip install Flask
-
Install other dependencies:
sudo apt-get install python-psycopg2 python-flask
sudo apt-get install python-sqlalchemy python-pip
sudo pip install oauth2client
sudo pip install requests
sudo pip install httplib2
- Create database:
$ sudo python database_setup.py
- Change path to client-secrets.json file to
/var/www/catalog/catalog/client_secrets.json
-
cd /var/www/catalog
-
$ sudo nano catalog.wsgi
Add this to file:
#!/usr/bin/python
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"
-
Create a virtual host conifg file:
$ sudo nano /etc/apache2/sites-available/catalog.conf
-
Add to file:
<VirtualHost *:80>
ServerName 54.189.193.41
ServerAlias ec2-54-189-193-41.us-west-2.compute.amazonaws.com
ServerAdmin [email protected]
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 with the following command:
$ sudo a2ensite catalog
-
$ sudo nano client_secrets.json
-
Add to Authorized Javascript Origin:
http://54.189.193.41
-
Add Authorized Redirect URL
http://ec2-189-193-41.us-west-2.compute.amazonaws.com
-
Go to
console.developers.google.com
and also add the above addresses to the OAuth Credencials
Restart Apache with the following command to apply the changes:
$ sudo service apache2 restart
$ sudo a2dissite 000-default.conf