Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created December 15, 2010 02:39
Show Gist options
  • Save nojimage/741544 to your computer and use it in GitHub Desktop.
Save nojimage/741544 to your computer and use it in GitHub Desktop.
Output VirtualHost configuration file for Apache HTTPD (CakePHP Shell)
<?php
$webroot = '/var/www/vhosts/' . $domain . '/htdocs';
?>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "<?= $webroot ?>"
ServerName <?= $domain ?>
ErrorLog "logs/<?= $domain ?>-error_log"
CustomLog "logs/<?= $domain ?>_log" combined
<Directory "<?= $webroot ?>">
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
<?php
class VhostShell extends Shell {
public function main() {
$this->out('Vhost config maker for Apache HTTPD');
if (empty($this->args)) {
// show help
$this->help();
return;
}
}
/**
* help
*
*/
public function help() {
$this->hr();
$this->out('Usage: cake vhost create <vhostname> [-t <template>]');
$this->hr();
$this->out('Parameters:');
$this->out(' <vhostname>');
$this->out(' (eg. vhost.example.com)');
$this->out();
$this->out(' <template>');
$this->out(' template file. (default: "default")');
$this->out();
$this->hr();
}
public function create() {
$domain = $this->args[0];
$template = 'default';
if (!empty($this->params['t']) && is_file($this->_getTemplatePath() . $this->params['t'] . '.ctp')) {
$template = $this->params['t'];
}
ob_start();
include $this->_getTemplatePath() . $template . '.ctp';
$conf = ob_get_contents();
ob_end_clean();
$this->out($conf);
}
protected function _getTemplatePath() {
return dirname(__FILE__) . DS . 'vhost_templates' . DS;
}
}
@nojimage
Copy link
Author

vendors/shells/にvhost.phpをぶっ込む。
vendors/shells/vhost_templates/ を作って default.ctpをぶっ込む。

cake vhost create vhost.example.com

とすれば、それらしき出力がでるですよ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment