{"id":18266118,"url":"https://github.com/alexandrabaturina/linux-server-configuration","last_synced_at":"2025-09-06T22:38:09.949Z","repository":{"id":119258546,"uuid":"249841824","full_name":"alexandrabaturina/linux-server-configuration","owner":"alexandrabaturina","description":"Configuring Ubuntu Linux server to host Flask application","archived":false,"fork":false,"pushed_at":"2020-11-21T01:03:20.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T01:47:28.921Z","etag":null,"topics":["amazon-lightsail","apache","postgresql","ubuntu-server","ufw","wsgi-application"],"latest_commit_sha":null,"homepage":"http://54.191.192.22.xip.io/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexandrabaturina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-24T23:36:58.000Z","updated_at":"2020-11-21T01:03:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"99068314-5b9e-45e1-bb11-6f23550ade49","html_url":"https://github.com/alexandrabaturina/linux-server-configuration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexandrabaturina/linux-server-configuration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrabaturina%2Flinux-server-configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrabaturina%2Flinux-server-configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrabaturina%2Flinux-server-configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrabaturina%2Flinux-server-configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexandrabaturina","download_url":"https://codeload.github.com/alexandrabaturina/linux-server-configuration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexandrabaturina%2Flinux-server-configuration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273973969,"owners_count":25200578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-lightsail","apache","postgresql","ubuntu-server","ufw","wsgi-application"],"created_at":"2024-11-05T11:21:52.608Z","updated_at":"2025-09-06T22:38:09.926Z","avatar_url":"https://github.com/alexandrabaturina.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Full Stack Web Development Nanodegree Capstone: Linux Server Configuration\n## Overview\n**Linux Server Configuration** is the capstone project of [Full Stack Web Developer Nanodegree Program](https://www.udacity.com/course/full-stack-web-developer-nanodegree--nd0044) provided by Udacity.\n\n**Linux Server Configuration** project has the following goals:\n* Access, secure, and perform the initial configuration of a bare-bones Linux server\n* Install and configure a web server\n* Install and configure database server\n* Host a web application\n\n[**Book Catalog**](https://github.com/alexandrabaturina/Book-Catalog) Flask-based application is built earlier as Project 2 of [Full Stack Web Developer Nanodegree Program](https://www.udacity.com/course/full-stack-web-developer-nanodegree--nd0044) provided by Udacity.\n\nVerify the deployment by visiting http://54.191.192.22.xip.io.  \n## Features\n**Linux Server Configuration** project consists of the following steps:\n* Initial configuring of ***Ubuntu*** Linux server instance on ***Amazon Lightsail***\n* Configuring ***Apache*** web server\n* Configuring ***PostgreSQL*** database server\n* Deploying  [**Book Catalog**](https://github.com/alexandrabaturina/Book-Catalog) as mod_wsgi application\n\n## Securing Server\nTo secure the server, the following steps were taken:\n* All currently installed packages are updated using ```sudo apt-get update``` and ```sudo apt-get upgrade``` commands.\n* The ***Lightsail*** firewall is configured to allow incoming connections for ```SSH``` (port ```2200```).\n*  The ***Uncomplicated Firewall (UFW)*** is configured to allow connections according to project specifications.\n### Configuring UFW\nTo host ```SSH``` on a non-default port, ```port 22``` is changed to ```port 2200``` in ```/etc/ssh/sshd_config``` configuration file.\n```\n# What ports, IPs and protocols we listen for\nPort 2200\n```\n\n***UFW*** is configured to only allow connections for ```SSH``` (port 2200), ```HTTP``` (port 80), and ```NTP``` (port 123). Below is the list of current UFW rules.\n```\nStatus: active\nDefault: deny (incoming), allow (outgoing), disabled (routed)\n\nTo                         Action      From\n--                         ------      ----\n22                         DENY IN     Anywhere\n2200                       ALLOW IN    Anywhere\n80                         ALLOW IN    Anywhere\n123                        ALLOW IN    Anywhere\n123/udp                    ALLOW IN    Anywhere\n22 (v6)                    DENY IN     Anywhere (v6)\n2200 (v6)                  ALLOW IN    Anywhere (v6)\n80 (v6)                    ALLOW IN    Anywhere (v6)\n123 (v6)                   ALLOW IN    Anywhere (v6)\n123/udp (v6)               ALLOW IN    Anywhere (v6)\n```\n## Configuring Server\n### Configuring Timezone\nThe local timezone for ```grader``` is configured to UTC using the following command.\n```\nsudo timedatectl set-timezone UTC\n```\n### Installing and Configuring Apache\n*Apache* web server is installed using the following command.\n```sh\nsudo apt-get install apache2\n```\nThe **Book Catalog** project is built with Python 3, so the Python 3 ```mod_wsgi``` package is installed on the server to host **Book Catalog** as a mod_wsgi application.\n```sh\nsudo apt-get install libapache2-mod-wsgi-py3\n```\n### Installing and Configuring PostgreSQL\n***PostgreSQL*** database server is installed using the following command.\n```sh\nsudo apt-get install postgresql\n```\nTo disable remote connections to the ***PostgreSQL*** database, in ***PostgreSQL*** client authentication configuration file  ```/etc/postgresql/9.5/main/pg_hba.conf``` listen addresses are set to ```127.0.0.1```.\n```\n# Database administrative login by Unix domain socket\nlocal   all             postgres                                peer\n\n# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n# \"local\" is for Unix domain socket connections only\nlocal   all             all                                     peer\n# IPv4 local connections:\nhost    all             all             127.0.0.1/32            md5\n# IPv6 local connections:\nhost    all             all             ::1/128                 md5\n```\n#### Creating ```catalog``` user\nDatabase user account named```catalog``` with limited permissions to **Book Catalog** database was created via interactive terminal for working with ***PostgreSQL*** using the following commands.\n```sh\npostgres=# create user catalog with login password 'catalog'; \nCREATE ROLE \npostgres=# alter user catalog with createdb; \nALTER ROLE \n```\n## Deploying Project\n### Creating Flask Application Structure\nTo allow ***Apache*** to serve the **Book Catalog** project as a ```WSGI``` applicaton, the following folder structure is used.\n```sh\nbookCatalog/\n    bookcatalog.wsgi\n    bookCatalog/\n        static/\n        templates/\n        __init__.py\n        client_secrets.json\n        database_setup.py\n        lotsofbooks.py\n```\n### Installing Software and Python Dependencies\nThe following programs are installed on the server.\n* **git**: to clone the **Book Catalog** project from *GitHub*\n* **pip**: to install some Python modules\n\nThe **Book Catalog** project was built using ```Flask```, which was installed using the commmand below.\n```sh\npip install Flask\n```\n\nThe following Python modules and dependencies are installed on the server:\n* **flask_sqlalchemy**: to work with *SQLAlchemy*\n* **httplib2**: to provide web access via *HTTP*\n* **psycopg2**: to connect and work with *PostgreSQL* server\n* **oauth2client**: to work with *OAuth 2.0*\n### Creating Configuration File\nVirtual host configured in ```bookCatalog.conf``` file under ```/etc/apache2/sites-available/```.\n```conf\n\u003cVirtualHost *:80\u003e\n                ServerName 54.191.192.22\n                WSGIScriptAlias / /var/www/bookCatalog/bookcatalog.wsgi\n                \u003cDirectory /var/www/bookCatalog/bookCatalog/\u003e\n                        Order allow,deny\n                        Allow from all\n                \u003c/Directory\u003e\n                Alias /static /var/www/bookCatalog/bookCatalog/static\n                \u003cDirectory /var/www/bookCatalog/bookCatalog/static/\u003e\n                        Order allow,deny\n                        Allow from all\n                \u003c/Directory\u003e\n                DocumentRoot /var/www/html\n                ErrorLog ${APACHE_LOG_DIR}/error.log\n                LogLevel warn\n                CustomLog ${APACHE_LOG_DIR}/access.log combined\n\u003c/VirtualHost\u003e\n\n```\nTo enable the configured virtual host and disable the default Apache configuration, the following commands were used.\n```sh\nsudo a2ensite bookCatalog\nsudo a2dissite 000-default.conf\n```\n### Creating WSGI File\nThe ```bookcatalog.wsgi``` file under ```/var/www/bookCatalog/``` is below.\n```sh\n#!/usr/bin/python\nimport sys\nimport logging\nlogging.basicConfig(stream=sys.stderr)\nsys.path.insert(0,\"/var/www/bookCatalog/\")\n\nfrom bookCatalog import app as application\napplication.secret_key = 'alexandrabaturina'\n```\n### Pupulating the Database\nUnder ```catalog``` user, the empty ```catalogitems``` database is created.\n```\nCREATE DATABASE catalogitems;\n```\nFor demonstration purposes, the ```catalogitems``` database is populated from the ```lotsoibooks.py``` file using the following commands:\n```sh\npython database_setup.py\npython lotsofbooks.py\n```\n## List of Resourses\n* [Flask mod_wsgi official documentation](https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/#configuring-apache)\n* [Official PostgreSQL documentation](https://www.postgresql.org/docs/9.5/auth-pg-hba-conf.html)\n* [Git documentation](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n* [How to Set or Change the Time Zone in Linux](https://linuxize.com/post/how-to-set-or-change-timezone-in-linux/#changing-the-time-zone-in-linux)\n* [How To Set Up a Firewall with UFW on Ubuntu 18.04](https://linuxize.com/post/how-to-setup-a-firewall-with-ufw-on-ubuntu-18-04/)\n* [How to Deploy a Flask App to a Linux Server](https://www.youtube.com/watch?v=YFBRVJPhDGY\u0026list=LLrB69AKIO0ESnb0rzqTZZ4g)\n## Authors\n    + Alexandra Baturina\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandrabaturina%2Flinux-server-configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexandrabaturina%2Flinux-server-configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexandrabaturina%2Flinux-server-configuration/lists"}