How to run Rust on server?

I want to run my build-result of rust on server but when i run its port always :8000. How to set port in Rust? And How to run Rust on bacground of server?

Hot to change the port depends on the framework/server library you use. To bint to a port less than 1024 you need root permissions at least temporarily. If you do not know how to acquire or drop them, I'd suggest to just leave it as is and start a reverse proxy which proxies from 80 to 8000.

This depends on your operating system. On windows create a service, on linux deamonize your project and let its lifecycle be managed by systemd, upstart, openRC or whatever init system you use on your box.

Summary: Since you asked how to do the background thing, I strongly suggest to not change your port right now, stick to the reverse proxy approach until you actually know what you are doing. Of course you still need to start your application as a service via the means of your system.

1 Like

I use Rocket Framework. I have been deployed on server and I also have been built the app. I try to make which contain cd /root/trashbuddy/ && ROCKET_ENV=production ./target/release/trashbuddy but when i run it via systemd, nothing happened

What do you mean by nothing happened? How does your unit file look like? Where does it live? Any errors in the logs? How did you start the service? Have you placed the binary in a place where systemd can read it? Have I forgotten some questions?

Did you try netstat -na | grep 8000 or ps aux | grep your_process commands to check if the program startup successfully?

and you can add more logs to check whether program start up normally or stuck somewhere