DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Data Engineering
  3. Databases
  4. Installing WordPress 5 on ZEIT Now With MySQL Hosting

Installing WordPress 5 on ZEIT Now With MySQL Hosting

Lear how to set it up so that your MySQL database runs on autopilot so you can keep your development efforts focused on the product.

Kristi Anderson user avatar by
Kristi Anderson
·
Feb. 13, 19 · Tutorial
Like (2)
Save
Tweet
Share
9.77K Views

Join the DZone community and get the full member experience.

Join For Free

Want to deploy WordPress 5.0 on the Now platform by ZEIT? Our friends over at ZEIT’s Now global serverless deployment platform whipped up a great tutorial for WordPress5-on-Now using cheap MySQL hosting instances from ScaleGrid. With such strong interest in this installation, we decided to write up the steps to configure your MySQL database on the ScaleGrid side to get you up and running ever faster with WordPress on Now.

So, why do you need MySQL hosting with ZEIT Now for WordPress? Now focuses on being the best platform for serverless hosting, but you need to find a way to store your data permanently. That’s where ScaleGrid comes in. You can set up fully managed MySQL on Azure for as little as $8/month for management-only, or $18/month with hosting included on dedicated servers.

The best part is all you need to do is set it up, and then your MySQL database runs on autopilot so you can keep your development efforts focused on product vs. those time-consuming database operations. Let’s get started!

Setting Up Your MySQL Database for WordPress on ZEIT Now

Create a MySQL Database in ScaleGrid

  1. Sign up for a free 30-day trial on the ScaleGrid console.
  2. Create your first MySQL cluster. Make sure to create it in a region that matches your Now deployment region. We support two different MySQL DBaaS plans (compare MySQL plans):
    • Dedicated MySQL Cluster - hosted through your ScaleGrid account.
    • BYOC MySQL Cluster - Hosted through your own Azure account.
  3. Once your cluster is set up, go to your MySQL Cluster Details page, select the ‘Databases’ tab, and click the green ‘New Database’ button.
  4. In the ‘Create a new database’ window that pops up, simply enter a name for your database and click ‘Create.’Create a MySQL Database in ScaleGrid For Your ZEIT Now Deployment on WordPress
  5. Your database will now be created! You can access it anytime under the ‘Databases’ tab of your MySQL cluster. Jot down your database name so you can use it in our later steps with ZEIT Now.

Create a New User for Your MySQL Database

  1. Go to your MySQL Cluster Details page, select the ‘Users‘ tab, and click the ‘New User’ button.
  2. In the ‘New User’ window, choose the database you just created from the ‘Select databases(s) user has permissions to access’ dropdown.
  3. Enter a ‘Name’ and ‘Password’ for the new user.
  4. In the ‘Role’ dropdown, make sure to select ‘Read – Write’ as the role so the new user has full write permissions on this database.Create a MySQL Database New User in ScaleGrid DBaaS for ZEIT Now on WordPress
  5. Click ‘Create’ and your new user will be created! Jot down your new database user name and password so you can use it when setting up ZEIT Now on WordPress.

Grab the Hostname of Your MySQL Deployment

  1. Go to your MySQL Cluster Details page and select the ‘Overview’ tab.
  2. Find the Command Line Syntax section at the bottom of the page to see the command that can be used to connect your MySQL deployment through the mysql client.MySQL Command Line Syntax - ScaleGrid DBaaS
  3. The server name following the -h option is the hostname of your MySQL deployment, and in this particular case, it is SG-help-1-master.devservers.scalegrid.io.
  4. Jot down your MySQL hostname to use in our next steps with ZEIT Now and WordPress.

Downloading Your ca.pem File

  1. Go to your MySQL Cluster Details page and select the ‘Overview’ tab.
  2. If your MySQL deployment is SSL enabled, then you will see a section ‘SSL Certificate.’
  3. Click on the ‘Get SSL CA cert’ link to see the contents of your CA certificate, and copy those contents to your ca.pem file.MySQL Cluster ca.pem File SSL Certificate - ScaleGrid DBaaS

You now have everything you need to set up your WordPress on ZEIT Now with MySQL instances! The steps outlined in the tutorial below was developed by ZEIT Now, and you can read the original instructions here at WordPress5-on-Now or follow below.

Setting Up WordPress 5 on ZEIT Now

Install Now. npm i -g now if short on time. Set up a database in a cloud SQL hosting provider like ScaleGrid. Make sure you pick a location that matches a Now deployment region. Create a wp-config.php file and a now.json file. Your now.json file will set up the @now/wordpress builder and a few routes:

{
  "version": 2,
  "builds": [
    { "src": "wp-config.php", "use": "@now/wordpress" }
  ],
  "routes": [
    { "src": "/wp-admin/?", "dest": "index.php" },
    { "src": ".*\\.php$", "dest": "index.php" }
  ],
  "env": {
    "DB_NAME": "@wordpress_db_name",
    "DB_USER": "@wordpress_db_user",
    "DB_PASSWORD": "@wordpress_db_password",
    "DB_HOST": "@wordpress_db_host"
  }
}

Notice that it’s referring to a few secrets like @wordpress_db_name. You can create these with now secret add. My wp-config.php looks like follows. Notice we use MySQL over TLS for security reasons.

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', $_ENV['DB_NAME']);

/** MySQL database username */
define('DB_USER', $_ENV['DB_USER']);

/** MySQL database password */
define('DB_PASSWORD', $_ENV['DB_PASSWORD']);

/** MySQL hostname */
define('DB_HOST', $_ENV['DB_HOST']);

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'WPSALT');
define('SECURE_AUTH_KEY',  'WPSALT');
define('LOGGED_IN_KEY',    'WPSALT');
define('NONCE_KEY',        'WPSALT');
define('AUTH_SALT',        'WPSALT');
define('SECURE_AUTH_SALT', 'WPSALT');
define('LOGGED_IN_SALT',   'WPSALT');
define('NONCE_SALT',       'WPSALT');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define('WP_DEBUG', false);

define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] );
define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] );
define( 'WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/wp-content' );

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');

define( 'MYSQL_SSL_CA', ABSPATH . 'ca.pem' );
define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL );

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Make sure to change your WPSALT to a random string or a secret passed as $_ENV. Finally, we created a ca.pem file downloaded from ScaleGrid. This is necessary only when using MySQL over TLS. That’s it! Then run now to deploy or git push if you configured Now + GitHub.

If there are any other scenarios where you’d like to use ZEIT with ScaleGrid’s MySQL, MongoDB, Redis, or PostgreSQL hosting and management plans, leave us a comment below and we’d be happy to write them up! Also, share any questions in our comments or on Twitter at @scalegridio and we’ll follow up to help.

MySQL Cluster WordPress Database

Published at DZone with permission of Kristi Anderson. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Public Cloud-to-Cloud Repatriation Trend
  • A Beginner's Guide to Back-End Development
  • Comparing Flutter vs. React Native
  • Simulating and Troubleshooting StackOverflowError in Kotlin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: