Add installation/installWithoutPostgress.md
This commit is contained in:
parent
f55ee678e3
commit
3a57ab94e8
102
installation/installWithoutPostgress.md
Normal file
102
installation/installWithoutPostgress.md
Normal file
@ -0,0 +1,102 @@
|
||||
# .NET Web API Deployment with PostgreSQL on Debian 12 LXC
|
||||
|
||||
## Overview
|
||||
|
||||
This document explains the setup steps, configuration, and important changes needed to deploy and maintain your .NET Web API connected to a PostgreSQL database in a Debian 12 LXC container managed by Proxmox.
|
||||
|
||||
***
|
||||
|
||||
## Installation Steps
|
||||
|
||||
### 1. Prepare Environment
|
||||
|
||||
- Ensure Debian 12 (Bookworm) LXC container is running.
|
||||
- PostgreSQL must already be installed and running. Verify with:
|
||||
```bash
|
||||
sudo systemctl status postgresql
|
||||
```
|
||||
- Install .NET 8 SDK and runtime using the provided `install.sh` script or manually:
|
||||
```bash
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
## Configuration Files to Edit
|
||||
|
||||
### appsettings.json
|
||||
|
||||
- Located in `/opt/api/appsettings.json` or your configured application directory.
|
||||
- Configure the connection string for PostgreSQL:
|
||||
```json
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Database=apidatabase;Username=api;Password=abcd1234"
|
||||
}
|
||||
}
|
||||
```
|
||||
- Adjust `Host` if your PostgreSQL runs on a different IP or port.
|
||||
- Ensure these credentials match the PostgreSQL user and database.
|
||||
|
||||
### systemd Service File
|
||||
|
||||
- Located at `/etc/systemd/system/mydotnetapi.service`
|
||||
- Key settings:
|
||||
- `ExecStart`: Path to your currently deployed DLL, e.g.:
|
||||
```
|
||||
ExecStart=/usr/bin/dotnet /opt/api/Taekwondo.WebApi.dll
|
||||
```
|
||||
- `WorkingDirectory`: Directory of your deployed API.
|
||||
- `User`: Linux user running the service, often `www-data` or your deployment user.
|
||||
- If you update or change your DLL naming, **update `ExecStart` accordingly.**
|
||||
|
||||
***
|
||||
|
||||
## Deployment Process
|
||||
|
||||
1. Publish your .NET Web API to a folder (e.g., using `dotnet publish -c Release`).
|
||||
2. Copy the published files (especially `.dll`, `appsettings.json`) to `/opt/api` or your `WorkingDirectory`.
|
||||
3. Restart the systemd service to load the new API version:
|
||||
```bash
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl restart mydotnetapi
|
||||
```
|
||||
4. Check service logs if there are startup issues:
|
||||
```bash
|
||||
sudo journalctl -u mydotnetapi -f
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
## Testing Your API
|
||||
|
||||
- Use tools like `curl` or Postman to test your endpoints:
|
||||
```bash
|
||||
curl http://localhost:5000/api/your-endpoint
|
||||
```
|
||||
- Verify expected responses to confirm database connectivity & API functionality.
|
||||
|
||||
***
|
||||
|
||||
## Troubleshooting Tips
|
||||
|
||||
- **Status=200/CHDIR error**: Ensure the directory in `WorkingDirectory` exists and is owned by the service user:
|
||||
```bash
|
||||
sudo mkdir -p /opt/api
|
||||
sudo chown www-data:www-data /opt/api
|
||||
```
|
||||
- **Database connection errors**:
|
||||
- Check PostgreSQL is running.
|
||||
- Validate credentials and connection string.
|
||||
- Verify PostgreSQL config allows local/API user connections.
|
||||
- **Permission denied in PostgreSQL shell** is usually normal when switching users.
|
||||
|
||||
***
|
||||
|
||||
## API Best Practices Summary
|
||||
|
||||
- Use clear and versioned endpoints (e.g., `/api/v1/products`).
|
||||
- Return proper HTTP status codes.
|
||||
- Document your API (consider Swagger/OpenAPI).
|
||||
- Secure the API, especially the database credentials.
|
||||
- Test and monitor regularly.
|
||||
Loading…
x
Reference in New Issue
Block a user