Step-by-step guide to set up WordPress on DigitalOcean with REST API, permalinks, and HTTPS.
คู่มือทีละขั้นตอนสำหรับติดตั้ง WordPress บน DigitalOcean พร้อม REST API, permalinks และ HTTPS
This will automatically update all commands with your domain name.
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
SSH into your droplet as root and update the system:
sudo apt update && sudo apt upgrade -y
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
sudo nano /etc/apache2/sites-available/000-default.conf
Add this inside the <VirtualHost *:80> block:
<Directory /var/www/html> AllowOverride All </Directory>
sudo a2enmod rewrite sudo systemctl reload apache2
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d your.domain.com
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
Visit your REST API endpoint:
https://your.domain.com/wp-json/
curl -X GET "https://your.domain.com/wp-json/wp/v2/posts" \ -H "Authorization: Basic $(echo -n 'your-username:your-app-password' | base64)"
https://your.domain.com/sample-page/
sudo systemctl restart apache2
sudo systemctl status apache2
sudo tail -f /var/log/apache2/error.log
sudo chown -R www-data:www-data /var/www/html
Your WordPress site is now ready for production use!
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