Linux Server Configuration is the last project as a part of Udacity Full Stack Web Developer Nanodegree certification. In this project, the Catalog Web Application will be hosted by a Ubuntu Linux server on an Amazon Lightsail instance.
- IP : 13.126.84.248
- SSH Port: 2200
One needs an AWS account and a Ubuntu Linux instance running on the Lightsail service. Refer to the Get Started on Lightsail chapter from Udacity FSWD project for instructions on setting up a Linux instance in this service.
In the terminal shell accessed, run the follow command to install required binaries and libraries.
sudo apt-get install apache2 postgresql python-psycopg2 python-sqlalchemy python-pip python-flask python-oauth2client python-requests python-httplib2 libapache2-mod-wsgi
First copy the default private key from server to local machine. You might need this in case you need to login with the user ubuntu.
Run Following commands
- adduser grader
- sudo usermod -aG sudo grader
- On local machine generate ssh key pair using command ssh-keygen on git bash.
- a key pair will be saved in the .ssh folder on local machine.
- On server, at location /home/grader create directory .ssh
- In the directory /home/grader/.ssh, create a file authorized_keys and copy the content of the .pub file generated by the keygen command.
- In file /etc/ssh/sshd_config change the port to 2200
Execute following commands:
- sudo ufw allow ssh
- sudo ufw allow 2200/tcp
- sudo ufw allow www
- sudo ufw allow ntp
- sudo ufw enable
In the Network manage section of AWS, add a new rule in firewall as Custom TCP port 2200. This will enable you to ssh with port 2200. Remove the SSH port 20 from the list. Also add rule for Custom TCP with Port 123 for NTP access. Try login using ssh from local machine to remote server using the login id grader.
-
In folder /var/www execute following command to clone the server code: git clone https://github.com/blueshift155/Udacity-Portal.git The git will create a folder named
Udacity-Portal
. Rename this tocatalog
-
Change directory to
catalog
. Create a wsgi file namedcatalogapp.wsgi
which is required by Apache to hand-off certain requests.
Paste below contents in this new file:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/catalog")
from __init__ import app as application
#application.secret_key = 'super_secret_key'
-
In Folder /etc/apache2/sites-available/, create new file named catalogapp.conf using command:
Paste following contents in this new file
<VirtualHost *:80>
ServerName 13.126.84.248
ServerAlias ec2-13-126-84-248.ap-south-1.compute.amazonaws.com
ServerAdmin [email protected]
WSGIDaemonProcess catalog user=www-data group=www-data threads=5
WSGIProcessGroup catalog
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/catalog/catalogapp.wsgi
<Directory /var/www/catalog/>
Order allow,deny
Allow from all
Options -Indexes
</Directory>
Alias /static /var/www/catalog/static
<Directory /var/www/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>
Create a database using the following commands:
- sudo su - postgres postgres@ip-172-26-12-211:~$ psql
- Then on the postgresql prompt, run these commands create user catalog with password 'pass'; create database catalog GRANT ALL PRIVILEGES ON DATABASE catalog TO catalog;
- sudo a2dissite 000-default.conf
- sudo a2ensite catalogapp.conf
https://github.com/udacity/fullstack-nanodegree-vm
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04