title: How to use ZEND modules (not Zend controller) as subdomain
body: <p>I have built my website using ZEND framework version 1.12.0. There are three other modules (admin, blog, images) in my site that i want to access as <a href="http://admin.mysitename.com" rel="nofollow">http://admin.mysitename.com</a>, <a href="http://blog.mysitename.com" rel="nofollow">http://blog.mysitename.com</a>, <a href="http://images.mysitename.com" rel="nofollow">http://images.mysitename.com</a> respectively. But, i am failing to access the subdomain. Please note: the modules have different action as well like update, add, archive etc.</p>
  
  <p><strong>.htaccess code:</strong></p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} -s [OR]
  RewriteCond %{REQUEST_FILENAME} -l [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [NC,L]
  RewriteRule ^.*$ index.php [NC,L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p><strong>Bootstrap.php:</strong></p>
  
  <pre><code>class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
      /**
       * Initialize the application autoload
       *
       * @return Zend_Application_Module_Autoloader
       */
      protected function _initAppAutoload(){
          $autoloader = new Zend_Application_Module_Autoloader(array(
              'namespace' =&gt; 'App',
              'basePath'  =&gt; dirname(__FILE__),
          ));
          return $autoloader;
      }
  
      /**
       * Initialize the layout loader
       */
      protected function _initLayoutHelper(){
          $this-&gt;bootstrap('frontController');
          $layout = Zend_Controller_Action_HelperBroker::addHelper(new Amz_Controller_Action_Helper_LayoutLoader());
      }   
  
      public function _initRoutes(){
          $frontController = Zend_Controller_Front::getInstance();
          $router = $frontController-&gt;getRouter();
  
          $route = new Zend_Controller_Router_Route ('cms/:page_url/',array('controller' =&gt; 'Cms','action'=&gt; 'index'));
          $router-&gt;addRoute('cms-page', $route);
  
  
          $router-&gt;addRoute('user', new Application_Route_User(
              'user',
              array(
                  'module' =&gt; 'default',
                  'controller' =&gt; 'Userdetail',
                  'action' =&gt; 'index'
              )
          ));
  
  
          $routeJoin = new Zend_Controller_Router_Route ('join/:id/',array('controller' =&gt; 'Index','action'=&gt; 'index'));
          $router-&gt;addRoute('join', $routeJoin); 
  
  
          $registration = new Zend_Controller_Router_Route ('registration/invitation/:id',array('controller' =&gt; 'Registration','action'=&gt; 'index'));
          $router-&gt;addRoute('registration', $registration);
  
  
      }  
  
      /**
       *Get the PDO database connection and set it to the Registry 
       */
      protected function _initDbConfig(){
          $config = new Zend_Config($this-&gt;getOptions());
          $params = $config-&gt;database-&gt;toArray();
          $DB = new Zend_Db_Adapter_Pdo_Mysql($params);    
          $DB-&gt;setFetchMode(Zend_Db::FETCH_OBJ);
          Zend_Registry::set('DB',$DB);
      }   
  
      /**
       *Get the smtp information and set it to the Registry 
       */
      protected function _initSiteConfig(){           
          $registry = Zend_Registry::getInstance();
          $DB = Zend_Registry::get('DB');     
          $selectSiteConfig= "SELECT * FROM site_config order by id"; //fetching available account types  
          $resultSiteInfo = $DB-&gt;fetchAssoc($selectSiteConfig);
          $site_config=array();
          foreach($resultSiteInfo as $row){
              $site_config[$row['config_name']]=$row['config_value'];         
          }   
          Zend_Registry::set('site_config',$site_config);
      }   
  
      /**
       * Setup the Custom Helpers
       */
      protected function _initSetHelper(){
          Zend_Controller_Action_HelperBroker::addPrefix('Helper');
      }   
  
  }
  </code></pre>
  
  <p><strong>index.php:</strong></p>
  
  <pre><code>ini_set("display_errors","on");
  // Define path to application directory
  defined('APPLICATION_PATH')
      || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
  
  // Define application environment
  defined('APPLICATION_ENV')
      || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
  
  
  //Ensure zend library is on include_path   
  $rootDir = dirname(__FILE__);
  set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());    
  
  /** Zend_Application */
  require_once 'Zend/Application.php';  
  
  // Create application, bootstrap, and run
  $application = new Zend_Application(
      APPLICATION_ENV, 
      APPLICATION_PATH . '/configs/application.ini'
  );
  
  
  
  $config = new Zend_Config_Ini('application/configs/application.ini','production');  
  
  $siteurl  = $config-&gt;siteurl;
  $sitedocroot = $config-&gt;sitedocroot;
  
  
  define('SITEURL',$siteurl); //DEFINE SITE URL AS CONSTANT
  define('SITEDOCROOT',$sitedocroot); //DEFINE SITE DOC ROOT AS CONSTANT
  define('FORMURL',$form_url);
  Zend_Registry::set('siteurl',$siteurl); //SET SITE URL IN REGISTRY
  Zend_Registry::set('sitedocroot',$sitedocroot); //SET SITE DOC ROOT IN REGISTRY
  
  
  
  $currentDate = date("Y-m-d");
  define('CURDATE',$currentDate);
  Zend_Registry::set('curdate',$currentDate);
  
  
  $currentDateTime = date("Y-m-d H:i:s");
  define('CURDATETIME',$currentDateTime);
  Zend_Registry::set('curdatetime',$currentDateTime);
  
  
  $detailDateForm= date("F j, Y");//March 22 2012
  define('DETAILDATE',$detailDateForm);
  Zend_Registry::set('detaildate',$detailDateForm);
  $application-&gt;bootstrap()-&gt;run();
  </code></pre>
  
  <p><strong>Steps i have followed:</strong></p>
  
  <p>1) Created separate sub-domains using cpanel. The subdomain have same DocumentRoot folder with domain.</p>
  
  <p>2) Wrote the below mentioned code in application.ini file (Mentioned the code only for images module)</p>
  
  <pre><code>resources.router.routes.images.type = "Zend_Controller_Router_Route_Hostname"
  resources.router.routes.images.route = ":module.mysitename.com"
  resources.router.routes.images.defaults.module = "images"
  resources.router.routes.images.chains.index.type = "Zend_Controller_Router_Route"
  resources.router.routes.images.chains.index.route = ":controller/:action/*"
  resources.router.routes.images.chains.index.defaults.controller
  </code></pre>
  
  <p><strong>Another steps i have followed:</strong></p>
  
  <p>1) Step 1 from above mentioned steps.</p>
  
  <p>2) Wrote the below mentioned code on main domain's bootstrap.php file (on _initRoutes function)</p>
  
  <pre><code>$router = Zend_Controller_Front::getInstance()-&gt;getRouter();
  
  $hostnameRoute = new Zend_Controller_Router_Route_Hostname(":images.mysitename.com");
  
  $router-&gt;addDefaultRoutes();
  foreach ($router-&gt;getRoutes() as $key=&gt;$route) {
  $router-&gt;addRoute('hostname' . $key, $hostnameRoute-&gt;chain($route));
  </code></pre>
  
  <p>I tried to get help from other site as well but found nothing important and most of them are mentioned for controller. </p>
  
  <p>Is my steps are correct? Please help me on this.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As per the post (suggested by David Weinraub), i have added below mentioned code on application.ini </p>
  
  <pre><code>resources.modules[] = "images"
  
  ; abstract routes to be used in chaining
  resources.router.routes.plain.type = "Zend_Controller_Router_Route"
  resources.router.routes.plain.abstract = true
  resources.router.routes.plain.route = "/:controller/:action"
  resources.router.routes.plain.defaults.controller = "index"
  resources.router.routes.plain.defaults.action = "index"
  
  resources.router.routes.mysite.type = "Zend_Controller_Router_Route_Hostname"
  resources.router.routes.mysite.abstract = true
  resources.router.routes.mysite.route = "images.mysitename.com"
  resources.router.routes.mysite.defaults.module = "images"
  
  resources.router.routes.mysite1.type = "Zend_Controller_Router_Route_Hostname"
  resources.router.routes.mysite1.abstract = true
  resources.router.routes.mysite1.route = "blog.mysitename.com"
  resources.router.routes.mysite1.defaults.module = "blog"
  
  ; now the actual (non-abstract) routes are chains of the abstract ones
  resources.router.routes.mysite-plain.type = "Zend_Controller_Router_Route_Chain"
  resources.router.routes.mysite-plain.chain = "mysite,plain"
  
  resources.router.routes.mysite1-plain.type = "Zend_Controller_Router_Route_Chain"
  resources.router.routes.mysite1-plain.chain = "mysite1,plain"
  </code></pre>
  
  <p>But, this did not solve. I am getting the below mentioned error.</p>
  
  <pre><code>Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(/home/debcho/public_html/application/../../Library/ZendX/Application/Resource/Frontcontroller.php) is not within the allowed path(s): (/home/debcho/public_html:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/debcho/public_html/library/Zend/Loader.php on line 186
  
  Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /home/debcho/public_html/library/Zend/Loader.php/186' in /home/debcho/public_html/library/Zend/Session.php:451 Stack trace: #0 /home/debcho/public_html/library/Zend/Session/Namespace.php(143): Zend_Session::start(true) #1 /home/debcho/public_html/application/Bootstrap.php(128): Zend_Session_Namespace-&gt;__construct('Zend_Auth_LipyU...') #2 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap-&gt;_initSetUserAccessPermission() #3 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract-&gt;_executeResource('setuseraccesspe...') #4 /home/debcho/public_html/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract-&gt;_bootstrap(NULL) #5 /home/debcho/public_html/library/Zend/Application.php(355 in /home/debcho/public_html/library/Zend/Session.php on line 451
  </code></pre>