Skip to content

Instantly share code, notes, and snippets.

@krolow
Created September 20, 2012 18:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krolow/3757622 to your computer and use it in GitHub Desktop.
Save krolow/3757622 to your computer and use it in GitHub Desktop.
Create Project PHP - sudo create-project.php name_of_project /path/of/project
<?php
/*
* Template of virtual host
*/
$template = "<VirtualHost *:80>\n";
$template .= "ServerName {$argv[1]}\n";
$template .= "DocumentRoot {$argv[2]}\n";
$template .= "<Directory {$argv[2]}>\n";
$template .= " Options Indexes FollowSymLinks MultiViews\n";
$template .= " AllowOverride All\n";
$tempalte .= " Order allow,deny\n";
$template .= " allow from all\n";
$template .= "</Directory>\n";
$template .= "ErrorLog /var/log/apache2/{$argv[1]}_error.log\n";
$template .= " LogLevel warn\n";
$template .= " CustomLog /var/log/apache2/{$argv[1]}_access.log combined\n";
$template .= "</VirtualHost>\n";
echo $template;
$file = fopen("/etc/apache2/sites-available/{$argv[1]}", 'x');
fwrite($file, $template);
fclose($file);
exec("ln -s /etc/apache2/sites-available/{$argv[1]} /etc/apache2/sites-enabled/{$argv[1]}");
$file = fopen("/etc/hosts", 'a+');
fwrite($file, "127.0.0.1 {$argv[1]}\n");
fclose($file);
exec('/etc/init.d/apache2 restart');
echo 'Created with success the config for: ', $argv[1];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment