570 lines
11 KiB
Markdown
570 lines
11 KiB
Markdown
# WebGIS Poverty Mapping - Deployment Guide
|
|
|
|
**Version:** 1.0
|
|
**Last Updated:** May 2026
|
|
|
|
## Table of Contents
|
|
|
|
1. [Prerequisites](#prerequisites)
|
|
2. [Installation Steps](#installation-steps)
|
|
3. [Database Setup](#database-setup)
|
|
4. [Configuration](#configuration)
|
|
5. [Testing](#testing)
|
|
6. [Deployment Checklist](#deployment-checklist)
|
|
7. [Troubleshooting](#troubleshooting)
|
|
8. [Maintenance](#maintenance)
|
|
|
|
---
|
|
|
|
## Prerequisites
|
|
|
|
### System Requirements
|
|
|
|
- **Server:** Apache 2.4 or higher (with mod_rewrite enabled)
|
|
- **PHP:** 7.4 or higher
|
|
- **Database:** MySQL 5.7+ or MariaDB 10.3+
|
|
- **OS:** Linux (Ubuntu 18.04 LTS recommended) or Windows with XAMPP
|
|
|
|
### Required Software
|
|
|
|
```bash
|
|
# Ubuntu/Debian
|
|
sudo apt-get update
|
|
sudo apt-get install -y apache2 php php-mysql php-gd php-json mysql-server
|
|
|
|
# Verify installations
|
|
php -v
|
|
mysql --version
|
|
apache2ctl -v
|
|
```
|
|
|
|
### Browser Support
|
|
|
|
- Chrome 90+
|
|
- Firefox 88+
|
|
- Safari 14+
|
|
- Edge 90+
|
|
|
|
---
|
|
|
|
## Installation Steps
|
|
|
|
### Step 1: Prepare Web Directory
|
|
|
|
```bash
|
|
# For Ubuntu/Linux
|
|
sudo mkdir -p /var/www/html/webgis
|
|
sudo chown -R www-data:www-data /var/www/html/webgis
|
|
cd /var/www/html/webgis
|
|
|
|
# For Windows XAMPP
|
|
# Create folder: C:\xampp\htdocs\webgis\
|
|
cd C:\xampp\htdocs\webgis\
|
|
```
|
|
|
|
### Step 2: Copy Application Files
|
|
|
|
```bash
|
|
# Copy all application files to web directory
|
|
cp -r /path/to/application/* /var/www/html/webgis/
|
|
|
|
# Set proper permissions (Linux only)
|
|
sudo chmod -R 755 /var/www/html/webgis/
|
|
sudo chmod -R 777 /var/www/html/webgis/logs/
|
|
sudo chmod -R 777 /var/www/html/webgis/data/
|
|
```
|
|
|
|
### Step 3: Enable Apache Modules (Linux)
|
|
|
|
```bash
|
|
sudo a2enmod rewrite
|
|
sudo a2enmod headers
|
|
sudo a2enmod php*
|
|
sudo systemctl restart apache2
|
|
```
|
|
|
|
### Step 4: Create Virtual Host (Optional - Linux)
|
|
|
|
Create `/etc/apache2/sites-available/webgis.conf`:
|
|
|
|
```apache
|
|
<VirtualHost *:80>
|
|
ServerName webgis.local
|
|
ServerAdmin admin@webgis.local
|
|
DocumentRoot /var/www/html/webgis
|
|
|
|
<Directory /var/www/html/webgis>
|
|
Options Indexes FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/webgis-error.log
|
|
CustomLog ${APACHE_LOG_DIR}/webgis-access.log combined
|
|
</VirtualHost>
|
|
```
|
|
|
|
Enable the site:
|
|
```bash
|
|
sudo a2ensite webgis.conf
|
|
sudo systemctl reload apache2
|
|
```
|
|
|
|
---
|
|
|
|
## Database Setup
|
|
|
|
### Step 1: Start MySQL Service
|
|
|
|
```bash
|
|
# Linux
|
|
sudo systemctl start mysql
|
|
|
|
# Windows (XAMPP)
|
|
# Start MySQL from XAMPP Control Panel
|
|
```
|
|
|
|
### Step 2: Run Setup Script
|
|
|
|
```bash
|
|
# Access the setup script via browser
|
|
http://localhost/webgis/setup_db.php
|
|
|
|
# OR run via command line
|
|
php /var/www/html/webgis/setup_db.php
|
|
```
|
|
|
|
**Expected Output:**
|
|
```
|
|
=== WebGIS Poverty Mapping - Database Setup ===
|
|
|
|
✓ Database 'webgis_unified' ready
|
|
✓ Table 'data_unified' created
|
|
✓ Table 'audit_log' created
|
|
✓ Table 'ref_kondisi_rumah' created
|
|
✓ Table 'ref_status_bantuan' created
|
|
✓ Table 'ref_sumber_penghasilan' created
|
|
✓ Table 'data_statistics' created
|
|
✓ Table 'users' created
|
|
✓ Trigger 'trg_data_unified_insert' created
|
|
✓ Trigger 'trg_data_unified_update' created
|
|
✓ Trigger 'trg_data_unified_delete' created
|
|
✓ View 'v_data_summary' created
|
|
✓ View 'v_poor_house_analysis' created
|
|
|
|
=== Setup Selesai ===
|
|
Database: webgis_unified
|
|
Tables: 9 (data_unified, audit_log, ref_kondisi_rumah, ref_status_bantuan, ref_sumber_penghasilan, data_statistics, users, + 2 views)
|
|
Triggers: 3 (INSERT, UPDATE, DELETE)
|
|
Ready for production use!
|
|
```
|
|
|
|
### Step 3: Verify Database
|
|
|
|
```bash
|
|
# Connect to MySQL
|
|
mysql -u root -p
|
|
|
|
# List databases
|
|
SHOW DATABASES;
|
|
|
|
# Select database
|
|
USE webgis_unified;
|
|
|
|
# List tables
|
|
SHOW TABLES;
|
|
|
|
# Check table structure
|
|
DESCRIBE data_unified;
|
|
```
|
|
|
|
---
|
|
|
|
## Configuration
|
|
|
|
### Step 1: Update db.php (if needed)
|
|
|
|
File: `db.php`
|
|
|
|
```php
|
|
<?php
|
|
$conn = new mysqli("localhost", "root", "", "webgis_unified");
|
|
|
|
if ($conn->connect_error) {
|
|
die("Koneksi gagal: " . $conn->connect_error);
|
|
}
|
|
|
|
$conn->set_charset("utf8mb4");
|
|
?>
|
|
```
|
|
|
|
### Step 2: Configure PHP Settings
|
|
|
|
Edit `php.ini`:
|
|
|
|
```ini
|
|
; Increase upload file size
|
|
upload_max_filesize = 100M
|
|
post_max_size = 100M
|
|
|
|
; Set timezone
|
|
date.timezone = "Asia/Jakarta"
|
|
|
|
; Enable extensions
|
|
extension=mysqli
|
|
extension=json
|
|
|
|
; Error reporting (development)
|
|
error_reporting = E_ALL
|
|
display_errors = On
|
|
|
|
; Error reporting (production)
|
|
error_reporting = E_ALL
|
|
display_errors = Off
|
|
log_errors = On
|
|
error_log = /var/log/php/error.log
|
|
```
|
|
|
|
### Step 3: Create .htaccess (if needed)
|
|
|
|
File: `.htaccess`
|
|
|
|
```apache
|
|
<IfModule mod_rewrite.c>
|
|
RewriteEngine On
|
|
|
|
# CORS headers (if needed for API)
|
|
Header set Access-Control-Allow-Origin "*"
|
|
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
|
|
Header set Access-Control-Allow-Headers "Content-Type"
|
|
</IfModule>
|
|
```
|
|
|
|
### Step 4: Create logs Directory
|
|
|
|
```bash
|
|
mkdir -p /var/www/html/webgis/logs
|
|
chmod 777 /var/www/html/webgis/logs
|
|
```
|
|
|
|
---
|
|
|
|
## Testing
|
|
|
|
### Step 1: Run Database Tests
|
|
|
|
```bash
|
|
# Access via browser
|
|
http://localhost/webgis/TESTS.php
|
|
|
|
# OR command line
|
|
php /var/www/html/webgis/TESTS.php
|
|
```
|
|
|
|
Expected results: All tests should pass ✓
|
|
|
|
### Step 2: Test API Endpoints
|
|
|
|
```bash
|
|
# Test GET endpoint
|
|
curl "http://localhost/webgis/get_improved.php?limit=10"
|
|
|
|
# Test POST endpoint (Create)
|
|
curl -X POST http://localhost/webgis/save_improved.php \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"tipe":"point","nama":"Test","latitude":-0.0554,"longitude":109.3494}'
|
|
|
|
# Test GET with filter
|
|
curl "http://localhost/webgis/get_improved.php?tipe=worship"
|
|
```
|
|
|
|
### Step 3: Test Web Interface
|
|
|
|
1. Open browser: `http://localhost/webgis/`
|
|
2. Verify map loads
|
|
3. Test adding new feature
|
|
4. Test editing feature
|
|
5. Test deleting feature
|
|
6. Verify data appears on map
|
|
|
|
---
|
|
|
|
## Deployment Checklist
|
|
|
|
- [ ] All prerequisite software installed
|
|
- [ ] Web directory created with proper permissions
|
|
- [ ] Application files copied to web directory
|
|
- [ ] Apache modules enabled (Linux)
|
|
- [ ] Virtual host configured (optional)
|
|
- [ ] MySQL service running
|
|
- [ ] Database setup script executed successfully
|
|
- [ ] All tables created correctly
|
|
- [ ] Triggers and views created
|
|
- [ ] Reference data populated
|
|
- [ ] PHP configuration updated
|
|
- [ ] .htaccess file created
|
|
- [ ] logs directory created and writable
|
|
- [ ] All database tests pass
|
|
- [ ] API endpoints tested
|
|
- [ ] Web interface tested
|
|
- [ ] Backups configured
|
|
- [ ] Security hardening done
|
|
- [ ] Production deployment completed
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Issue: Connection Refused
|
|
|
|
**Error:** `Could not connect to MySQL`
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Check MySQL status
|
|
sudo systemctl status mysql
|
|
|
|
# Start MySQL
|
|
sudo systemctl start mysql
|
|
|
|
# Check if MySQL is listening
|
|
sudo netstat -tlnp | grep mysql
|
|
```
|
|
|
|
### Issue: Permission Denied
|
|
|
|
**Error:** `Permission denied` on logs or data folder
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Fix permissions
|
|
sudo chown -R www-data:www-data /var/www/html/webgis/
|
|
sudo chmod -R 755 /var/www/html/webgis/
|
|
sudo chmod -R 777 /var/www/html/webgis/logs/
|
|
sudo chmod -R 777 /var/www/html/webgis/data/
|
|
```
|
|
|
|
### Issue: 404 Error
|
|
|
|
**Error:** `The requested resource was not found`
|
|
|
|
**Solution:**
|
|
```bash
|
|
# Check if mod_rewrite is enabled
|
|
sudo a2enmod rewrite
|
|
|
|
# Check virtual host configuration
|
|
sudo apache2ctl configtest
|
|
|
|
# Restart Apache
|
|
sudo systemctl restart apache2
|
|
```
|
|
|
|
### Issue: Database Import Error
|
|
|
|
**Error:** `Unknown collation` or charset issues
|
|
|
|
**Solution:**
|
|
```bash
|
|
# When running setup script, ensure UTF-8 is used
|
|
# In db.php, add:
|
|
$conn->set_charset("utf8mb4");
|
|
|
|
# Or in SQL:
|
|
SET NAMES utf8mb4;
|
|
```
|
|
|
|
### Issue: CORS Error in Browser
|
|
|
|
**Error:** `Access to XMLHttpRequest blocked by CORS policy`
|
|
|
|
**Solution:**
|
|
Add to `.htaccess`:
|
|
```apache
|
|
<IfModule mod_headers.c>
|
|
Header set Access-Control-Allow-Origin "*"
|
|
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, DELETE, PUT"
|
|
Header set Access-Control-Allow-Headers "Content-Type"
|
|
</IfModule>
|
|
```
|
|
|
|
---
|
|
|
|
## Maintenance
|
|
|
|
### Daily Tasks
|
|
|
|
1. Check application logs for errors
|
|
2. Monitor disk space
|
|
3. Verify database connectivity
|
|
|
|
### Weekly Tasks
|
|
|
|
1. Review access logs
|
|
2. Check for failed transactions
|
|
3. Validate data integrity
|
|
|
|
### Monthly Tasks
|
|
|
|
1. Run full database backup
|
|
2. Test backup restoration
|
|
3. Review performance metrics
|
|
4. Update documentation
|
|
|
|
### Quarterly Tasks
|
|
|
|
1. Security audit
|
|
2. Performance optimization
|
|
3. Database maintenance (OPTIMIZE, ANALYZE)
|
|
4. Software updates
|
|
|
|
### Backup Procedure
|
|
|
|
```bash
|
|
# Manual backup
|
|
mysqldump -u root -p webgis_unified > backup_$(date +%Y%m%d).sql
|
|
|
|
# Automated daily backup (add to crontab)
|
|
0 2 * * * mysqldump -u root -pYOURPASSWORD webgis_unified > /backup/webgis_$(date +\%Y\%m\%d).sql
|
|
|
|
# List backups
|
|
ls -la /backup/
|
|
|
|
# Restore from backup
|
|
mysql -u root -p webgis_unified < backup_20260520.sql
|
|
```
|
|
|
|
### Database Optimization
|
|
|
|
```bash
|
|
# Connect to MySQL
|
|
mysql -u root -p
|
|
|
|
# Select database
|
|
USE webgis_unified;
|
|
|
|
# Optimize tables
|
|
OPTIMIZE TABLE data_unified;
|
|
OPTIMIZE TABLE audit_log;
|
|
|
|
# Analyze tables
|
|
ANALYZE TABLE data_unified;
|
|
ANALYZE TABLE audit_log;
|
|
|
|
# Check table
|
|
CHECK TABLE data_unified;
|
|
|
|
# View table status
|
|
SHOW TABLE STATUS;
|
|
```
|
|
|
|
---
|
|
|
|
## Security Hardening
|
|
|
|
### 1. Change Default Credentials
|
|
|
|
```bash
|
|
# MySQL - change root password
|
|
mysql -u root
|
|
ALTER USER 'root'@'localhost' IDENTIFIED BY 'StrongPassword123!';
|
|
FLUSH PRIVILEGES;
|
|
```
|
|
|
|
### 2. Create Application User
|
|
|
|
```sql
|
|
-- Create dedicated user for application
|
|
CREATE USER 'webgis_user'@'localhost' IDENTIFIED BY 'AppPassword123!';
|
|
|
|
-- Grant permissions
|
|
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER ON webgis_unified.*
|
|
TO 'webgis_user'@'localhost';
|
|
|
|
FLUSH PRIVILEGES;
|
|
```
|
|
|
|
### 3. Update db.php
|
|
|
|
```php
|
|
<?php
|
|
$conn = new mysqli("localhost", "webgis_user", "AppPassword123!", "webgis_unified");
|
|
?>
|
|
```
|
|
|
|
### 4. Disable Directory Listing
|
|
|
|
Add to `.htaccess`:
|
|
```apache
|
|
Options -Indexes
|
|
```
|
|
|
|
### 5. Set PHP Configuration
|
|
|
|
```ini
|
|
; Disable dangerous functions
|
|
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec
|
|
|
|
; Limit file uploads
|
|
upload_max_filesize = 10M
|
|
post_max_size = 10M
|
|
|
|
; Session security
|
|
session.secure = On
|
|
session.httponly = On
|
|
session.samesite = Strict
|
|
```
|
|
|
|
---
|
|
|
|
## Performance Optimization
|
|
|
|
### Enable Database Query Caching
|
|
|
|
```ini
|
|
; my.cnf
|
|
query_cache_type = 1
|
|
query_cache_size = 64M
|
|
```
|
|
|
|
### Add Indexes
|
|
|
|
```sql
|
|
-- Already included in setup script, verify:
|
|
SHOW INDEXES FROM data_unified;
|
|
```
|
|
|
|
### Optimize Queries
|
|
|
|
```php
|
|
// Use LIMIT for large result sets
|
|
$limit = 1000;
|
|
$offset = 0;
|
|
$sql = "SELECT * FROM data_unified LIMIT $limit OFFSET $offset";
|
|
```
|
|
|
|
---
|
|
|
|
## Documentation Files
|
|
|
|
All documentation is included in the application:
|
|
|
|
- `SKPL_SRS_WebGIS_PovertyMapping.md` - System requirements specification
|
|
- `API_DOCUMENTATION.md` - API endpoint documentation
|
|
- `DEPLOYMENT_GUIDE.md` - This file
|
|
- `README.md` - Quick start guide
|
|
|
|
---
|
|
|
|
## Support & Contact
|
|
|
|
For technical support or issues:
|
|
|
|
1. Check logs: `/var/www/html/webgis/logs/error.log`
|
|
2. Review troubleshooting section above
|
|
3. Contact development team
|
|
|
|
**Last Updated:** May 20, 2026
|
|
**Version:** 1.0
|
|
**Status:** Production Ready
|