Forum in maintenance, we will back soon 🙂
Hosting fast API on VPS server
@dassa did you get this working?
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack
Mr hassan. I changed my Hostings to contobo vps. I use Webmin and virtual min as discussed with you in Discord. But it is difficult to host my fast API in a virtual server. I tried so many times. but no luck. Can you guide me?
@dassa I mentioned that PythonFast API can't be hosted directly through the UI on webmin.
You will need to host the Ubuntu server manually. something like this:
# Step 1: Install Python and FastAPI on Webmin Server
# Connect to your Webmin server via SSH
sudo apt update
sudo apt install python3 python3-pip python3-venv
# Create a Python virtual environment and activate it
navigate to your preferred directory where the API files are, then:
python3 -m venv fastapi_env
source fastapi_env/bin/activate
# Install FastAPI and Uvicorn (ASGI server)
pip install fastapi uvicorn
# Step 2: Set Up Systemd Service for FastAPI
# Create a systemd service file for FastAPI
sudo tee /etc/systemd/system/fastapi.service > /dev/null <<EOF
[Unit]
Description=FastAPI application
After=network.target
[Service]
User=$USER
Group=www-data
WorkingDirectory=/home/$USER/myfastapiapp
ExecStart=/home/$USER/fastapi_env/bin/uvicorn main:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable and start the FastAPI service
sudo systemctl daemon-reload
sudo systemctl enable fastapi
sudo systemctl start fastapi
# Step 3: Install and Configure Nginx
# Install Nginx
sudo apt install nginx
# Create a new Nginx config file for FastAPI
sudo tee /etc/nginx/sites-available/fastapi > /dev/null <<EOF
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
# Enable the Nginx configuration and restart Nginx
sudo ln -s /etc/nginx/sites-available/fastapi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
# Step 4: Manage FastAPI with Webmin
# Go to Webmin at http://yourdomain.com:10000/ and log in.
# Use Webmin to manage services like Nginx and systemd.
# Step 5: Access the FastAPI App
# Visit your FastAPI app at http://yourdomain.com/
Is there any method like using GitHub to push the API to the host whenever I update the API in GitHub like you show in Digital Ocean Host?
I developed a tool to automate the process of deploying and updating API on a VPS server, you can check the project here:
hassancs91/Python-FastAPI-Auto-Deploy (github.com)
Mr Hasan, what is this error.
Setting up SSL with Let's Encrypt...
Command 'sudo certbot --nginx --non-interactive --agree-tos --email dhdassanayaka@gmail.com -d fastapi.ceeveeglobal.com' failed with exit status 1
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Some challenges have failed.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.
Also, I need to know automatically pushing updates will work or not with this? If yes, when I changed my VPS root password, did it affect the automatic update procedure?
Also please recommend any resources to learn completely about VPS and settings.
@dassa yes you can update the API with this tool. make sure to update the root password if you change it.
I will prepare a short course on linux management, it is a good idea!