Notice: These instructions are for Rocky Linux 9/8, but with small adjustments can be used on any.
Install the crab language (RHEL distributions):
sudo dnf install rust rust-src cargo
For non-RHEL distributions:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Create new project using cargo
and give permission to webmaster
user:
cd /var/www/
sudo cargo new hello-rocket --bin
sudo chown -R webmaster:webmaster hello-rocket
cd hello-rocket/
Add rocket framework:
echo -e 'rocket = { version = "=0.5.0-rc.3", features = ["secrets", "tls", "json", "http2", "uuid"] }\n' >> Cargo.toml
Add some basic website code nano src/main.rs
:
#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
Add configuration file nano Rocket.toml
:
## defaults for _all_ profiles
[default]
#address = "127.0.0.1"
limits = { form = "64 kB", json = "1 MiB" }
## set only when compiled in debug mode, i.e, `cargo build`
[debug]
port = 9000
## only the `json` key from `default` will be overridden; `form` will remain
limits = { json = "10MiB" }
secret_key = "czEyUm5iNkdNS1pid1RYOWEyTkc2Y0RJemZuV09oOFcK"
## set only when compiled in release mode, i.e, `cargo build --release`
[release]
port = 8000
ip_header = false
secret_key = "VnEzeGlVQXBRRXlmTnowMkNwaXFpY2ZveHZ3OG5jWWgK"
Build web application:
cargo build
To build for production: cargo build --release
Allow httpd to use the local server as proxy:
setsebool -P httpd_can_network_connect 1
Run rocket web-server (to view session type tmux at
in the shell):
tmux new-session -d -s "rocket" cargo run