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.
-
you should really check for a better soloution, your selected answer causes many security risks!Andreas Linden– Andreas Linden2010-09-25 03:26:28 +00:00Commented 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.David Thomas– David Thomas2010-09-25 03:28:59 +00:00Commented Sep 25, 2010 at 3:28
-
uhm what? a virtualhost is the ONLY proper soloution for this problem ;)Andreas Linden– Andreas Linden2010-09-25 03:32:24 +00:00Commented 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...Andreas Linden– Andreas Linden2010-09-25 03:34:38 +00:00Commented 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 ;)Andreas Linden– Andreas Linden2010-09-25 03:36:21 +00:00Commented Sep 25, 2010 at 3:36
3 Answers
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.
2 Comments
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
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...