keepcalculator

06 Numbers and Powers

Install WordPress with a Separate Managed Database

Card No. 06·43808 · Updated · Standard formula, shown below

This guide walks you through installing WordPress on a web server while using a separate managed database service (like Amazon RDS, DigitalOcean Managed Databases, or a similar provider). This setup improves performance, scalability, and security by decoupling your database from your web server. You’ll need a domain name, a web server with PHP, and a managed database instance already provisioned.

What You’ll Need

  • A domain name (e.g., example.com) with DNS access.
  • A web server (VPS, shared host, or cloud instance) with PHP 7.4+ and a web server (Apache or Nginx) installed.
  • A managed database instance (MySQL or MariaDB) with a hostname, port, database name, username, and password.
  • SSH access to your web server (if you’re doing a manual install).
  • An FTP client or file manager if you prefer uploading files manually.

Step-by-Step

  1. Prepare your managed database
    Log into your database provider’s dashboard. Create a new database (e.g., wordpress) and a dedicated user with all privileges on that database. Note the hostname (often something like db.example.com), port (usually 3306), database name, username, and password. Ensure the database is accessible from your web server’s IP address—most managed services require you to whitelist IPs or set up a private network.
  2. Download WordPress
    SSH into your web server. Navigate to your web root (e.g., /var/www/html). Download the latest WordPress package with wget https://wordpress.org/latest.tar.gz, then extract it with tar -xzf latest.tar.gz. Move the contents of the wordpress folder to your web root if needed.
  3. Set up the wp-config.php file
    In the WordPress directory, copy wp-config-sample.php to wp-config.php using cp wp-config-sample.php wp-config.php. Open the file with a text editor and fill in your database details:
    define('DB_NAME', 'your_db_name');
    define('DB_USER', 'your_db_user');
    define('DB_PASSWORD', 'your_db_password');
    define('DB_HOST', 'your_db_hostname:port'); // e.g., 'db.example.com:3306'
      

    Save the file.

  4. Add security keys
    Visit https://api.wordpress.org/secret-key/1.1/salt/ and copy the generated keys. Replace the placeholder lines in your wp-config.php with these keys. This improves security.
  5. Set file permissions
    Ensure the web server can read the files. Run chown -R www-data:www-data /var/www/html (adjust user/group to match your web server) and set directory permissions to 755 and file permissions to 644 with find . -type d -exec chmod 755 {} \; and find . -type f -exec chmod 644 {} \;.
  6. Run the WordPress installer
    Open your browser and go to http://yourdomain.com. You’ll see the WordPress installation wizard. Select your language, then enter your site title, admin username, password, and email. Click “Install WordPress�.
  7. Verify the connection
    After installation, log in to your WordPress admin dashboard. Go to Tools → Site Health and check that there are no database connection errors. Also, try creating a test post to confirm everything works.
  8. Update your DNS (if needed)
    If you pointed your domain to the web server earlier, it should already work. If not, update your DNS A record to point to your web server’s IP address and wait for propagation.

Common Mistakes

  • Wrong DB_HOST format: Some users enter just the hostname without the port. If your managed database uses a non-default port, you must include it as hostname:port.
  • Database user privileges: The user must have all privileges on the specific database. If you only granted SELECT, WordPress will fail during installation.
  • Firewall blocking port 3306: Even if your database is whitelisted, your web server’s firewall might block outbound connections to port 3306. Ensure outbound traffic is allowed.
  • Using localhost: A common mistake is leaving DB_HOST as localhost when your database is remote. Always use the provided hostname.
  • SSL mismatch: If your managed database requires SSL, you may need to add specific SSL settings to wp-config.php. Check your provider’s documentation.

Tips

  • Use a private network: If your web server and database are on the same cloud provider, use a private IP for lower latency and better security.
  • Enable caching: With a remote database, latency can increase. Use a caching plugin like W3 Total Cache or WP Super Cache to reduce database queries.
  • Backup your database: Managed databases often have automated backups, but also set up your own scheduled backups using tools like mysqldump.
  • Monitor performance: Use a monitoring tool to track database connections and query times. This helps identify bottlenecks early.
  • Keep WordPress updated: Regularly update WordPress core, themes, and plugins to ensure compatibility with your database version.

Troubleshooting

  • Error: “Error establishing a database connection�
    Check your wp-config.php for typos. Verify the database hostname, port, and credentials. Test the connection from your web server using mysql -h hostname -P port -u user -p. If that fails, check your database’s firewall rules and ensure your IP is whitelisted.
  • Installation hangs at “Database connection�
    This often means the database user doesn’t have full privileges. Log into your database admin and grant all privileges on the database to the user.
  • White screen after installation
    Enable WP_DEBUG in wp-config.php by adding define('WP_DEBUG', true);. This will show errors. Common causes are missing PHP extensions like mysqli or curl. Install them via your package manager.
  • Cannot connect from web server only
    If you can connect from your local machine but not from the web server, the server’s IP may not be whitelisted. Add the server’s public IP to the database’s allowed IP list.
  • Slow site performance
    If your site is slow, check the database connection latency. If it’s high, consider moving the database closer to your server or using a CDN. Also, enable persistent connections in wp-config.php with define('WP_USE_EXT_MYSQL', false); and adjust your PHP settings.

Frequently Asked Questions

Can I use a managed database with any web host?

Yes, as long as your web host allows outbound connections to external databases. Some shared hosts block external database connections for security, so check with your provider.

Do I need to install MySQL on my web server?

No. The whole point of a managed database is to avoid installing and maintaining MySQL on your server. You only need the PHP MySQL extension (like mysqli) installed.

What if my managed database uses a different port?

You can specify the port in the DB_HOST constant as hostname:port. For example, db.example.com:3307.

Is it safe to use the same database for multiple WordPress sites?

It’s possible, but not recommended. Each site should have its own database to avoid table prefix collisions and to simplify backups. You can use different table prefixes (e.g., wp1_, wp2_) if you must share a database, but it’s messy.

How do I migrate an existing WordPress site to a managed database?

Export your current database using phpMyAdmin or mysqldump. Create a new database on your managed service, import the SQL file, then update wp-config.php with the new database details. Also, update the site URL if it changed.

What if my managed database requires SSL?

You’ll need to add SSL constants to wp-config.php. For example, define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL); and possibly specify the CA certificate path. Check your provider’s documentation for the exact settings.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →