Cloud Server Installation
Last updated
Last updated
Follow these steps to create a server and host the lobby server and/or the game server.
In this example, we are going to use Digital Ocean, but the server application can be hosted on any cloud provider of your choice.
If you do not have an account already, you can use this referral link to create an account, and the first two months will be free.
You will need to download these two applications in order to access your server. One is a SFTP file manager and the other is a SSH command line tool. These tools are for Windows, but there are plenty of SFTP and SSH alternatives on Mac/Linux.
WinSCP:
Putty:
When installing Putty, make sure to also install PuttyGen (it is to generate ssh keys).
After you created a Digital Ocean account and entered your credit card information, and that your account is ready to use, you are ready to create a Droplet.
1) In Droplets section, click on Create -> Droplet
2) Select the OS: I use Ubuntu 22.04
3) Choose the specs of your server
4) Choose any region (closest to you will have better performances).
5) Select a SSH key (see next section to generate a new one)
6) Select a hostname for your server (can be anything).
7) Click Create Droplet
Once your droplet is ready, the IP of your server will be displayed. You will need that IP later when creating the unity build.
To generate a key, open PuttyGen and click on generate.
Once done, save the private key file on your computer.
Then copy the public key displayed on screen to Digital Ocean.
On Digital Ocean, Add a name to your key and then click on Add SSH key.
Make sure to store your private key file in a secure place, if you lose the key you won’t be able to access your droplet.
Open WinSCP and create a new connection.
Enter the IP of your server as Host, and enter Root as the username.
The password is blank since we use a SSH key instead.
Click on Advanced, then SSH/Authentication, then select your private key file there.
This will give you access to the server files
You can unzip and upload the NodeJS code into any folder. In my demo I created this folder and uploaded all the JS code there.
/server/api
To access the command line, from WinSCP, click on Commands->Open in Putty.
Once you gain access you can navigate to the server folder with
cd /server/api
Follow the instruction to install MongoDB
If you get an error about libssl, check this to resolve it:
Start Mongo with
And make sure it is working correctly
Open mongo command line with
While mongo is running in the command line prompt, you can run mongo commands. Use this one to change to the admin database to manage users
Run these command to add mongo users. Make sure to set a different password for each, save them somewhere to use later, and note the database name (in this example its called userdb).
Create a Root user
Create a user for your app
And finally I also like to create a read-only user
If you made a mistake you can delete a user with
Use Ctrl-C at anytime to quit mongo and return to regular ubuntu command line.
Run this to install NodeJS and NPM
Install forever globally to run NodeJS as a service
Install node modules for the User API app
In WinSCP, open the config.js file to edit a few things
Change mongo_user to "api" (or any other mongo user you created for your app)
Change mongo_pass to the password your set for your api user
Change jwt_secret to any random value
In command line, try to run the app to see if it is working
If there are no error message, this means the app is working! Use ctrl-c to quit the app.
You can use forever to run NodeJS as a service so it stays on when you close the command line window
When you make any changes, or reupload the app, you can restart with
You can also check if it is running properly