Step-by-step guide to set up WordPress on DigitalOcean with REST API, permalinks, and HTTPS.
คู่มือทีละขั้นตอนสำหรับติดตั้ง WordPress บน DigitalOcean พร้อม REST API, permalinks และ HTTPS
🌐 Domain Configuration
การตั้งค่าโดเมน
Enter your domain:
wordpress.example.com
This will automatically update all commands with your domain name.
📋 Setup Progress Checklist
รายการตรวจสอบความคืบหน้า
- Create DigitalOcean Droplet
- Configure Domain DNS
- Update Server & Access
- Apache Permalink & API Setup (Critical)
- Install SSL Certificate (HTTPS)
- Force HTTPS Redirect
- Complete WordPress Setup
- Configure Permalinks
- Test REST API
- Generate Application Password
1. Create the Droplet
1. สร้าง Droplet
- Go to DigitalOcean Marketplace
- Search for "WordPress One-Click" install
- Choose your region, size, and authentication
- Create the droplet and note the IP address
Recommended: Choose at least 1GB RAM for WordPress. Enable backups for production sites.
2. Set Up Domain DNS
2. ตั้งค่า DNS ของโดเมน
Point your domain's A record to your droplet's IP address:
Type: A Record
Name: @ (or your subdomain)
Value: YOUR_DROPLET_IP
TTL: 3600
3. Update & Access the Server
3. อัปเดตและเข้าถึงเซิร์ฟเวอร์
SSH into your droplet as root and update the system:
sudo apt update && sudo apt upgrade -y
4. 🔴 Apache Permalink & API Setup (Critical)
4. 🔴 ตั้งค่า Apache Permalink & API (สำคัญ)
a. Create/Check .htaccess file:
sudo nano /var/www/html/.htaccess
Paste this content into the .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
b. Edit Apache Config to Allow .htaccess Overrides:
sudo nano /etc/apache2/sites-available/000-default.conf
Add this inside the <VirtualHost *:80> block:
<Directory /var/www/html>
AllowOverride All
</Directory>
c. Enable mod_rewrite:
sudo a2enmod rewrite
sudo systemctl reload apache2
5. Secure Your Site with HTTPS
5. รักษาความปลอดภัยด้วย HTTPS
a. Install Certbot:
sudo apt install certbot python3-certbot-apache -y
b. Run Certbot (after DNS points to your droplet):
sudo certbot --apache -d your.domain.com
Follow the prompts: Enter your email, agree to terms. Certbot will auto-configure Apache for SSL.
6. Force HTTPS (Recommended)
6. บังคับใช้ HTTPS (แนะนำ)
Add HTTPS redirect inside <VirtualHost *:80> in /etc/apache2/sites-available/000-default.conf:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Reload Apache:
sudo systemctl reload apache2
7. Complete WordPress Setup in Browser
7. ตั้งค่า WordPress ในเบราว์เซอร์
- Go to https://your.domain.com
- Complete WordPress installation (site name, admin user, password, etc.)
- Save your admin credentials securely
8. Fix Permalinks in WP Admin
8. แก้ไข Permalinks ใน WP Admin
- Go to WP Admin → Settings → Permalinks
- Choose your preferred structure (recommended: Post name)
- Click Save Changes (this triggers .htaccess rewrite)
9. Test REST API
9. ทดสอบ REST API
Visit your REST API endpoint:
https://your.domain.com/wp-json/
Expected result: Should show JSON data, not a 404 error. If you see JSON, your REST API is working!
10. Generate Application Password (for API Access)
10. สร้าง Application Password (สำหรับ API)
- Go to Users → Profile in WP Admin
- Scroll to Application Passwords section
- Enter a name (e.g., "n8n Integration", "API Access")
- Click Add New Application Password
- Save the generated password - you won't see it again!
🧪 Quick Tests & Verification
การทดสอบและตรวจสอบ
Test REST API with curl:
curl -X GET "https://your.domain.com/wp-json/wp/v2/posts" \
-H "Authorization: Basic $(echo -n 'your-username:your-app-password' | base64)"
Test Permalinks:
https://your.domain.com/sample-page/
🔧 Common Issues & Solutions
ปัญหาที่พบบ่อยและวิธีแก้ไข
404 errors on REST API:
- Check if .htaccess file exists and has correct content
- Verify Apache AllowOverride is set to "All"
- Ensure mod_rewrite is enabled
- Restart Apache:
sudo systemctl restart apache2
SSL Certificate issues:
- Ensure DNS is pointing to your droplet before running Certbot
- Check if port 80 and 443 are open
- Verify domain ownership
WordPress not loading:
- Check Apache status:
sudo systemctl status apache2 - Check error logs:
sudo tail -f /var/log/apache2/error.log - Verify file permissions:
sudo chown -R www-data:www-data /var/www/html
🎉 You're Done!
เสร็จสิ้น!
- ✅ REST API and permalinks are working
- ✅ HTTPS is enforced
- ✅ Ready for integrations (n8n, Postman, etc.)
- ✅ Application password generated for API access
Your WordPress site is now ready for production use!
📚 Quick Reference
ข้อมูลอ้างอิงด่วน
WordPress Admin: https://your.domain.com/wp-admin/
REST API Base: https://your.domain.com/wp-json/
Posts API: https://your.domain.com/wp-json/wp/v2/posts
Pages API: https://your.domain.com/wp-json/wp/v2/pages
Users API: https://your.domain.com/wp-json/wp/v2/users
Apache Config: /etc/apache2/sites-available/000-default.conf
WordPress Files: /var/www/html/
Error Logs: /var/log/apache2/error.log
Essential Commands Summary:
Update System:
sudo apt update && sudo apt upgrade -y
Enable mod_rewrite:
sudo a2enmod rewrite && sudo systemctl reload apache2
Install SSL:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d your.domain.com
Restart Apache:
sudo systemctl restart apache2
Check Apache Status:
sudo systemctl status apache2
View Error Logs:
sudo tail -f /var/log/apache2/error.log
Need help? Contact us at ShantiLink.com 💬