我编写的PHP脚本必须引导ex1.mydrupalsite.pl
这些网站使用Aegir平台托管。
结构如下:
/var/aegir/platforms/drupal-7.31/sites/ex1.mydrupalsite.pl
/var/aegir/platforms/drupal-7.31/sites/ex2.mydrupalsite.pl
# etc...
我一直在尝试:
define('DRUPAL_ROOT', '/var/aegir/platforms/drupal-7.31');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['HTTP_HOST'] = 'ex1.mydrupalsite.pl';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SCRIPT_NAME'] = '/' . basename(__FILE__);
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
但没有运气。
答案 0 :(得分:2)
我在任何地方都没有找到答案,所以经过一番努力,以下是如何做到这一点:
<?php
# Set username and password
$username = 'NAME';
$password = 'PASSWORD';
# Drupal Bootstrap code
define('DRUPAL_ROOT', '/var/aegir/platforms/drupal_7');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
# My attempt at injecting variables for multisite stuff to fit aegir
$variables['url'] = 'http://example.com/';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'mypass',
'host' => 'localhost',
'port' => '3306',
);
$db_url['default'] = 'mysql://sqluser:sqlpass@localhost:3306/sqldb';
drupal_override_server_variables($variables);
# Try to bootstrap
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
# Try to login
$uid = FALSE;
$account = user_load_by_name($username);
if ($account) {
// Allow alternate password hashing schemes.
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
if (user_check_password($password, $account)) {
// Successful authentication.
$uid = $account->uid;
// Update user to new password scheme if needed.
if (user_needs_new_hash($account)) {
user_save($account, array('pass' => $password));
}
}
}
debug($uid);
答案 1 :(得分:-1)
问题是在Aegir安装中,数据库访问信息不是存储在settings.php中,而是存储在/var/aegir/config/server_master/apache/vhost.d/ [sitename]中作为$ _SERVER环境变量。您需要在脚本中明确声明它们。
或者更好的是,使用“Drush scr”来运行脚本。它会为你做引导工作!有关更详细的说明,请参阅http://www.oliverdavies.uk/blog/dont-bootstrap-drupal-use-drush/。