anggagewor
8/8/2016 - 8:11 AM

membuat vhost dengan xampp dan laravel

membuat vhost dengan xampp dan laravel

  1. Download dan install xampp seperti biasa.
  2. download take ownership lalu extract
  3. install take ownership
  4. arahkan ke c:\windows\system32\drivers\etc\hosts
  5. klik kanan pada hosts dan pilih take ownership
  6. masuk ke dir htdoc xampp
  7. install laravel laravel new panel
  8. setelah itu edit routes.php
  9. lalu masukan code berikut
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::get('/domain/add', function () {
    return view('domain.add');
});



Route::post('/domain/add', function () {

$vhost      = "E:\\server\\apache\\conf\\extra\\httpd-vhosts.conf";
$host       = "c:\\windows\\system32\\drivers\\etc\\hosts";
$docroot    = "E:\\server\\htdocs";


    $vtext = "\n\n
##$_POST[name]
<VirtualHost $_POST[name]:80>
    ServerAdmin $_POST[email]
    DocumentRoot \"E:/server/htdocs/$_POST[name]\"
    ServerName $_POST[name]
    ErrorLog \"logs/$_POST[name]-error.log\"
    CustomLog \"logs/$_POST[name]-access.log\" common
</VirtualHost>";

//host
$vcur = file_get_contents($vhost);
$vcur .= $vtext;
file_put_contents($vhost, $vcur);
if(!file_exists("E:/server/htdocs/$_POST[name]")){
    mkdir("E:/server/htdocs/$_POST[name]");
}
//host
$hoos = file_get_contents($host);
$hoos .= "\n127.0.0.1       $_POST[name],www.$_POST[name]";
file_put_contents($host, $hoos);
echo "jangan lupa restart apache nya.";
});

Variable $vhost $host $docroot sesuaikan value nya sesuai dengan keadaan PC/Laptop.

lalu jalankan localhost/panel/public/domain/add