1

By default my script is accessible by using this url http://localhost/myscript/public/. But i need to access it by this url http://localhost/myscript/. How can i do this in Zend Framework.

5
  • you should really check for a better soloution, your selected answer causes many security risks! Commented Sep 25, 2010 at 3:26
  • why in the name of sanity would you want to? This is, as noted so emphatically by @zolex, not a good idea. It's possible (obviously), but not wise. Commented Sep 25, 2010 at 3:28
  • uhm what? a virtualhost is the ONLY proper soloution for this problem ;) Commented Sep 25, 2010 at 3:32
  • on a production system you NEVER have anything else than the public folder accessable via http, otherwise you'll be an easy victim for exploits and stuff... Commented Sep 25, 2010 at 3:34
  • and that means if you won't wat to rewrite your whole application when ie. running it directly on a domain like myLocallyDevelopedZendApp.com you should listen to what i say ;) Commented Sep 25, 2010 at 3:36

3 Answers 3

1

The "public" folder is an important key feature of the Zend Framework because it confines Apache to only read files in that directory and, if used properly, would keep all your other code outside public visibility. If you are indeed putting your entire application up and you have to do /public/index.php to get where you want to go, you should be aware of this.

Typically, in a shared hosting configuration, you will have a public folder for your site and you separate your public folder from the rest of your application. Say for instance you have a "public_html" folder in your directory, and that is the visible folder for your domain. Then, following that logic, instead of putting everything you wanted into your home directory, you "install" your application into a custom made sub-directory called "zend_app". You would copy the files from "public" into the "public_html" folder, copy the rest of the files into the "zend_app" folder and customize your index.php file apprioriately, for example:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend_app/application'));

Most of the other zend configuration is derived from that definition so it's fairly safe to build from that. If you keep that in mind when configuring your application, you can help maintain this portability. In theory, using this, you should be able to construct a configuration that would work for your needs.

Sign up to request clarification or add additional context in comments.

2 Comments

the problem may persist coz major hosting provider provide public_html or public as root directory?
well, in general the url a zend application is called with, must not have any impact on it's functionality and look. i achieve this by setting the so called base-url in the config for mandatory use in the hole application. depending on the application envirionment the base url may then vary from his development machnine with "/myscript/public/" over stuff like staging and testting and typically "/" on a production machine as well as otehr developers with all individual setups.
1

simply create a virtualhost using your webserver and configure it to use the folder "public" as the document-root and you'll be fine and secure.

1 Comment

@Andreas Linden: you have to told the way to do this ... can you ?
-1

just put all files from the public folder into the root folder.

then open the index.php or bootstrap.php, where ever you have this code

set_include_path(‘.’
        . PATH_SEPARATOR . get_include_path()
        . PATH_SEPARATOR . ‘../library’
        . PATH_SEPARATOR . ‘../application/classes/’
        . PATH_SEPARATOR . ‘../application/models/’

and change it to this one

set_include_path(‘.’
        . PATH_SEPARATOR . get_include_path()
        . PATH_SEPARATOR . ‘library’
        . PATH_SEPARATOR . ‘application/classes/’
        . PATH_SEPARATOR . ‘application/models/’

but check other pathes too, like this one.

require_once 'Zend/Controller/Front.php';

Got this tutorial from this page :) http://www.fincha.com/blog/2010/tutorial-zf-public-verzeichnis-umgehen-nicht-verwenden/

Its in German...

5 Comments

WOW THIS IS MADNEDSS PURE!!!! DO NOT DO THIS, THIS WILL CAUSE MANY MANY SECURITY LEAKS!!! see my answer for a proper soloution
@zolex yes it does, but on my host I can't use directrly the public folder... so I have to use it this way. or if you have 2 application first one is domain.com/first/ and second domain.com/second, how you gonna do this???
just configure apache properly ^^
this is no problem to do this on a local server, but not every "public" server let you do this...
@Fincha: why should you want to use such a great framework on such a bad server which does not allow proper configuration?... change your provider ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.