Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Deploy Get_Server on VPS? #35

Open
semihpolat opened this issue Feb 5, 2021 · 3 comments
Open

How to Deploy Get_Server on VPS? #35

semihpolat opened this issue Feb 5, 2021 · 3 comments

Comments

@semihpolat
Copy link

I am a fan of GetX and I wanna start to use Get_server for my backend side. Currently I use node.js I really wonder how can we deploy this framework on VPS?

@smjxpro
Copy link

smjxpro commented Feb 12, 2021

Here's how you can deploy your get_server or any Dart server-side app on Ubuntu VPS:

Create, Compile and Run Your Project On The Local Machine

  1. Install the Dart SDK on your local machine by following the official docs here: https://dart.dev/get-dart
  2. Create your project: dart create your_project_name
  3. Compile your project in native binary using: dart compile exe bin/your_project_name.dart and you should get a file with .exe extension (your_project_name.exe)
  4. Confirm that your app is running by: ./your_project_name.exe and visiting http://localhost:8080

If everything is ok, then move on to the next part.

On The VPS

  1. Upload the exe file to your VPS. Let's say on /home/user/projects directory.
  2. Optionally you can confirm that it's also working on your server by running ./your_project_name.exe and visiting http://your_vps_ip:8080*

Configure systemd Service

  1. Create a systemd service by sudo nano /etc/systemd/system/your_project_name.service and pasting the following:
[Unit]
Description=My Dart Server App

[Service]
User=user
WorkingDirectory=/home/user/projects
ExecStart=/home/user/projects/your_project_name.exe
Restart=always

[Install]
WantedBy=multi-user.target
  1. Enable the service: sudo systemctl enable your_project_name
  2. Restart systemd daemon: sudo systemctl daemon-reload
  3. Start the service: sudo service your_project_name start
  4. Check if everything is ok and your service is running properly: sudo service your_project_name status

Configure nginx Server Block and Proxy Pass

  1. Create a nginx server block by sudo nano /etc/nginx/sites-available/your_project_name.conf and pasting the following:
server {
  listen 80;
  server_name your_domain_name;
  root /home/user/projects;

  location / {
    try_files $uri @proxy;
  }

  location @proxy {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
  }
}

  1. Enable the server block: sudo ln -s /etc/nginx/sites-available/your_project_name.conf /etc/nginx/sites-enabled/your_project_name.conf
  2. Test your nginx configuration: sudo nginx -t
  3. Restart nginx: sudo service nginx reload

That's it! Now you can visit your_domain_name to see your shiny new get_server dart app in full effect on the web.
Additionally, you can secure your app using Let's Encrypt SSL using certbot: sudo certbot -d your_domain

Here's the live example: http://getxserver.smj.xyz/
And here's the example repo: https://github.com/smjxpro/get_server_boot

  • You may need to change the file permission(sudo chmod 777 your_project_name.exe) and disable firewall or open port 8080.

@jonataslaw
Copy link
Owner

Here's how you can deploy your get_server or any Dart server-side app on Ubuntu VPS:

Create, Compile and Run Your Project On The Local Machine

  1. Install the Dart SDK on your local machine by following the official docs here: https://dart.dev/get-dart
  2. Create your project: dart create your_project_name
  3. Compile your project in native binary using: dart compile exe bin/your_project_name.dart and you should get a file with .exe extension (your_project_name.exe)
  4. Confirm that your app is running by: ./your_project_name.exe and visiting http://localhost:8080

If everything is ok, then move on to the next part.

On The VPS

  1. Upload the exe file to your VPS. Let's say on /home/user/projects directory.
  2. Optionally you can confirm that it's also working on your server by running ./your_project_name.exe and visiting http://your_vps_ip:8080*

Configure systemd Service

  1. Create a systemd service by sudo nano /etc/systemd/system/your_project_name.service and pasting the following:
[Unit]
Description=My Dart Server App

[Service]
User=user
WorkingDirectory=/home/user/projects
ExecStart=/home/user/projects/your_project_name.exe
Restart=always

[Install]
WantedBy=multi-user.target
  1. Enable the service: sudo systemctl enable your_project_name
  2. Restart systemd daemon: sudo systemctl daemon-reload
  3. Start the service: sudo service your_project_name start
  4. Check if everything is ok and your service is running properly: sudo service your_project_name status

Configure nginx Server Block and Proxy Pass

  1. Create a nginx server block by sudo nano /etc/nginx/sites-available/your_project_name.conf and pasting the following:
server {
  listen 80;
  server_name your_domain_name;
  root /home/user/projects;

  location / {
    try_files $uri @proxy;
  }

  location @proxy {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
  }
}
  1. Enable the server block: sudo ln -s /etc/nginx/sites-available/your_project_name.conf /etc/nginx/sites-enabled/your_project_name.conf
  2. Test your nginx configuration: sudo nginx -t
  3. Restart nginx: sudo service nginx reload

That's it! Now you can visit your_domain_name to see your shiny new get_server dart app in full effect on the web.
Additionally, you can secure your app using Let's Encrypt SSL using certbot: sudo certbot -d your_domain

Here's the live example: http://getxserver.smj.xyz/
And here's the example repo: https://github.com/smjxpro/get_server_boot

  • You may need to change the file permission(sudo chmod 777 your_project_name.exe) and disable firewall or open port 8080.

Nice tutorial <3

@jonataslaw jonataslaw pinned this issue May 10, 2021
@voipworld
Copy link

very nice tuto!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants