Lets say you want to run your project from a subfolder (in my case ‘xproject’) in your document root (in my case ~/Sites). So you want it to access via http://localhost/xproject and you do not want to be in hassle of creating virtual hosts (which you cannot do in shared hosting at all). These are the steps to do it.
- Copy the .htaccess file from you public folder and place it one older above
(in my case, copy ~/Sites/xproject/public/.htaccess to ~/Sites/xproject)$ cp ~/Sites/xproject/public/.htaccess ~/Sites/xproject/
Replace the lines there with these:
RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]
- Open the application.ini file of Zend Framework project (in my case ~/Sites/xproject/application/config/application.ini) in text editor of your choice and place this in development section (or your local environment section)
settings.baseUrl = "/xproject"
and save it.
-
Open the Bootstrap file of your application (in my case ~/Sites/xproject/application/Bootstrap.php)
protected function _initBaseUrl() { $options = $this->getOptions(); $baseUrl = isset($options['settings']['baseUrl']) ? $options['settings']['baseUrl'] : null; // null tells front controller to use autodiscovery, the default $this->bootstrap('frontcontroller'); $front = $this->getResource('frontcontroller'); $front->setBaseUrl($baseUrl); }
Save the file.
- And you are done. Fire your browser to http://localhost/xproject and you will see the project running