# WordPress Backend Setup Guide Complete installation and configuration guide for the WordPress backend component of the Planit AI template on Japanese VPS/rental servers. ## 📋 Prerequisites - VPS or rental server with PHP 7.4+ and MySQL 5.7+ (or MariaDB 10.3+) - SSH access (for VPS) or control panel access (for rental servers) - Domain name (or temporary IP address) - Basic knowledge of Linux command line (for VPS) ## 🚀 Installation Methods This guide covers multiple installation methods for different server types: - **Method 1:** Manual Installation via FTP/SFTP - **Method 2:** WP-CLI Installation (Command Line) - **Method 3:** One-Click Installer (Rental Servers) --- ## Method 1: Manual Installation via FTP/SFTP ### Step 1: Download WordPress ```bash # On local machine cd ~/Downloads wget https://wordpress.org/latest.tar.gz tar -xzf latest.tar.gz ``` ### Step 2: Upload to Server #### Option A: Using FTP Client (FileZilla, Cyberduck) 1. Connect to server via FTP/SFTP - Host: Your server IP or domain - Username: Your server username - Password: Your server password - Port: 21 (FTP) or 22 (SFTP) 2. Navigate to server root directory: - **VPS:** `/var/www/html` or `/usr/share/nginx/html` - **Rental Server:** Usually `public_html` or `www` or `htdocs` 3. Upload all WordPress files from extracted `wordpress` folder 4. Set proper file permissions (via SSH): ```bash sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html ``` #### Option B: Using SCP from Command Line ```bash # From local machine scp -r wordpress/* your-username@your-server-ip:/var/www/html/ ``` ### Step 3: Create Database Choose one of the database setup methods from the main SETUP-GUIDE.md: - MySQL Command Line - phpMyAdmin - Control Panel (Rental Servers) - MariaDB ### Step 4: Configure WordPress 1. Visit your domain in browser 2. Follow WordPress installation wizard 3. Enter database credentials: - Database name: `planitai_wp` (or your database name) - Username: Database user - Password: Database password - Database host: Usually `localhost` - Table prefix: `wp_` (default) 4. Complete initial setup: - Site title - Admin username - Admin password - Admin email --- ## Method 2: WP-CLI Installation ### Step 1: Install WP-CLI ```bash # Download WP-CLI cd ~ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # Make executable chmod +x wp-cli.phar # Move to system path sudo mv wp-cli.phar /usr/local/bin/wp # Verify installation wp --info ``` ### Step 2: Download WordPress ```bash # Navigate to web root cd /var/www/html # Download WordPress sudo wp core download --allow-root ``` ### Step 3: Create Database Refer to database setup methods in SETUP-GUIDE.md, then use: ```bash # Create database (if not created) mysql -u root -p CREATE DATABASE planitai_wp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password'; GRANT ALL PRIVILEGES ON planitai_wp.* TO 'wp_user'@'localhost'; FLUSH PRIVILEGES; EXIT; ``` ### Step 4: Create WordPress Configuration ```bash cd /var/www/html sudo wp config create --dbname=planitai_wp --dbuser=wp_user --dbpass=your_password --dbhost=localhost --allow-root ``` ### Step 5: Install WordPress ```bash sudo wp core install \ --url=https://your-domain.com \ --title="Your Site Title" \ --admin_user=admin \ --admin_password=secure_password_here \ --admin_email=your@email.com \ --allow-root ``` ### Step 6: Set File Permissions ```bash sudo chown -R www-data:www-data /var/www/html sudo find /var/www/html -type d -exec chmod 755 {} \; sudo find /var/www/html -type f -exec chmod 644 {} \; ``` --- ## Method 3: One-Click Installer (Rental Servers) ### Sakura Internet (さくらのレンタルサーバ) 1. **Access Control Panel** - Log into [sakura.ne.jp](https://www.sakura.ne.jp/) - Access your control panel 2. **WordPress Installation** - Navigate to "WordPress簡単インストール" (WordPress Easy Install) - Select domain and installation directory - Click "インストール" (Install) - Follow on-screen instructions 3. **Post-Installation** - Update WordPress to latest version - Install required plugins - Configure file permissions if needed ### ConoHa WING 1. **Access Control Panel** - Log into ConoHa WING control panel 2. **Application Installation** - Go to "アプリケーション" (Applications) - Select WordPress - Configure: - Domain selection - Database creation - Admin credentials - Click "インストール" (Install) 3. **Complete Installation** - Wait for installation to complete - Note admin credentials - Access WordPress admin panel ### Xserver (エックスサーバー) 1. **Access Control Panel** - Log into Xserver control panel 2. **WordPress Installation** - Navigate to "WordPress簡単インストール" - Select server and domain - Choose installation directory - Set admin credentials - Click "インストール実行" (Execute Installation) 3. **Verify Installation** - Access WordPress admin - Update WordPress and plugins - Configure settings ### ConoHa VPS / Other VPS Providers Many VPS providers offer WordPress installation scripts: ```bash # Example: Using WordPress installation script cd /var/www/html wget https://raw.githubusercontent.com/WordPress/wp-cli/master/utils/wp-install.sh chmod +x wp-install.sh sudo ./wp-install.sh ``` **Note:** After one-click installation: - Update WordPress to latest version - Install required plugins manually - Configure file permissions - Set up database backups --- ## Database Setup Methods ### Method 1: MySQL Command Line ```bash # Access MySQL sudo mysql -u root -p # or mysql -u root -p # Create database CREATE DATABASE planitai_wp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; # Create user CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password_here'; # Grant privileges GRANT ALL PRIVILEGES ON planitai_wp.* TO 'wp_user'@'localhost'; # Flush privileges FLUSH PRIVILEGES; # Exit EXIT; ``` ### Method 2: phpMyAdmin 1. **Access phpMyAdmin** - URL: `http://your-server-ip/phpmyadmin` - Login with MySQL root credentials 2. **Create Database** - Click "新規作成" (New) or "データベース" (Database) - Enter name: `planitai_wp` - Select collation: `utf8mb4_unicode_ci` - Click "作成" (Create) 3. **Create User** - Click "ユーザーアカウント" (User Accounts) tab - Click "アカウントを追加" (Add User Account) - Enter username and password - Under "データベースに対する権限" (Database privileges): - Select database: `planitai_wp` - Click "すべて選択" (Select All) - Click "実行" (Go) ### Method 3: Control Panel (Rental Servers) #### Common Steps: 1. **Access MySQL Database Section** - Navigate to "MySQLデータベース" (MySQL Database) in control panel 2. **Create Database** - Click "データベース作成" (Create Database) - Enter name: `planitai_wp` - Note: Database name is often prefixed with your account name 3. **Create User** - Click "ユーザー作成" (Create User) - Enter username and password - Note: Username is often prefixed with account name 4. **Link User to Database** - Select database and user - Grant all privileges - Save configuration 5. **Note Credentials** - Database host: Usually `localhost` or provided hostname - Database name: Full name with prefix - Username: Full username with prefix - Password: The one you set --- ## Import Template Data ### Step 1: Install Migration Plugin #### Via WordPress Admin: 1. Log into WordPress admin: `http://your-domain.com/wp-admin` 2. Go to **プラグイン > 新規追加** (Plugins > Add New) 3. Search: "All-in-One WP Migration" 4. Click **今すぐインストール** (Install Now) 5. Click **有効化** (Activate) #### Via WP-CLI: ```bash cd /var/www/html sudo wp plugin install all-in-one-wp-migration --activate --allow-root ``` ### Step 2: Import Backup File #### Method A: Via WordPress Admin 1. Go to **All-in-One WP Migration > Import** 2. Click **Import From > File** 3. Upload `wordpress/planitai-wp.wpress` 4. Wait for completion (may take several minutes) 5. **Important:** Do not close browser during import #### Method B: Via WP-CLI (Recommended for large files) 1. **Upload file to server** ```bash # From local machine scp wordpress/planitai-wp.wpress your-username@your-server:/tmp/ ``` 2. **Import via WP-CLI** ```bash cd /var/www/html sudo wp ai1wm import /tmp/planitai-wp.wpress --allow-root ``` 3. **Clean up** ```bash rm /tmp/planitai-wp.wpress ``` #### Method C: Direct File Upload (for large files) 1. **Increase PHP limits** in `php.ini` ```ini upload_max_filesize = 512M post_max_size = 512M memory_limit = 256M max_execution_time = 300 ``` 2. **Restart PHP service** ```bash sudo systemctl restart php8.0-fpm # or sudo systemctl restart php-fpm ``` 3. **Upload via WordPress admin** - Use plugin's import feature - Or install "All-in-One WP Migration Unlimited Extension" ### Step 3: Update Permalinks 1. Go to **設定 > パーマリンク設定** (Settings > Permalinks) 2. Click **変更を保存** (Save Changes) - do this **twice** 3. Or via WP-CLI: ```bash sudo wp rewrite flush --allow-root ``` ### Step 4: Update Site URLs (If Domain Changed) #### Method A: Via Plugin 1. Install "Better Search Replace" plugin 2. Go to **ツール > Better Search Replace** (Tools > Better Search Replace) 3. Search: `https://planitai-wp.smacon.info` 4. Replace: `https://your-domain.com` 5. Select all tables 6. Click **実行** (Run) #### Method B: Via WP-CLI ```bash cd /var/www/html sudo wp search-replace 'https://planitai-wp.smacon.info' 'https://your-domain.com' --allow-root sudo wp option update siteurl 'https://your-domain.com' --allow-root sudo wp option update home 'https://your-domain.com' --allow-root ``` --- ## Configure WordPress ### Step 1: Configure reCAPTCHA 1. **Get reCAPTCHA Keys** - Visit [Google reCAPTCHA Admin Console](https://www.google.com/recaptcha/admin) - Click **+ Create** to create a new site - Enter a label for your site - Select **reCAPTCHA v3** (invisible, runs in background) - Add your domain(s) to the allowed domains list - Click **Submit** - **Copy both the Site Key and Secret Key** 2. **Configure Contact Form 7** - In WordPress admin: **お問い合わせ > 統合** (Contact > Integration) - Find **reCAPTCHA** section - Enter **Site Key** and **Secret Key** - Click **変更を保存** (Save Changes) 3. **Verify Contact Form** - Go to **お問い合わせ > お問い合わせフォーム** (Contact > Contact Forms) - Note the form ID (should be 219) - Test form submission ### Step 2: Configure Email (SMTP) 1. **Install WP Mail SMTP** - Go to **プラグイン > 新規追加** (Plugins > Add New) - Search: "WP Mail SMTP" - Install and activate 2. **Configure SMTP** - Go to **WP Mail SMTP > 設定** (WP Mail SMTP > Settings) - Choose your email provider (Gmail, SendGrid, etc.) - Enter SMTP credentials - Test email delivery --- ## ✅ Verification Checklist - [ ] WordPress installed and accessible - [ ] Backup imported successfully - [ ] Permalinks updated - [ ] Site URLs updated (if domain changed) - [ ] reCAPTCHA configured - [ ] Contact form working - [ ] Email sending successfully - [ ] REST API accessible at `/api/wp/v2` - [ ] File permissions correct - [ ] Database connection working --- ## 🔧 Troubleshooting ### Import Fails (File Size) **Solution 1: Install Extension** - Install "All-in-One WP Migration Unlimited Extension" - Or use WP-CLI import method **Solution 2: Increase PHP Limits** ```ini # Edit php.ini upload_max_filesize = 512M post_max_size = 512M memory_limit = 256M max_execution_time = 300 ``` **Solution 3: Use WP-CLI** ```bash cd /var/www/html sudo wp ai1wm import /path/to/planitai-wp.wpress --allow-root ``` ### Images Not Loading **Check file permissions:** ```bash sudo chown -R www-data:www-data /var/www/html/wp-content/uploads sudo chmod -R 755 /var/www/html/wp-content/uploads ``` **Clear browser cache and WordPress cache** ### Database Connection Errors **Verify credentials in wp-config.php:** ```php define('DB_NAME', 'planitai_wp'); define('DB_USER', 'wp_user'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost'); ``` **Test database connection:** ```bash mysql -u wp_user -p planitai_wp ``` ### Contact Form Not Sending **Configure SMTP:** - Install WP Mail SMTP plugin - Configure email provider settings - Test email delivery ### Permission Errors **Fix WordPress permissions:** ```bash sudo chown -R www-data:www-data /var/www/html sudo find /var/www/html -type d -exec chmod 755 {} \; sudo find /var/www/html -type f -exec chmod 644 {} \; ``` **Fix uploads directory:** ```bash sudo chmod -R 775 /var/www/html/wp-content/uploads ``` --- ## 📞 Next Steps After WordPress is set up: 1. Configure Next.js frontend (see `../nextjs/NEXTJS-SETUP.md`) 2. Update Next.js API URL to point to this WordPress installation 3. Test integration between frontend and backend 4. Set up automated backups 5. Configure SSL certificate (HTTPS) --- For complete setup including Next.js, see `../SETUP-GUIDE.md` **Last Updated:** November 2024