How do I configure a CMS installation like WordPress or Drupal, to run on multiple websites as a replicate of one main CMS installation. Owned and managed by different server accounts all hosted on the same server.
My setup is similar to the following:
- Webserver software:
nginx
running together withapache2
(VestaCP) - Document Root:
/home/user/example.com/public_html/
What do I mean with, "a replicate of one CMS installation":
As described in the diagram all users owning a folder where DocumentRoot is pointed at, will be able to replicate/create an instance of/use the CMS installation.
You probably need the following files to run the CMS installation:
- DocumentRoot/configuration.php - specify with what data the CMS should load.
- DocumentRoot/index.php - Call and render the specified output.
WordPress
To sort out what approach will work out the best I could come up with these two different scenario's:
- where there is only one symbolic linked folder, this folder includes the wordpress core files.
- all the wordpress core files and folders are symbolically linked.
In both scenario's the setup is trying to require their own config file (my-config.php
), so not the one what's symbolically linked.
1: Symbolic linked wordpress folder:
wordpress/wp-config.php
<?php
require_once( ROOT_PATH . 'my-config.php');
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
wordpress/test.php
<?php echo 'Path is '.getcwd(); ?>
DocumentRoot/index.php
<?php
define('ROOT_PATH', dirname(__FILE__) . '/');
require('wordpress/index.php');
DocumentRoot/my-config.php
Contains everything except the code inside wordpress/wp-config.php
<?php
define('WP_HOME', ... );
define( 'WP_CONTENT_URL', ... );
etc..
The symbolic link is as following
ln -s /path/to/wordpress/ .
My results
- [Visited URL] - [Testing results]
- ../ - Redirect to: ../wp-admin/install.php + 404
- ../wp-admin/ - 404
- ../wordpress/ - WSOD
- ../wordpress/wp-admin/ - WSOD
- ../wordpress/test.php - Output: Path is /path/to/wordpress
2: Another approach could be something like this:
wordpress/wp-config.php
<?php
require_once('my-config.php'); // So DocumentRoot/my-config.php
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
wordpress/test.php
<?php echo 'Path is '.getcwd(); ?>
DocumentRoot/my-config.php
The same as the DocumentRoot config file used in scenario 1.
The symbolic links are as following
ln -s /path/to/wordpress/* .
My results
- [Visited URL] - [Testing results]
- ../ - Redirect to: ../wp-admin/install.php + WSOD
- ../wp-admin/ - WSOD
- ../test.php - Output: Path is /home/user/example.com/public_html
Conclusion WordPress
In both scenario's the main index file redirects to the installation file. This normally happens when the connection to the database has been made but the database is still empty, so by following the installation instruction you will insert your first data. But then why does it give a WSOD?
The test file (test.php
) clears things up a bit. In the scenario 1 the path to the wordpress directory becomes the absolute path for the wordpress core files. For the scenario 2 the DocumentRoot's path becomes the absolute path for the wordpress core files... or not?
Although not for the sub directories in the wordpress directory, as we can learn from scenario 1. For example the wp-admin
directory, files what call getcwd()
should output /path/to/wordpress/wp-admin
right? If so then it means, all calls to files within those directories will never find the file. Because the file /home/user/example.com/public_html/wp-admin/file.php
doesn't exists! It's not symbolically linked and so it's only accessible via /path/to/wordpress/wp-admin/file.php
.