title: Deploy ZF2 site to shared host
body: <p>When you deploy a Zend Framework website to a shared host, you usually cannot change the DocumentRoot to point at the public/ folder of the website. As a result the URL to the website is now <a href="http://www.example.com/public/" rel="nofollow">http://www.example.com/public/</a>. This doesn't look very professional, so I'd like to remove it. Up to now I have used ZF1 and Rob Allen kindly provides a method for doing this on his blog <a href="http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/" rel="nofollow">http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/</a> . I have tried to modify this for ZF2. He proposes placing an index.php file in the root with the line: </p>
  
  <p><code>include 'public/index.php';</code></p>
  
  <p>After doing this, <a href="http://www.example.com" rel="nofollow">http://www.example.com</a> opens the index page OK but the CSS links are broken. Rob adds a controller plugin to reset the baseUrl to /public to deal with public facing CSS and image files etc. To do this in ZF2 I found an item from Matthew Weier O' Phinney <a href="http://zend-framework-community.634137.n4.nabble.com/Setting-the-base-url-in-ZF2-MVC-td3946284.html" rel="nofollow">http://zend-framework-community.634137.n4.nabble.com/Setting-the-base-url-in-ZF2-MVC-td3946284.html</a> where he describes how to set the baseUrl. Based on his code I added this to modules/Application/Module.php</p>
  
  <pre><code>class Module {
      public function onBootstrap(MvcEvent $e) {
          $config          = $e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('config');
          $router          = $e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('router');        
          $router-&gt;setBaseUrl($config['base_url']);
      }
  }
  </code></pre>
  
  <p>The base_url key is set in  modules/Application/configs/module.config.php:</p>
  
  <p><code>'base_url' =&gt; '/public'</code> </p>
  
  <p>I was able to dump the router object and confirm that the base_url was being set correctly at this stage. Unfortunately, now <a href="http://www.example.com" rel="nofollow">http://www.example.com</a> no longer opens the index page and gives a 404 routing error.</p>
  
  <p>Is anyone able to tell me what I am doing wrong or point me in the right direction for running a ZF2 site in a shared hosted environment?</p>