如何在非WordPress站点集成WooCommerce?本地测试数据库登录受阻求助
Hey there, totally get being stuck on database setup when you're just starting out—let's break this down step by step, no fancy jargon.
First off, quick reminder: WooCommerce is a WordPress plugin, so it must run on a WordPress installation. The "subdirectory approach" you're trying means setting up a WordPress instance in a subfolder of your non-WordPress site, then integrating WooCommerce with your main site via APIs or frontend embeds. Let's fix that database login block first.
1. Confirm your local database basics first
You need these 4 key pieces of info for WordPress to connect to your database—don't guess, double-check:
- Database Name: Create an empty database first using your local DB tool (phpMyAdmin, Adminer, etc.)—name it something like
local_woocommerce(don't use the defaultmysqldatabase). - Username: Local databases usually use
rootas the default username (works for XAMPP, WAMP, MAMP). - Password: Defaults vary: XAMPP/WAMP use an empty password, MAMP uses
root. If you changed it, use your custom password. - Database Host: Almost always
localhost, but if you're using MAMP, it might belocalhost:8889(check your local server's settings for the MySQL port).
2. Troubleshoot common database login failures
If you're still getting errors after entering the info, rule out these issues:
- Did you actually create the empty database? Don't skip this step—WordPress can't create it for you automatically in most local setups.
- Is your MySQL server running? Open your XAMPP/WAMP/MAMP control panel and make sure the MySQL service is marked "Running".
- Port mismatch? If your local MySQL uses a non-standard port (like 8889 for MAMP), add it to the host field (e.g.,
localhost:8889). - Typo in credentials? Even a single space in the password field will break the connection—copy-paste if you can.
3. Quick fix: Manually configure wp-config.php
If the WordPress installer's database form keeps failing, skip it and set up the config file manually:
- Go to your WordPress subdirectory (e.g.,
htdocs/my-non-wp-site/shop) and findwp-config-sample.php. - Open it in a text editor and replace the placeholder values with your database details:
define( 'DB_NAME', 'local_woocommerce' ); define( 'DB_USER', 'root' ); define( 'DB_PASSWORD', '' ); // Leave empty if using XAMPP/WAMP define( 'DB_HOST', 'localhost' ); // Or localhost:8889 for MAMP - Save the file as
wp-config.php(remove the-samplepart). - Refresh the WordPress installation page—it should skip the database step and take you straight to creating your admin account.
4. Post-database setup: Next steps for integrating with your non-WP site
Once WordPress and WooCommerce are installed in the subdirectory:
- Activate WooCommerce in the WordPress admin and run its setup wizard to configure your store basics.
- To connect it to your non-WordPress site, use the WooCommerce REST API to pull products, orders, and cart data into your main site. You can also embed WooCommerce pages (like the shop or cart) using iframes, but the API is the cleaner long-term solution.
内容的提问来源于stack exchange,提问作者wosope

