https://christophermay.dev/2019/11/28/running-multiple-wordpress-sites-on-synology/
This tutorial is all about dev work. Specifically, running multiple wordpress instances as a way to keep projects separated as well as testing in a non-live environment. Synology makes this easy. Let me show you how.
First of all, allow me to preface this by saying there are a few ways you could go about trying to achieve this. The route I chose allows access outside the localhost/local area network via the Synology dynamic DNS service. I’m not interested in serving sites via my local machine to the outside network beyond personal access for public use, so i’m not going to be covering redirects or proxies, or any other advanced routing today. I would not recommend serving sites to the wider public via your personal machines. This is simply an easy way of accessing development sites when outside of the network, for personal use only.
Step 1: Getting Prepared
We need to download WordPress, and get our folders setup. First head over to https://wordpress.org/download/ and download it to your computer. I’m using version 5.3, but your version may be different. Once downloaded, login to your disk station and copy the entire zip archive to your web folder. Unzip it inside your web folder. If you do not have a web folder it’s because you have not yet setup webstation. Make sure you have webstation running, as well as php, mariaDB, and phpMyAdmin.
Step 2: Adjusting The Settings
Next you are going to want to create a new folder for the site you are working on. I’m calling mine “woocommerce”. Copy all the files from your unziped WordPress 5.3 archive and paste them into the new project folder you created.
Now that everything has been prepared, we can tweak our file settings and get the database running. If you try to run WordPress at this point, you’re going to get some serious errors. The first thing we need to do is get our “wp-config.php” file ready.
wp-config.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’, ‘woocommerce’ );
/** MySQL database username */
define( ‘DB_USER’, ‘wordpress_user’ );
/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password’ );
/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost:/run/mysqld/mysqld10.sock’ );
/** 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’, ‘XXX’);
define(‘SECURE_AUTH_KEY’, ‘XXX’);
define(‘LOGGED_IN_KEY’, ‘XXX’);
define(‘NONCE_KEY’, ‘XXX’);
define(‘AUTH_SALT’, ‘XXX’);
define(‘SECURE_AUTH_SALT’, ‘XXX’);
define(‘LOGGED_IN_SALT’, ‘XXX’);
define(‘NONCE_SALT’, ‘XXX’);
/**#@-*/
/**
* 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 = ‘XX_’;
/**
* 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( ‘FS_METHOD’, ‘direct’ );
/* That’s all, stop editing! Happy publishing. */
$pageURL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80” and $_SERVER[“SERVER_PORT”] != “443”) {
$pageURL .= $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”];
} else {
$pageURL .= $_SERVER[“SERVER_NAME”];
}
if ($_SERVER[“HOST”] != “”) {
define(‘WP_SITEURL’, $pageURL);
} else {
define(‘WP_SITEURL’, $pageURL.’/woocommerce’);
}
if (!defined(‘SYNOWORDPRESS’))
define(‘SYNOWORDPRESS’, ‘Synology Inc.’);
/** Absolute path to the WordPress directory. */
if ( ! defined( ‘ABSPATH’ ) ) {
define( ‘ABSPATH’, dirname( __FILE__ ) . ‘/’ );
}
/** Sets up WordPress vars and included files. */
require_once( ABSPATH . ‘wp-settings.php’ );
/**require_once( ABSPATH . ‘syno-misc.php’ ); */
define( ‘AUTOMATIC_UPDATER_DISABLED’, true );
/** add_filter(‘pre_site_transient_update_core’,’__return_null’); */
Create a database username and type it into the line labeled “define( ‘DB_USER’, ‘XXXXXXXXXX’ );”, replacing the X’s with your chosen name. Also choose a password for the password line directly below.
At the bottom of the above screenshot you see a block of code with a large blank space. This is where you need to paste your secret-key. You can generate a key for this file at the link below. Just follow the link, copy the code and then paste it into your config file.
In addition to the above edits, we will also need to change the line labeled “$table_prefix = ‘XXXX’;” to something unique, keep it short. You will also want to change the line labeled “define(‘WP_SITEURL’, $pageURL.’/woocommerce’);” Replace woocommerce with whatever you named your site folder inside the web folder.
Now that we’ve got the config file setup, we can turn our attention to the .htaccess file.
.htaccess
# Synology PHP
AddHandler default-handler .htm .html .shtml
AddHandler php-fastcgi .php
AddType text/html .php
Action php-fastcgi /php56-fpm-handler.fcgi
# Synology PHP
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
RewriteEngine On
RewriteBase /woocommerce/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /woocommerce/index.php [L]
# END WordPress
We just need to update two spots in red with the folder name of our project. Again, in my project that was “woocommerce”. Paste both of these modified text files in the folder with the rest of your WordPress files.
Step 3: Create Database
We need to create a database for the WordPress server to store data, including users, posts, and whatever else you create for your site. Setting up Maria DB 10 and phpMyAdmin is not the purpose of this tutorial, so i’m going assume you already know how to do that and have already set both up. Upon logging into phpMyAdmin, you need to create a new database by pressing the “New button on the left hand side of the screen. This will bring you to the Databases screen where you can enter a name for your new database, and then press the create button. Your new database is now created.
Next you are going to want to go to the User accounts screen which can be accessed from menu bar along the top of the screen. From this screen you may either create a new user for your database, or re-use another user you have already created.
That’s it, you should now be ready to use your new site if you did everything correctly. Now navigate to your synology’s webstation address (for me, this is https://myname.synology.me/woocommerce). There are many domain options available through the synology DDNS system, so yours may differ from mine. You can repeat these steps as many times as you’d like for as many instances of WordPress as you’d like, just create a new folder for each site you want to create.