Skip to content

Instantly share code, notes, and snippets.

@jcarter62
Last active July 23, 2019 22:12
deploy python app to linux
Things to do:
Update Available Package Lists:
# sudo apt-get update
Upgrade installed packages:
# sudo apt-get upgrade
Other Tasks:
# sudo apt-get autoremove
Discover Packages: https://packages.ubuntu.com
Add User: sudo adduser <name>
Giving sudo access to user:
/etc/sudoers.d contains a file for each account allowd.
copy existing /etc/sudoers.d//vagrant to <name> and change existing name to <name>
Do not just copy /etc/sudoers to /etc/sudoers.d/<name>, as this will break sudo.
On any system:
Generate key pairs
# ssh-keygen
Save to file, which will create a private and public key, key pair. For example if you save the pair to a file such as ~/.ssh/linuxclass
On the remote system. Login as the non-admin user such as <student>
Install public key
# cd ~
# mkdir .ssh
# touch .ssh/authorized_keys
# vi .ssh/authorized_keys
paste the linuxclass.pub into the authorized_keys as one line, then save the file.
# chmod 700 .ssh
# chmod 644 .ssh/authorized_keys
On local system:
# ssh -p 2222 <student>@localhost -i ~/.ssh/linuxclass
Disable password logins:
# sudo vi /etc/ssh/sshd_config
Find the line similar to:
PasswordAuthentication yes
-- change it to --
PasswordAuthentication no
Change sudo for a user, so they don't need a password:
reference: https://phpraxis.wordpress.com/2016/09/27/enable-sudo-without-password-in-ubuntudebian/
edit /etc/sudoers.d/<name>
change line for this user to:
user ALL=(ALL) NOPASSWD:ALL
***
Deploy Flask app to Apache:
https://www.bogotobogo.com/python/Flask/Python_Flask_HelloWorld_App_with_Apache_WSGI_Ubuntu14.php
***
Edit /etc/apache2/envvars
Add line:
export APP_DIR=/home/..../path2app/
Apache Config information: https://stackoverflow.com/a/49807673
`
<VirtualHost *:80>
ServerName MY_SERVER_NAME
WSGIDaemonProcess appname threads=5 home=${APP_DIR}
WSGIScriptAlias / "${APP_DIR}your_app.wsgi"
<Directory "${APP_DIR}">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Require all granted
WSGIProcessGroup appname
WSGIApplicationGroup %{GLOBAL}
</Directory>
</VirtualHost>
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment