paleobot / pbot-dev

Codebase and initial design documents for pbot client
MIT License
2 stars 2 forks source link

Install procedure #240

Open NoisyFlowers opened 9 months ago

NoisyFlowers commented 9 months ago

Document production install procedure

NoisyFlowers commented 9 months ago

1) initial setup https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-22-04 sudo user ufw Install git if not already Install nvm https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-22-04 Use nvm to install node v16.7.0 Install npm

2) install neo4j https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-neo4j-on-ubuntu-22-04 Install APOC (https://neo4j.com/labs/apoc/4.4/installation/) for the version of the db installed Import db as described in #46

3) If importing images from previous installation, do that now. tar.gz image directory from previous and bring that file to new machine Create a directory somewhere that will hold the images. The image directory must be accessible by whatever user runs the node instance. The easiest way to do this is just put it in the home directory of that user. I don't see a problem with this, since that same user will be the one running pm2. Extract the images into that directory Make sure to configure the api server's .env file for this directory These images will all have link values that point to the old server. Change them now with

MATCH 
    (i:Image)
SET 
    i.link = replace(i.link, '<old server domain or ip>', '<new server domain or ip>')

4) install nginx https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-22-04

Make sure it works. Create a server block like this. We will either copy build files to the root below or change the root 
to point to where they are.
    server {

        root /var/www/pbot-client/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name pbot.paleobiodb.org;

        location / {
            try_files $uri /index.html;  
        }

        #These take the place of "proxy": "http://localhost:4001/" in package.json
        location /graphql {
            proxy_pass http://localhost:4001;
        }

        location /user/register {
            proxy_pass http://localhost:4001;
        }

        location /user/login {
            proxy_pass http://localhost:4001;
        }

        location /images {
            proxy_pass http://localhost:4001;
        }

        location /countries {
            proxy_pass http://localhost:4001;
        }

        location /states {
            proxy_pass http://localhost:4001;
        }
        }

5) deploy client to nginx https://www.digitalocean.com/community/tutorials/how-to-deploy-a-react-application-with-nginx-on-ubuntu-20-04 This article uses scp to copy client build files to nginx root. We could also clone the repo locally and cp from there. Or we could point nginx at the local repo's build directory. cp env.template .env and set values therein Make sure it works (can see the splash screen). Should get frownies elsewhere

6) clone pbot-api locally. I cloned into /var/www. Not sure this is the best place. /opt/pbot might be a better choice. Could also clone into home directory of user that will be running pm2. run npm install cp env.template .env and set values therein (Interestingly, I got the api working without doing this. No idea how it's accessing neo4j without the right password.) Start it up ("node index.js") Try client again. Make sure frownies are gone. Stop server.

7) install pm2 https://pm2.keymetrics.io/docs/usage/quick-start/ There is an ecosystem.config.cjs file in pbot-api. This starts both the api and the client, but we don't want to run the client this way for staging/production. Edit it to include only the api. We use nvm for node version management. You have to tell pm2 which node to use. The ecosystem.config.cjs file contains the line

interpreter: "/home/doug/.nvm/versions/node/v16.7.0/bin/node",

Adjust this accordingly.

Later versions of pm2 will also accept this syntax

interpreter: "node@16.7.0",

Use pm2 and the ecosystem file to start the api server

pm2 start ecosystem.config.cjs

8) Once this is all working and the site responds on port 80, get it set up for HTTPS with Let's Encrypt https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-22-04