WikiHost
Questions answered by this recipe
- How can I Declare my installation path as a variable, so I only set once in my config.php file for the whole wiki installation?
- Can I simplify use of the local paths in my config.php so I can easily use the file as a template for other wiki installations?
- Can I ensure that paths to my install work for both http and https instances with no editing needed?
Description
Code to simplify updates/templating/migration regardless of http or https
I prefer to use variables instead of hard-coding paths, and I was having issues with https vs. http
this is the solution I came up with, which works across my dozen or so pmwiki installations.
Now I can update config.php files across installations and only edit one directory name, once, and that only
if the root Wiki directory is not "pmwiki"
I also eliminated some issues I was having with my .htaccess files and path references inside of my Wiki's due to https
Installation:
These are all edits / additions to the .../local/config.php file to simplify updates/templating/migration
The following should go at the beginning of your config.php file just after
if (!defined('PmWiki')) exit();
## -- If you have a default "/pmwiki" installation in a first level directory -- ## ## == Y O U C A N U S E T H I S W I T H N O E D I T I N G == ## ## Define the Path after the domain name, to YOUR directory containing pmwiki.php ## e.g. pmwiki is normally in the www.myexample.com/pmwiki directory ## In this case, "/pmwiki" is the WikiRoot path. ## Notice we never use the domain name! The Php finds it for us below. if (!defined('WikiRoot')){ define('WikiRoot', '/pmwiki'); } ## If you just use a different name for the wiki folder it might look like: ## ww.myexample.com/SomeFolder then you would use # if (!defined('WikiRoot')){ define('WikiRoot', '/SomeFolder'); } ## If your installation is at the Domain level (really a bad idea!) ## For example all the PMWiki files are located at http://www.mysite.com/ then # if (!defined('WikiRoot')){ define('WikiRoot', ''); } ## If your installation is several directories deep: ## For example https://www.mysite.com/somedirectory/anotherone/pmwiki then # if (!defined('WikiRoot')){ define('WikiRoot', '/somedirectory/anotherone/pmwiki'); } ## Define the domain of the pmwiki site, testing for https: ## You might change to default HTTP if you find you are having problems with your certificate. ## ## This code depends on the "check_https" function at the bottom of this page if (check_https()) { if (!defined('WikiHost')){ define('WikiHost', 'https://'.$_SERVER['HTTP_HOST']); } } else { if (!defined('WikiHost')){ define('WikiHost', 'http://'.$_SERVER['HTTP_HOST']); } } ##-- Default PATHS -- ## Now we can use the WikiHost and WikiRoot variables anywhere else we need in this file: $WikiRoot = WikiHost.WikiRoot; $ScriptUrl = WikiHost.WikiRoot.'/pmwiki.php'; $PubDirUrl = WikiHost.WikiRoot.'/pub'; $FarmPubDirUrl = WikiHost.WikiRoot.'/pub'; ## Function to check if the current installation URL uses an https or http prefix function check_https() { if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) { return true; } return false; }
Be sure you don't declare those variables again later in the file or you override what you just did.
Configuration
The comments in the above code pretty much tell you everything.
Be VERY sure you get the PMWiki root directory path correct, but you never need to write out your domain name.
Notes
To do / some day / maybe
Change log / Release notes
Comments
See discussion at WikiHost-Talk?
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.