Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure I understand what CI has to do with virtual hosts, but as of late, I created my own VHost functions:</p> <pre><code>define('VHOST_FILE','/etc/httpd/conf.d/vhost.conf'); /** * Generate Apache vhost entry. * @param string $domain Domain or subdomain name (eg: foo.example.com or example.biz). * @param string $path Path to document root. * @return string The generated vhost entry. */ function vhost_gen($domain,$path){ $eol=ISWIN ? CRLF : LF; return '&lt;VirtualHost *:80&gt;'.$eol. TAB.'ServerName '.str_replace(array(' ',CR,LF,TAB,NULL),'',$domain).$eol. TAB.'DocumentRoot "'.str_replace(array(CR,LF,TAB,NULL),'',$path).'"'.$eol. '&lt;/VirtualHost&gt;'.$eol.$eol; } /** * Writes the new vhost config file. * @param array $items List of objects(domain,docroot) used in config. */ function vhost_write($items){ $eol=ISWIN ? CRLF : LF; $data='NameVirtualHost *:80'.$eol.$eol; foreach($items as $item) $data.=vhost_gen ($item-&gt;domain,$item-&gt;docroot); return @file_put_contents(VHOST_FILE,$data); } /** * Returns a list of vhost entries. * @return array List of objects(id,domain,docroot) entries. */ function vhost_read(){ $entries=array(); $lines=explode(LF,str_replace(CR,LF,@file_get_contents(VHOST_FILE))); $entry=null; foreach($lines as $line){ // parse line $line=explode(' ',str_replace(TAB,' ',trim($line)),2); if(isset($line[0]))$line[0]=strtolower(trim($line[0])); // state engine if($line[0]=='&lt;virtualhost'){ $entry=new stdClass(); continue; } if($line[0]=='&lt;/virtualhost&gt;' &amp;&amp; $entry!==null){ $entry-&gt;id=count($entries)+1; $entries[$entry-&gt;id]=$entry; $entry=null; continue; } if($line[0]=='servername' &amp;&amp; $entry!==null){ $entry-&gt;domain=str_replace('"','',trim($line[1])); continue; } if($line[0]=='documentroot' &amp;&amp; $entry!==null){ $entry-&gt;docroot=str_replace('"','',trim($line[1])); continue; } } return $entries; } /** * Backup vhost config file. * @return boolean True on success, false otherwise. */ function vhost_backup(){ if(!@file_exists(VHOST_FILE)) return @file_put_contents(VHOST_FILE,'') &amp;&amp; @copy(VHOST_FILE,ServerCentral::path().'vhost.conf.bak'); return @copy(VHOST_FILE,ServerCentral::path().'vhost.conf.bak'); } /** * Restore vhost backup file. * @return boolean True on success, false otherwise. */ function vhost_restore(){ return @copy(ServerCentral::path().'vhost.conf.bak',VHOST_FILE); } /** * Restarts apache/httpd service daemon. * @return boolean True on success, false otherwise. */ function httpd_restart(){ $r=System::execute('service httpd restart'); return $r['return']==0; } </code></pre> <p>Since I basically copy+pasted it, you might want to replace some stuff:</p> <ul> <li><code>ServerCentral::path()</code> - Absolute path to the current running script.</li> <li><code>System::execute</code> - Runs a shell command, works exactly like <a href="https://stackoverflow.com/questions/5673740/php-or-apache-exec-popen-system-and-proc-open-commands-do-not-execute-any-comm/5673872#5673872">this</a>.</li> <li><code>ISWIN</code> - Defined like this: <code>define('ISWIN', strpos(strtolower(php_uname()),'win')!==false &amp;&amp; strpos(strtolower(php_uname()),'darwin')===false );</code></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload