Please ensure you have installed all of the software below:
-
MySQL - use this page if you don't already have it
-
Visual Studio Code (VS Code) - use this page if you don't already have it
- Please feel free to use a different IDE if you do not like/prefer VS Code
-
Install Python
- For Windows, please install Python using Microsoft Store Application if you don't already have it...this will help prevent future errors with Flask
- For macOS, please install Python using this page if you don't already have it
-
Git - use this page if you don't already have it
-
Clone this repository
-
Open the Command Prompt (Windows) or Terminal (macOS)
- When using the Command Prompt or Terminal, ensure that you enter after each command in order to complete and run the command
-
Now we need to clone the repository onto your computer. Begin by using
cd
to whatever folder you want to have the project in-
The
cd <folder name>
command allows you to access folders within your computer. Following the cd command should be the name of the folder you wish to enter. You must move through the folders as if you were opening them through Finder or your File Explorer.- If you would your folders are configured like this: QuasarResearch > Git > Code and you are starting in the QuasarResarch folder but would like to move to the Code folder, then you would need to do
cd Git
thencd Code
- If you would your folders are configured like this: QuasarResearch > Git > Code and you are starting in the QuasarResarch folder but would like to move to the Code folder, then you would need to do
-
If you would like to see a list of the folders you can enter, use
ls
(Mac) ordir
(Windows). Thels
/dir
command lists all the available folders in your current directory. -
cd ..
allows you to move back to the folder you were just previously in- If you were in QuasarResearch > Git > Code folder and you used
cd ..
then you would move to the Quasar > Git folder
- If you were in QuasarResearch > Git > Code folder and you used
-
-
Use this command to clone the repository to your computer
git clone https://<YOUR_GITHUB_USERNAME>@github.com/paolaUWB/QuasarResearchWebsite.git
- Make sure to replace <YOUR_GITHUB_USERNAME> with your GitHub username and remove the angled brackets (< >)
-
-
Check to see if all of the files were cloned
-
Run the
dir
/ls
command -
You should see a new "QuasarResearchWebsite" directory
-
-
Open project in Visual Studio Code
- Open Visual Studio Code
- File -> Open folder and then navigate to the QuasarResearchWebsite folder that you just cloned
-
Set up flask environment:
- Open a new terminal in Visual Studio Code and run
python3 -m venv flaskEnv
- To verify if this command worked, you should see a new folder called "flaskEnv" in the QuasarResearchWebsite folder
- Activate the environment
- For Windows: you can do this by running the following command:
flaskEnv\Scripts\activate
in the terminal. - For Mac: you can do this by running the following command:
source flaskEnv/bin/activate
- For Windows: you can do this by running the following command:
- Install the necessary software using the commands below
pip install flask
pip install PyMySQL
pip install Flask-WTF
pip install python-dotenv
pip install flask-sqlalchemy
pip install flask-migrate
pip install flask-login
pip install email-validator
-
On Windows you may recieve an error message stating "running scripts is disabled on this system"
-
To fix this open Windows PowerShell with administration privileges
- To open, search "PowerShell" in the Windows Start menu and right click on "Powershell" then select "Run as administrator" from the context menu
-
Enter 'set-executionpolicy remotesigned' to PowerShell
-
When asked "Do you want to change the execution policy?", respond with 'Y' for yes
-
-
For more instructions on using python environments in Visual Studio Code, see https://code.visualstudio.com/docs/python/environments
- Open a new terminal in Visual Studio Code and run
-
Add the secret environment variables:
- Create a new file in QuasarResearchWebsite/app/ and name it .env
- Add your secrets to the file with the following:
SECRET_KEY=<WHATEVER YOU WANT> MYSQL_DATABASE_PASSWORD=<YOUR MYSQL DB/ROOT PASSWORD>
-
Add the path for downloads
- Create a new directory/folder in QuasarResearchWebsite/app/ and name it tmp
- Create a new file in QuasarResearchWebsite/app/tmp and name it quasars.csv
-
Setup the MySQL database:
- In the VSCode Terminal, start mysql with
& cmd.exe /c "mysql -u root -p --verbose --local-infile=1 < app/quasarDB_win.sql"
, and enter your password for root user python app/updateDatabase_win.py
(this will update the paths to the images in the database)
- In the VSCode Terminal, start mysql with
-
Now check to see if things are working. In the Visual Studio terminal type
flask run
- If everything is working you should see something like:
(flaskEnv) PS C:\Users\guine\Desktop\test\QuasarResearchWebsite> flask run * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Follow the link on the last line to see if it runs. Your default internet browser should open to the home page of the website.
- Check that the images are loading correctly by going to the "Data Access" page under "Research", clicking on a row and seeing if the image shows up.
- Voila!
- If everything is working you should see something like:
-
The user database and login system follows these two tutorials
-
To view all users
-
flask shell
-
See list of all usernames
users = User.query.all()
users
-
See list of ids of users
users = User.query.all()
-
for u in users: ... print(u.id, u.username) ...
-
-
To add a user
-
flask shell
-
u = User(username='INSERT USERNAME HERE', email='INSERT EMAIL HERE')
-
u.set_password('INSERT PASSWORD HERE')
-
db.session.add(u)
-
db.session.commit()
-
-
To delete all users
-
flask shell
-
users = User.query.all()
-
for u in users: ... db.session.delete(u) ...
-
db.session.commit()
-
1. To delete a specific user
1. `flask shell`
1. Find the id of the user you want to delete.
1. `u = User.query.get(INSERT ID HERE)`
1. `db.session.delete(u)`
1. `db.session.commit()`
- Github account with access to this github page
- Putty (if on windows)
- Terminal (if on Mac or Linux)
-
Activate your UW shared web hosting
- Follow instructions on this page
- Ensure that you subscribe to and activate
Vergil Account
,Homer/Ovid Account
andWeb Publishing
- Ensure that you subscribe to and activate
- Follow instructions on this page
-
SSH into the school servers:
- Connect to the UW network and open PuTTY
- In PuTTY, under Host Name put
vergil.u.washington.edu
- Port 22
- Connection type SSH
- Under Saved Sessions type whatever name you want
- Click
Save
(this will make it so that you can just double click or load next time you want to access the server) - Click
Open
- If prompted with a PuTTY Security Alert message, click
Accept
- If prompted with a PuTTY Security Alert message, click
- Login as:
Your UW ID
- Password:
Your UW password
- If you are new to SSH, know that you won't actually see your password get typed. It'll look invisible but it is still getting input into the system.
- Voila! You should be in now! Check that everything worked by typing
ls
into the command prompt. You should see one directory, "public_html"
- If you are on macOS, connect to the UW network and open Terminal
- If you are unsure how to connect to the UW network, it is reccomended to use Husky OnNet. More information and how to download and use the software can be found here
- Type and enter
ssh <YOUR_UW_NETID>@vergil.u.washington.edu
- When prompted for your password, use your UW password
- If you are new to SSH, know that you won't actually see your password get typed. It'll look invisible but it is still getting input into the system.
- Voila! You should be in now! Check that everything worked by typing and entering
ls
into the command prompt. You should see one directory, "public_html"
If you need more information, see this page
-
Setup MySQL on the school servers:
- Set up Localhome
- Ensure you are still connected to UW's network and Vergil then type
localhome
in your Terminal- To recconnect to Vergil, follow the directions in the previous step again
- Exit from Vergil by typing and entering
exit
in your Terminal - SSH into
ovid
by typing and entering<YOUR_UW_NETID>@ovid.u.washington.edu
in your Terminal
- Ensure you are still connected to UW's network and Vergil then type
- Make sure to write down your root password and username
If you need more inforamtion, see this page
- Set up Localhome
-
Add files to the web server
-
In the terminal clone files from github with the following commands:
cd ~/public_html
git clone https://<YOUR_GITHUB_USERNAME>@github.com/paolaUWB/QuasarResearchWebsite.git
- Enter your github password when prompted
-
Check to see if all of the files were cloned
ls
- You should see a new "QuasarResearchWebsite" directory in your public_html folder
-
-
Set up a python virtual environment:
cd ~/public_html
- type into the prompt:
python3 -m venv flaskEnv
(this will take a couple of seconds to run)source flaskEnv/bin/activate
You should now see something like:(flaskEnv) vergil11$
pip install flask
pip install PyMySQL
pip install Flask-WTF
pip install python-dotenv
pip install flask-sqlalchemy
pip install flask-migrate
pip install flask-login
pip install email-validator
-
Create a .env file to store secret information
cd ~/public_html/QuasarResearchWebsite
nano .env
- type the following:
SECRET_KEY= <WHATEVER_SECRET_KEY_YOU_WANT> MYSQL_DATABASE_PASSWORD=<YOUR_MYSQL_DATABASE_ROOT_PASSWORD> MYSQL_DATABASE_PORT = <YOUR_MYSQL_DATABASE_PORT>
- Save and close with the following commands:
ctrl+x y enter
-
Add the path for downloads
cd ~/public_html/QuasarResearchWebsite/app
mkdir tmp
cd ~/public_html/QuasarResearchWebsite/app/tmp
touch quasars.csv
-
Setup DB
cd ~/public_html/QuasarResearchWebsite/app
- Create and update the database with the following command (it will run the commands in the .sql file)
~/mysql/bin/mysql < quasarDB.sql -u root -p --verbose
- Update DB with graph images
cd ~/public_html/QuasarResearchWebsite/app
- Make sure your flask enviroment is activated
python updateDatabase.py
-
Edit htaccess and cgi files
-
This next part is a little tricky and easy to make a mistake by leaving off slashes by accident. Be careful here!
-
Make sure you are in your 'public_html' directory
cd ~/public_html
-
In the terminal create a new htaccess file by typing the following:
pico .htaccess
- Enter the following into the file:
RewriteEngine on RewriteRule ^/?$ /<YOUR_UW_NETID>/main.cgi [L]
- Save and close with the following commands:
ctrl+x y enter
- Enter the following into the file:
-
Now we need to create the CGI file
-
cd ~/public_html
-
Type
pico main.cgi
into the terminal -
Copy and paste this into the file (you can paste in Putty by clicking left and right mouse buttons at the same time)
#!flaskEnv/bin/python3 import sys, os import cgi; import cgitb; cgitb.enable() from wsgiref.handlers import CGIHandler sys.path.insert(0, 'QuasarResearchWebsite') sys.path.insert(0, 'QuasarResearchWebsite/app') from app.__init__ import app CGIHandler().run(app)
-
Save and close with:
ctrl+x y enter
-
Change the file permissions to allow the server to execute the program with
chmod 755 main.cgi
-
Now change the file permissions for the python init file with the following commands:
cd ~/public_html/QuasarResearchWebsite/app
chmod 755 __init__.py
-
-
Check to see if it worked by going to your UW url. It will be https://students.washington.edu/<YOUR_UW_NETID>/
-
-
Basic MySQL Administration: https://itconnect.uw.edu/connect/web-publishing/shared-hosting/using-mysql-on-shared-uw-hosting/basic-mysql-administration/
-
Troubleshooting Steps: https://itconnect.uw.edu/connect/web-publishing/shared-hosting/troubleshooting/
-
If the Data Access page doesn't work (E.g. "Internal Server Error", data not displaying, etc.)
- Go to init.py
- Change the port number in the method connect_db() to have your port number
-
To update and access most recent files enter
git pull
into the terminal when you are in your QuasarResearchWebsite folder -
To push your most recent files to the master branch
- Enter
git status
to list out files that have been added/changed. the names of the files should be red - Add files that are unecessary to the project to .gitignore
- Enter
git status
To list out files again to check if those files were removed. - Enter
git add .
To the terminal. - Enter
git status
to the terminal. The names of the files should now be green. - Enter git
commit -m "message"
. You can change the message to anything you want but it should be somewhat descriptive. - Enter git `push to the terminal.
- If this is your first time doing so you should type in "git push --set-upstream origin YourBranch". Change "YourBranch" to the actual name of the branch.
- Go to the Github repository to merge your request
- Enter
-
If you recieve the error message: "running scripts is disabled on this system"
- Open Windows PowerShell with administration privileges
- To open, search "PowerShell" in the Windows Start menu and select "Run as administrator" from the context menu
- Enter
set-executionpolicy remotesigned
to PowerShell - When asked "Do you want to change the execution policy?", respond with
Y
for yes - For more information visit: https://www.faqforge.com/windows/windows-powershell-running-scripts-is-disabled-on-this-system/
- Open Windows PowerShell with administration privileges
-
To add the mysql exe file to the path
- type "path" into the windows search bar and click "edit the system environment variables"
- click on environment variables
- click on path, then edit, then new
- then add the paths
C:\Program Files\MySQL\MySQL Shell 8.0\bin\
andC:\Program Files\MySQL\MySQL Server 8.0\bin\
to the list - click ok/apply
- restart your computer
1. If you recieve the error mesage: `module not found`
1. Type `python -m pip list` into VS Code's terminal
1. This will list all installed packages
1. If the package you need is not in the list, enter `pip install [package name]` to the terminal
1. For example, if you need to install PyMySql, enter `pip install PyMySQL` to the terminal
1. Setting the virtual enviroment in VS Code
1. type "path" into the windows search bar and click "edit the system environment variables"
1. Use `CTRL + SHIFT + P`
1. click on "Python: select interpreter"
1. Select the path that has flaskEnv/Scripts/ in the path name
1. To learn more check this page: https://code.visualstudio.com/docs/python/environments