Would you give me an example of codes for connecting to a remote database?
<?php
$dsn = 'mysql:host=localhost;dbname=remote;charset=utf8;collation=utf8_general_ci';
$usr = 'root';
$pwd = 'pwd';
$xpdoOptions = array(
XPDO_OPT_HYDRATE_FIELDS => true,
XPDO_OPT_HYDRATE_RELATED_OBJECTS => true
);
$pdoDriverOptions = array(
PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING,
PDO_ATTR_PERSISTENT => false,
PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true
);
$remote = new xPDO($dsn, $usr, $pwd, $xpdoOptions, $pdoDriverOptions);
?><?php
require_once(MODX_BASE_PATH . 'xpdo/xpdo.class.php');
class remoteModel extends xPDO {
var $modx = null;
function remoteModel(& $modx) {
$this->__construct($modx);
}
function __construct(& $modx) {
$this->modx = & $modx;
parent :: __construct(
'mysql:host=localhost;dbname=remote;charset=utf8;collation=utf8_general_ci',
'remote',
'foobar',
array(
XPDO_OPT_TABLE_PREFIX => 'remote_',
XPDO_OPT_HYDRATE_FIELDS => true,
XPDO_OPT_HYDRATE_RELATED_OBJECTS => true,
),
array(
PDO_ATTR_PERSISTENT => false,
)
);
$this->setPackage('remote', MODX_BASE_PATH . 'assets/remote/model/');
$this->setLogTarget('HTML');
$this->setLogLevel(XPDO_LOG_LEVEL_ERROR);
}
// other custom functions for your remote model here
}
?><?php require_once(MODX_BASE_PATH . 'assets/remote/model/remote/remotemodel.class.php'); $remoteModel = new remoteModel($modx); ?>
<?php
$dsn = 'mysql:host=localhost;dbname=remote;charset=utf8';
$usr = 'root';
$pwd = 'pwd';
$pdoDriverOptions = array(
PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING,
PDO_ATTR_PERSISTENT => false,
PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true
);
$remote = new PDO($dsn, $usr, $pwd, $pdoDriverOptions);
?>
... I would use a single core and simply create a database configuration and manager for each domain. In this way, you share only the core files and each domain has their own database.
Yes, this is how I do it, though I use svn to checkout the core directly at the location I’ve chosen on my server. You can use either package, though it makes more sense to use the advanced, since you will want the setup to extract the files into the document root locations you choose for each context (i.e. make sure Files Already in Place is not checked). To move the core, simply move the directory where you want it (you can even rename it) and then go into setup/includes/config.core.php and set the MODX_CORE_PATH to that location. You will also want to change MODX_CONFIG_KEY to whatever you want the configuration to be called (I typically use the domain of the site for easy identification).
Is it possible to set up a single core and create a database configuration and manager for each domain. Using the standard install package, or is it required to use the advanced package?
Are there specific config options I will need to select/set to allow me to move the core?
Well, I hope you aren’t running Apache/PHP as root, as that is a definite potential security problem. And unfortunately, this depends on your environment, including how PHP is running in Apache. FWIW, as long as the core/cache and core/packages directories are writable by the PHP user and the rest readable, the core should be secure.
I am guessing that the system will need access to the core (out side the web root) so how am I to grant the system these permissions... right now I have only one user set up on my server with these rights (Root).
I am wondering about security here?
MODX_CORE_PATH
'/home/core/'
define('MODX_CORE_PATH', '/home/core/');define ('MODX_CONFIG_KEY', 'domain1');Put the core somewhere it has access to, remove open_basedir restrictions, or add the path to your open_basedir configuration.
ok, so I thought I got things so that they should work, but I now get this error:
Warning: main() [function.main]: open_basedir restriction in effect. File(/home/core/model/modx/modx.class.php) is not within the allowed path(s): (/home/domain1:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp)
This was kind of what i was originally getting at when I asked about root access.
My sites user doesn’t have access outside the site root. (in this case one dir above public_html)
How do I work around this?
ok, so I thought I got things so that they should work, but I now get this error:
Warning: main() [function.main]: open_basedir restriction in effect. File(/home/core/model/modx/modx.class.php) is not within the allowed path(s): (/home/domain1:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp)
This was kind of what i was originally getting at when I asked about root access.
My sites user doesn’t have access outside the site root. (in this case one dir above public_html)
How do I work around this?
Yep, just copy the setup/ directory to another virtual host or document root and edit the setup/includes/config.core.php with the core location and configuration name.
OK, now my one site is running very nicely, I have added content and things seems to be good.
To setup a second site with its own database.... what might the steps be?
Can I use the installer on the next site... and then just edit things the same way?
I read about context and they have been mentioned.. how do these come into play?They would not come in to play in separate configurations/databases. Those would be for isolating sections of a site or subdomains or even multiple domains within a single database/configuration. Completely different approaches for completely different needs, i.e. sharing just the core or sharing the site data.