A Spring Boot application for local Bike Hire Businesses Around Campus For fast and efficient Service delivery.
Live Demo: https://comp493-barasa-peter.duckdns.org/
- Prerequisites
- Installation
- Database Configuration
- Application Deployment
- Production Configuration
- Nginx Reverse Proxy Setup
- SSL/HTTPS Configuration
- Service Management
- Ubuntu/Debian-based server
- SSH access to your server
- Domain name (for production deployment)
- Maven (for building the application)
SSH into your instance VPS and install Java JDK 25:
sudo apt update
sudo apt install -y openjdk-25-jdk
java -versionInstall PostgreSQL database server:
sudo apt install -y postgresql postgresql-contribSwitch to the PostgreSQL user and access the database:
sudo -i -u postgres
psqlCreate the application database:
CREATE DATABASE speedy;Update the postgres user password:
\password postgresEnter and confirm your new password when prompted.
Edit the PostgreSQL configuration file:
sudo nano /etc/postgresql/*/main/pg_hba.confEnsure the following line is present for local connections:
local all all md5
Restart PostgreSQL to apply changes:
sudo systemctl restart postgresqlOn your local machine, build the Spring Boot application:
./mvnw clean packageThis generates the JAR file at:
target/myapp-0.0.1.jar
Copy the JAR file to your EC2 instance:
scp -i pem-key.pem target/myapp-0.0.1.jar ubuntu@EC2_PUBLIC_IP:/home/ubuntu/app.jarClone the repository on your server:
git clone https://github.com/barasapeter/SPEEDY.gitInstall required dependencies:
sudo apt install -y openjdk-17-jdk maven nginxVerify installations:
java -version
nginx -vImportant: Never run production applications from a git directory.
sudo mkdir -p /opt/speedy
sudo mv ~/SPEEDY/speedy-0.0.1-SNAPSHOT.jar /opt/speedy/speedy.jar
sudo chown -R ubuntu:ubuntu /opt/speedyDO NOT hardcode credentials in your source code.
Create a production configuration file:
nano application-prod.propertiesAdd the following configuration:
spring.application.name=speedy
# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/db-name
spring.datasource.username=username
spring.datasource.password=your-password
# JPA/Hibernate Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# Session Management
spring.session.jdbc.initialize-schema=always
# Security
spring.security.user.name=name-here
spring.security.user.password=secret-here
# Server Configuration
server.address=0.0.0.0
server.port=8080
# M-Pesa Integration (Environment Variables)
mpesa.consumer-key=${MPESA_CONSUMER_KEY}
mpesa.consumer-secret=${MPESA_CONSUMER_SECRET}
mpesa.shortcode=${MPESA_SHORTCODE}
mpesa.online-passkey=${MPESA_ONLINE_PASSKEY}
mpesa.base-url=${MPESA_BASE_URL}
mpesa.callback-url=${MPESA_CALLBACK_URL}Create a service file for automatic startup:
sudo nano /etc/systemd/system/speedy.servicePaste the following configuration:
[Unit]
Description=Speedy Spring Boot Application
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/opt/speedy
ExecStart=/usr/bin/java -jar /opt/speedy/speedy.jar
Restart=always
RestartSec=5
SuccessExitStatus=143
Environment=SPRING_PROFILES_ACTIVE=prod
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable speedy
sudo systemctl start speedyCheck service status:
systemctl status speedyEdit your Spring configuration:
nano ~/SPEEDY/src/main/resources/application.propertiesAdd or update:
server.address=127.0.0.1
server.port=8080Rebuild and redeploy:
./mvnw clean package -DskipTests
sudo mv target/speedy-0.0.1-SNAPSHOT.jar /opt/speedy/speedy.jar
sudo systemctl restart speedyCreate Nginx configuration:
sudo nano /etc/nginx/sites-available/speedyAdd the following (replace comp493-barasa-peter.duckdns.org with your actual domain):
server {
listen 80;
server_name comp493-barasa-peter.duckdns.org www.comp493-barasa-peter.duckdns.org;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
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;
}
}Enable the site:
sudo ln -s /etc/nginx/sites-available/speedy /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxYour application should now be accessible at:
http://comp493-barasa-peter.duckdns.org
Install Certbot for Let's Encrypt SSL certificates (FREE):
sudo apt install -y certbot python3-certbot-nginxRun Certbot to automatically configure SSL:
sudo certbot --nginx -d comp493-barasa-peter.duckdns.org -d www.comp493-barasa-peter.duckdns.orgFollow the prompts to complete the SSL setup.
Verify that certificate auto-renewal works:
sudo certbot renew --dry-runYour application is now accessible via HTTPS:
https://comp493-barasa-peter.duckdns.org
Check service status:
systemctl status speedyView logs:
sudo journalctl -u speedy -fRestart service:
sudo systemctl restart speedyStop service:
sudo systemctl stop speedyStart service:
sudo systemctl start speedy- Never commit sensitive credentials to version control
- Use environment variables for API keys and secrets
- Keep your system and dependencies updated
- Regularly monitor application logs
- Use strong passwords for database and admin accounts
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
For issues and questions, please open an issue on the GitHub repository.