Installing WordPress 5 on ZEIT Now with MySQL Hosting
Tags: mysql, wordpress, zeit, database
Published: 2019-02-11 18:27:31

---
title: Installing WordPress 5 on ZEIT Now with MySQL Hosting
published: true
description: Want to deploy WordPress 5.0 on ZEIT Now global serverless deployment platform with cheap MySQL hosting instances? Configure your MySQL database to get started.
tags: MySQL, WordPress, ZEIT, Database,
canonical_url: https://scalegrid.io/blog/installing-wordpress-5-on-zeit-now-with-mysql-hosting/
---
<link rel="canonical" href="https://scalegrid.io/blog/installing-wordpress-5-on-zeit-now-with-mysql-hosting/" />

<a href="https://scalegrid.io/blog/installing-wordpress-5-on-zeit-now-with-mysql-hosting/"><img class="alignnone size-full wp-image-4008" style="padding-top: 15px;" src="https://scalegrid.io/blog/wp-content/uploads/2019/02/Installing-WordPress-5-on-ZEIT-Now-with-MySQL-Hosting-ScaleGrid-Blog.jpg" alt="Installing WordPress 5 on ZEIT Now with MySQL Hosting - ScaleGrid" width="100%" height="auto" /></a>

<p style="text-align: justify; padding-bottom: 15px;"><i>The ZEIT Now WordPress builder has been officially deprecated, and ZEIT cannot guarantee the performance/reliability of the Now PHP community builder.</i></a>
<p style="text-align: justify; padding-bottom: 15px;">Want to deploy <a style="color: #2da964;" href="https://wordpress.org/support/wordpress-version/version-5-0/" target="_blank">WordPress 5.0</a> on the <a style="color: #2da964;" href="https://zeit.co/now" target="_blank">Now platform by ZEIT</a>? Our friends over at ZEIT's Now global serverless deployment platform whipped up a great tutorial for <a style="color: #2da964;" href="https://wordpress5.now.sh/?p=18" target="_blank">WordPress5-on-Now</a> using cheap <a style="color: #2da964;" href="https://scalegrid.io/mysql.html" target="_blank">MySQL hosting</a> 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.</p>

<p style="text-align: justify; padding-top: 15px;">So, why do you need <a style="color: #2da964;" href="https://scalegrid.io/blog/installing-wordpress-5-on-zeit-now-with-mysql-hosting/">MySQL hosting with ZEIT Now for WordPress</a>? 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 setup fully managed <a style="color: #2da964;" href="https://scalegrid.io/mysql/azure.html" target="_blank">MySQL on Azure</a> for as little as <a style="color: #2da964;" href="https://scalegrid.io/pricing.html?db=mysql&amp;cloud=cloud_azure&amp;replica=deployment_standalone&amp;instance=micro#section_pricing_byoc" target="_blank">$8/month</a> for management-only, or <a style="color: #2da964;" href="https://scalegrid.io/pricing.html?db=mysql&amp;cloud=cloud_azure&amp;replica=deployment_standalone&amp;instance=micro#section_pricing_dedicated" target="_blank">$18/month</a> with hosting included on dedicated servers.</p> 
<p style="text-align: justify; padding-top: 15px;">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!</p>
<h2 style="padding-top: 15px;">Setting Up Your MySQL Database for WordPress on ZEIT Now</h2>
<h3 style="padding-top: 15px;">Create a MySQL Database in ScaleGrid</h3>
<ol>
	<li style="text-align: justify; padding-top: 15px;">Sign up for a <a style="color: #2da964;" href="https://console.scalegrid.io/users/register" target="_blank">free 30-day trial</a> on the ScaleGrid console.</li>
<li style="text-align: justify; padding-top: 15px;">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 (<a style="color: #2da964;" href="https://help.scalegrid.io/docs/mysql-hosting-features-by-plan" target="_blank">compare MySQL plans</a>):
<ul>
	<li style="text-align: justify; padding-top: 15px;"><a style="color: #2da964;" href="https://help.scalegrid.io/docs/mysql-new-cluster-dedicated-hosting" target="_blank">Dedicated MySQL Cluster</a> - hosted through your ScaleGrid account.</li>
<li style="text-align: justify; padding-top: 15px;"><a style="color: #2da964;" href="https://help.scalegrid.io/docs/mysql-new-cluster-bring-your-own-cloud" target="_blank">BYOC MySQL Cluster</a> - Hosted through your own Azure account.</li>
</ul>
<li style="text-align: justify; padding-top: 15px;">Once your cluster is set up, go to your MySQL Cluster Details page, select the ‘Databases’ tab, and click the green 'New Database' button.</li>
<li style="text-align: justify; padding-top: 15px;">In the 'Create a new database' window that pops up, simply enter a name for your database and click 'Create'. <a href="https://scalegrid.io/blog/wp-content/uploads/2019/02/Create-a-MySQL-Database-in-ScaleGrid-DBaaS.jpg"><img class="alignnone size-full wp-image-4008" style="padding-top: 15px;" src="https://scalegrid.io/blog/wp-content/uploads/2019/02/Create-a-MySQL-Database-in-ScaleGrid-DBaaS.jpg" alt="Create a MySQL Database in ScaleGrid For Your ZEIT Now Deployment on WordPress" width="100%" height="auto" /></a></li>
<li style="text-align: justify; padding-top: 15px;">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.</li>
</ol>

<h3 style="padding-top: 15px;">Create a New User for Your MySQL Database</h3>
<ol>
<li style="text-align: justify; padding-top: 15px;">Go to your MySQL Cluster Details page, select the ‘Users‘ tab, and click the ‘New User’ button.</li>
<li style="text-align: justify; padding-top: 15px;">In the 'New User' window, choose the database you just created from the 'Select databases(s) user has permissions to access' dropdown.</li>
<li style="text-align: justify; padding-top: 15px;">Enter a 'Name' and 'Password' for the new user.</li>
<li style="text-align: justify; padding-top: 15px;">In the 'Role' dropdown, make sure to select 'Read - Write' as the role so the new user has full write permissions on this database.<a href="https://scalegrid.io/blog/wp-content/uploads/2019/02/Create-a-MySQL-Database-New-User-in-ScaleGrid-DBaaS.jpg"><img class="alignnone size-full wp-image-4018" style="padding-top: 15px;" src="https://scalegrid.io/blog/wp-content/uploads/2019/02/Create-a-MySQL-Database-New-User-in-ScaleGrid-DBaaS.jpg" alt="Create a MySQL Database New User in ScaleGrid DBaaS for ZEIT Now on WordPress" width="100%" height="auto" /></a></li>
<li style="text-align: justify; padding-top: 15px;">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.</li>
</ol>
<h3 style="padding-top: 15px;">Grab The Hostname of Your MySQL Deployment</h3>
<ol>
<li style="text-align: justify; padding-top: 15px;">Go to your MySQL Cluster Details page and select the ‘Overview’ tab.</li>
<li style="text-align: justify; padding-top: 15px;">Find the <a style="color: #2da964;" title="MySQL Command Line Syntax" href="https://help.scalegrid.io/docs/mysql-command-line-syntax" target="_blank">Command Line Syntax</a> section at the bottom of the page to see the command that can be used to connect your MySQL deployment through mysql client. <a href="https://scalegrid.io/blog/wp-content/uploads/2019/02/MySQL-Command-Line-Syntax-ScaleGrid-DBaaS.png"><img class="alignnone size-full wp-image-4023" style="padding-top: 15px;" src="https://scalegrid.io/blog/wp-content/uploads/2019/02/MySQL-Command-Line-Syntax-ScaleGrid-DBaaS.png" alt="MySQL Command Line Syntax - ScaleGrid DBaaS" width="100%" height="auto" /></a></li>
<li style="text-align: justify; padding-top: 15px;">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’.</li>
<li style="text-align: justify; padding-top: 15px;">Jot down your MySQL hostname to use in our next steps with ZEIT Now and WordPress.</li>
</ol>
<h3 style="padding-top: 15px;">Downloading Your ca.pem File</h3>
<ol>
<li style="text-align: justify; padding-top: 15px;">Go to your MySQL Cluster Details page and select the ‘Overview’ tab.</li>
<li style="text-align: justify; padding-top: 15px;">If your MySQL deployment is SSL enabled, then you will see a section ‘SSL Certificate’</li>
<li style="text-align: justify; padding-top: 15px;">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.<a href="https://scalegrid.io/blog/wp-content/uploads/2019/02/MySQL-Cluster-ca.pem-File-SSL-Certificate-ScaleGrid-DBaaS.png"><img class="alignnone size-full wp-image-4025" style="padding-top: 15px;" src="https://scalegrid.io/blog/wp-content/uploads/2019/02/MySQL-Cluster-ca.pem-File-SSL-Certificate-ScaleGrid-DBaaS.png" alt="MySQL Cluster ca.pem File SSL Certificate - ScaleGrid DBaaS" width="100%" height="auto" /></a></li>
</ol>
<hr />
<p style="text-align:justify;">You now have everything you need to setup 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 <a style="color: #2da964;" href="https://wordpress5.now.sh/?p=18" target="_blank">WordPress5-on-Now</a> or follow below.</p>

<hr />
<h2 style="padding-top: 15px;">Setting Up WordPress 5 on ZEIT Now</h2>
<p style="text-align: justify; padding-top: 15px;">Install <a style="color: #2da964;" href="https://zeit.co/download">Now</a>. <code>npm i -g now</code> 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 <code>wp-config.php</code> file and a <code>now.json</code> file.   Your <code>now.json</code> file will set up the <code>@now/wordpress</code> builder and a few routes:</p> 

<pre class="wp-block-code" style="color: #23282d;"><code>{
  "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"
  }
}</code></pre>

<p style="text-align: justify; padding-top: 15px;">Notice that it’s referring to a few secrets like <code>@wordpress_db_name</code>. You can create these with <code>now secret add</code>.   My <code>wp-config.php</code> looks like follows. Notice we use MySQL over TLS for security reasons.</p>

<pre class="wp-block-code" style="color: #23282d;"><code>&lt;?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');</code></pre>

<p style="text-align: justify; padding-top: 15px;">Make sure to change your <code><code>WPSALT</code></code> to a random string or a secret passed as <code>$_ENV</code>.   Finally we created a <code>ca.pem</code> file downloaded from ScaleGrid. This is necessary only when using MySQL over TLS.   That’s it! Then run <code>now</code> to deploy or <code>git push</code> if you configured <a style="color: #2da964;" href="https://zeit.co/github">Now + GitHub</a>.</p>
<hr />
<p style="text-align: justify; padding-top: 15px; padding-bottom: 15px;">If there are any other scenarios where you'd like to use ZEIT with ScaleGrid's <a style="color: #2da964;" title="MySQL Hosting" href="https://scalegrid.io/mysql.html" target="_blank">MySQL</a>, <a style="color: #2da964;" title="MongoDB Hosting" href="https://scalegrid.io/mongodb.html" target="_blank">MongoDB</a>, <a style="color: #2da964;" title="Redis Hosting" href="https://scalegrid.io/redis.html" target="_blank">Redis</a>, or <a style="color: #2da964;" title="PostgreSQL Hosting" href="https://scalegrid.io/postgresql.html" target="_blank">PostgreSQL</a> 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.</p>