28.02.2025
You can make a repository with a project on GitHub hidden and after changing the project files on a local PC, the project can be updated on the VM using the command – ‘git pull’, how to do this will be discussed in point 16, also to work with a hidden repository, you need to authenticate on GitHub through the VM, this will be done in point 9.
Next, create a hidden (this instruction is designed for the repository to be hidden) or open repository of the project in your GitHub account, called – ‘crystal’. You can ‘fork’ (fork repository, can’t be hidden) or import the project from repository CRYSTAL v1.0.
SSH key, needed to connect to the VM from another PC, in this case via the terminal in Win 11. Win 11 comes with a built-in OpenSSH client, which can be used to generate SSH keys.
To create an SSH key, press – ‘Win+R’ on the keyboard, then enter – ‘cmd’ in the window that opens and press – ‘Enter’, the terminal will open, enter the command in it:
ssh-keygen -t ed25519
Next, enter the name of the key:
crystal_key
Screen 1.
After entering the key, press – ‘Enter’.
You will be asked to create a password, this is not mandatory, but it will increase security, since each time you connect to the VM, you will need to enter the password. The default key location is ‘C:\Users\UserName\’. After creating the key, two files will appear, one with the .pub extension (public key) and one without the extension (private key), move the files to the address – ‘C:\Users\UserName\.ssh\’. In the future, the public key will be added to the VM on the cloud service. Using a private key, a connection to the VM will be made via the terminal in Win 11.
Next, open the menu on the left and go to the section – ‘Security groups’, then select – ‘Create a security group’.
Availability zone – ru.AZ-1 (can be any, but the security group and VM must have the same availability zone).
Name – сrystal.
Description – can be left blank.
Tags – can be left blank.
Description of ports:
443 – access via HTTPS.
80 – access via HTTP.
22 – to access the VM via the SSH key created earlier.
In the ‘Inbound Traffic Rules’ section, click ‘Add Rule’ and fill in the items as in the example on the screenshot № 2.
Copy the IP below and enter it in the ‘Source’ field:
0.0.0.0/0
In the ‘Description’ field, enter:
HTTPS IPv4
Screen 2.
After filling in, click the button – ‘Create’.
Next, add the rest of the incoming traffic rules. The result should look like in screenshot № 3.
Screen 3.
Add outgoing traffic rules, as in screenshot № 4.
Screen 4.
Copy to fill the ‘Description’ field:
All egress IPv4
After adding the outgoing traffic rule, click on the button – ‘Create’ (security group).
Open the menu, section – ‘Virtual machines’, and select – ‘Create virtual machine’.
Fill in the items as in the example below.
Name – crystal.
Description – can be left blank.
Tags – can be left blank.
Availability zone – ru.AZ-1 (should be the same as in the previously created security group).
Do not create a placement group.
Public – Debian 12.
Guaranteed share of vCPU – 30%
vCPU – 2
RAM – 4
Boot disk
Name – default
Type – SSD
Size – 20GB
Do not connect to subnet.
Must be checked – ‘Connect public IP’ (An automatically created static public IP address will be connected to the VM).
IP type – Direct.
Security groups – select the previously created security group – ‘crystal’.
Host name – crystal.
Login – crystal-vm.
Select – ‘Public key’.
You can also set a password to connect to the VM via the virtual console – Cloud.ru. The connection will be available only within the Cloud.ru service, and not via the Internet, since the default is ‘PasswordAuthentication no’.
Then click – ‘Add new key’, select – ‘Load from file’, then go to the directory – ‘C:\Users\UserName\.ssh\’ and select the previously created public key – ‘crystal_key.pub’.
After adding the key file, enter in the field – ‘Name’, the key name – crystal_key.pub, then click the button – ‘Add’.
Then click the button – ‘Create’ (VM).
If successful, the VM should be created and after a while, it will be available.
You can find the public IP address of your VM in the ‘Virtual Machines’ section, in the column of the same name.
Change the sample text and enter the command in the terminal:
ssh -i C:\Users\UserName\.ssh\crystal_key crystal-vm@VMPublicIPAddress
Example command:
ssh -i C:\Users\Andrew\.ssh\crystal_key crystal-vm@55.55.55.55
After entering the command, press – ‘Enter’. If the question – ‘Are you sure you want to continue connecting (yes/no/[fingerprint])?’ enter – ‘ yes’, then enter the password that you set when creating the SSH key.
In the future, when entering commands, the question – ‘Do you want to continue? [Y/n]’ may appear, in this case, enter – ‘Y’, and then press – ‘Enter’.
sudo -i
apt update && apt -y upgrade
If a window with questions opens during installation, press the – ‘Enter’ key.
curl -fsSL https://deb.nodesource.com/setup_23.x | bash - && \apt-get install -y nodejs && nodejs -v
Enter the command:
apt-get install nginx && nginx -v
If the installation was successful, the console should show the nginx version, for example – ‘nginx version: nginx/1.22.1’.
Enter the command:
apt install git && apt install gh
Enter the command:
gh auth login
From the options provided, select – ‘GitHub.com’, then – ‘HTTPS’, then – ‘Authenticate Git with your GitHub credentials?’ – ‘Y’, then ‘Login with a web browser’, then press – Enter, there will be an error, since the work is carried out from the console.
Next, copy the link and open it in the browser from which you have already logged into your GitHub account:
https://github.com/login/device
After that, enter the code from the terminal in the window that opens, as in screenshot № 5.
Screen 5.
Click – ‘Authorize github’. If everything goes well, at the end you will see a message like in screenshot № 6.
Screen 6.
After a while, a message like this should appear in the console – ‘✓ Authentication complete.’.
Enter the command and replace the sample text with your GitHub login:
cd /var/www/ && gh repo clone YourLoginGitHub/crystal
In this instruction, the nano text editor will be used. In Debian 12 on the VM, nano is installed by default, check if this editor is installed on your system by entering the command:
nano --version
A message similar to this should appear – ‘GNU nano, version 7.2’, if it is not there, install nano using the commands that are suitable for your system or use another editor. You can enable mouse control in the editor by pressing – ‘alt + m’ (English keyboard layout must be enabled).
Enter the command:
rm /etc/nginx/sites-available/default && nano /etc/nginx/sites-available/crystal
Add the code below to the window that opens. Replace the example text in line 4 with your VM’s public IP address:
server {
listen 80;
listen [::]:80;
server_name 'add your VM's public IP address here, without apostrophes';
location /
{
root /var/www/crystal/frontend/dist;
try_files $uri $uri /index.html;
}
location /api/
{
proxy_pass http://localhost:3000/;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
After adding the code, press sequentially – ‘ctrl + x’, ‘y’, ‘Enter’.
Enter the command:
rm /etc/nginx/sites-enabled/default && ln -s /etc/nginx/sites-available/crystal /etc/nginx/sites-enabled/ && systemctl restart nginx
Enter the command:
cd /var/www/crystal/frontend && mkdir env
In the following command, add the public IP address of the VM:
echo VITE_BASE_URL=http://PublicIPAddressVM/api > ./env/.env.prodIP
Enter the command:
curl -fsSL https://get.pnpm.io/install.sh | sh - && source /root/.bashrc && pnpm -v
Enter the command:
pnpm i && pnpm buildProdIP
After successful assembly, enter the public IP address of the VM in the browser address bar, and the frontend part of the project will appear there, for example – ‘http://PublicIPAddressVM/’ (required – ‘http’, not ‘https’).
Screen 7.
Enter the command:
cd /var/www/crystal/backend && mkdir env && nano ./env/.env
Next, you need to set the value of the variable – ‘JWT_SECRET_KEY’, you can enter the value of letters and numbers yourself, or generate it in various services, for example in Nano ID.
An example of what JWT_SECRET_KEY might look like – ‘IA9bVtK6yQu1hpG2TCKCrC5h0VJmRZcZlrnZ’.
When a user registers with an email address that is the same as in the variable – ‘CREATOR_EMAIL’, the administrator mode will be enabled (editing/deleting users and posts).
Enter the data below in the window that opens, and replace the sample text with your values:
JWT_SECRET_KEY=JWT_Secret_Key
CREATOR_EMAIL=email_for_administrator_mode
After adding the code, press sequentially – ‘ctrl + x’, ‘y’, ‘Enter’.
The variable – ‘PRODUCTION_STATUS’, in the .env.prod file, determines the mode in which the server will be launched. In this case, the mode is production.
Enter the command:
echo PRODUCTION_STATUS=true > ./env/.env.prodIP
Enter the command:
pnpm i
The actions in this section will be based on the official documentation MongoDB.
Enter the command:
sudo apt-get install gnupg curl
Enter the entire command:
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
Enter the entire command:
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
Enter the command:
sudo apt-get update
Enter the command:
sudo apt-get install -y mongodb-org
Enter the entire command:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Enter the command:
sudo systemctl start mongod
Verify that it started successfully by entering the command:
sudo systemctl status mongod
If it started successfully, you should see messages like this:
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2025-01-08 15:09:54 UTC; 13s ago
Next press – ‘ctrl + c’.
sudo systemctl enable mongod
You can monitor the status of the MongoDB process for errors or important messages by monitoring the output in the file – /var/log/mongodb/mongod.log.
Enter the command:
mongosh
A console interface for interacting with databases will open, read more about mongosh.
In the interface that opens, enter the command:
show dbs
You will see a list of databases that are currently available, should appear: ‘admin’, ‘config’, ‘local’;
Then press – ‘ctrl + c’.
Enter the command:
cd /var/www/crystal/backend && sudo npm install pm2@latest -g && pnpm startProdIP && pm2 save && pm2 startup && pm2 status
Command description:
Installing PM2 – ‘sudo npm install pm2@latest -g’.
Running the file – ‘backend/src/server.js’: ‘pnpm startProd’.
Saving the PM2 process – ‘pm2 save’.
Restart the PM2 process, after rebooting the VM – ‘pm2 startup’.
The PM2 process status – ‘pm2 status’.
If the launch is successful, the process named – ‘prodIP’ should have the status – ‘online’.
Open the project in the browser, for example – ‘http://PublicIPVMAddress/’ (required – ‘http’, not “https’). Complete the registration and add a post.
Select or create any folder on the local PC, into which the project from your repository will be cloned – ‘crystal’.
Open a new terminal window and enter the command below:
cd C:\FolderName
Example: cd C:\GIT
Next, clone the repository using the GitHub CLI command:
gh repo clone YourUserNameOnGitHub/crystal
Go to the c folder project, with the command:
cd C:\GIT\crystal
Make any change in the project, for example in the file – ‘crystal\frontend\src\index.css’
After, commit the changes to the repository – ‘crystal’, on GitHub, with the command:
git add -A & git commit -m "commit" & git push -u origin main
Next, open a terminal window with the VM, update the project and build it with the command:
cd /var/www/crystal && git pull && cd /var/www/crystal/frontend && pnpm buildProdIP
Check the changes on the site, through the browser.
Share
BTC (Network BTC) - 1C2EWWeEXVhg93hJA9KovpkSd3Rn3BkcYm
Ethereum (Network ERC20) - 0x05037ecbd8bcd15631d780c95c3799861182e6b8
Comment on