Quantcast
Channel: Anil Konsal
Viewing all articles
Browse latest Browse all 10

Running Zend Framework Project from a subfolder

$
0
0

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.

  1. 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]
  2. 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.

  3. 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.

  4. And you are done. Fire your browser to http://localhost/xproject and you will see the project running

Viewing all articles
Browse latest Browse all 10

Trending Articles