Skip to content

Instantly share code, notes, and snippets.

@sarpdorukaslan
Last active October 12, 2015 12:14
Show Gist options
  • Save sarpdorukaslan/636633e7f6375cb28d05 to your computer and use it in GitHub Desktop.
Save sarpdorukaslan/636633e7f6375cb28d05 to your computer and use it in GitHub Desktop.
<?php
/**
* usage = sudo php aconf.php -d altklasor -h host.name
*
*/
$shortopts = "d:";
$shortopts .= "h:";
$options = getopt($shortopts);
$conf = "<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/{$options['d']}
ServerName {$options['h']}
<Directory /var/www/html/{$options['d']}>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>";
$confFile = "/etc/apache2/sites-available/".$options['h'].".conf";
$confHandler = fopen($confFile,'w+');
fwrite($confHandler,$conf);
fclose($confHandler);
/**
* Host Dosyasına kayıt.
*/
$hostFile = "/etc/hosts";
echo $hostContent = file_get_contents($hostFile);
$hostLines = explode("\n", $hostContent);
$found = false;
for ($i = 0; $i < sizeof($hostLines); ++$i)
{
if (strpos($hostLines[$i], $options['h']) !== false)
{
$found = true;
}
}
if (!$found)
{
$hostHandler = fopen($hostFile,'a+');
fwrite($hostHandler,'127.0.0.1 '.$options['h']);
fclose($hostHandler);
}
else {
echo $options['h']."host kaydı zaten var.\n";
}
exec('a2ensite '.$options['h'].".conf");
exec('service apache2 restart');
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment