Deploy To Amazon Linux


System

First update

sudo yum update -y  


And then the actual packages we need (some might already be installed like httpd)


sudo yum install -y zip python3 python3-pip httpd mod_wsgi git libjpeg-turbo-devel
sudo service httpd start    


Let's create the file structure - this is where we usually host our files but you can use the structure you are already using.



mkdir /srv/www/mkdir /srv/www/invatron.com   


SSH keys

Add the key to the ssh keys (provided in the email), this will allow you to download the repo. Upload to the server and and add the invatron key to your ~/.ssh directory. 

Upload the files to the server, if you are on a mac/linux machine you can

 scp thekeys.zip <username>@invatron.com: 

Once the key is up, unzip it into the .ssh location.


unzip ~/thekeys.zip ~/.ssh/vim (or use nano) ~/.ssh/config 

Add the one line to the config file


IdentityFile ~/.ssh/invatron  

Now close the file and change it's permissions


chmod 700 ~/.ssh/config 

Now exit the terminal session to reload with the newest bash



Python + Repo

We get the repo and setup python


cd /srv/www
git clone git@bitbucket.org:alsoplus/invatron.git invatron.com
cd invatron.com
python3 -m venv envsource env/bin/activate pip install -r req.txt


If all was successful you can try to run the server and see if it works on port 8000, the server won't actually work yet but will turn on, any connection will fail because there is no database yet.


Copy the database from the email into application/db.sqlite3

Copy the media files into public_html/media/

Make the directory logs/ (that's where I usually throw my logs but you may want to do something different)

Once everything looks like it's ready to go with the virualenv activate run


python application/manage.py collectstatic 


This will copy all the static files into public_html/static/ 



Setting up Apache

We use wsgi to connect Apache with Django, our example conf (invatron.designtennis.ca.conf)  shows how we connect it with the virtualenv. We also create direct links to the /static/ and /media/ because Django shouldn't be managing these files.

I think I've included the right mod for apache, mod_wsgi, but let me know if your apache can't find this or doesn't like it.


For SSL I will leave it up to your to configure so you can maintain it. We usually use certbot because it's free and easy (I don't know if it exists for Amazon Linux though)


Once we are ready to launch live we should edit the application/application/settings.py file to disable debug mode. 


 

https://www.memory-lovers.blog/entry/2018/07/08/205820
Mod WSGI is complicated.

Find the wsgi config that you discovered 

 

Updates

Occasionally there will be a need for pulls to the server.

To do this goto 

cd /var/www/html/invatron.com/git pullsource/env/bin/activate python application/manage.py collectstatic


We will need to pull the data from the dev site, which is just using the links from before 

going live. 

db.sqlite should go to invatron.com/application/

media.zip should go to public_html and then unzipped (we'll have to remove the previous version)



Update page_cms

When we've updated the content management system we will need to update it on the server.

cd /var/www/html/invatron.com/source /env/bin/activatepip uninstall page_cmspip install libs/page_cms-2.0.25.tar.gz  python application/manage.py collectstatic