views:

3008

answers:

9

I'm new to Zend Framework. I would like to know how to implement zend framework on a shared hosting. Because of the zend framework folder structure all view files are put into the "public" folder.

Suppose

"/" is the main root folder for me and public is like "/public"

so that the url becomes "http://site/public/. .. .bla bla..."

is this correct?

or is there any other method?

i dont have any permission to create a virtual host.

so what to do?

I hope that you understood my question. If not, please ask me.

Thank you!

A: 

Indeed it's not the best idead to run Zend Framework applications on a shared hosting. I would really recommend getting a virtual private hosting (VPS). There are very good and inexpensive hostings out there with Zend Framework and other frameworks already installed and regularly updated. I'm on servergrove and it has been great so far!

But this doesn't mean that you can't make it work on a shared hosting. You just have to rather work with .htacess. Put the content of the public folder into your webroot and adjust your paths in the bootstrap.php, make sure all other folders cannot be accesses directly and use the usual ZF approach of routing everything through your index.php.

tharkun
Details on my own implementation of this approach: http://bit.ly/btQGbh
David Weinraub
+5  A: 
ArneRie
hi - just wondering can you spot anything wrong with the details i posted at the bottom of this thread?
emeraldjava
Possible n00b question: What effect will this have on ZF routing? That is, won't the "/public" prefix be part of the url that ZF sees (I guess via the $request object)? As a result, do all ZF Routes now need to be "/public" aware? That would be pretty undesirable, wouldn't it?
David Weinraub
A: 

I suggest the simpliest: Develop your apps in a way where index.php is in your root (even better - always define PUBLIC_PATH - dirname(__FILE__); in your index.php and make links relative to this constant). Along with the application and library folders. You can easily make them unaccessible from outside using deny from all in .htaccess.

The PUBLIC_PATH constant also helps when your public is not public. (public html or /public html/www (in my case))

Tomáš Fejfar
A: 

I've been in the same situation and have put the zend libraries under a folder under public like 'src' - and use an .htaccess Deny from All. You'll have to juggle a couple paths, but it works fine.

Justin
+2  A: 

Include this .htacces file under your base path (that is /../public):

RewriteEngine On

# Exclude some directories from URI rewriting
#RewriteRule ^(dir1|dir2|dir3) - [L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

And leave the .htaccess that was under the publc directory where it was.

So you will have 2 .htaccess files, one under the public directory (the ordinary one from Zend Framework documentation) and second one under your base path (the one I posted above).

Richard Knop
hi - just wondering can you spot anything wrong with the details i posted at the bottom of this thread?
emeraldjava
I tried this, but it does not find other directories, which link to application folder outside the public folder. Other simple pages work
mrNepal
A: 

. . . How Magento uses Zend framework??? I'm using XAMPP and I did install Magento locally without modify php.ini, http.conf nor virtual host.

A: 

Not really an answer just a follow question, and the comments section is too small.

My root .htaccess file is the same as above.

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

My ./public/index.php contains

<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 'on');

// define the base path
define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));

// Define path to application directory
define('APPLICATION_PATH', BASE_PATH . '/application');

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

set_include_path(
    implode(PATH_SEPARATOR, 
        array(
            realpath(BASE_PATH . '/library'),
            realpath(BASE_PATH . '/application'),
            get_include_path()
        )
    )
); 

// echo get_include_path();

/** Zend_Application */
require_once 'Zend/Loader/AutoLoader.php';
Zend_Loader_Autoloader::getInstance();

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini'
);

$application->bootstrap()->run();
?>

My /public/.htaccess file has

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I've been developing on XP, but when i deploy to a linux server i get this exception.

Warning: require_once(Zend/Loader/AutoLoader.php) [function.require-once]: failed to open stream: No such file or directory in home/bhaa1/public_html/members/public/index.php on line 28

Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader/AutoLoader.php' (include_path='/home/bhaa1/public_html/members/library:/home/bhaa1/public_html/members/application:.:/usr/local/php52/pear') in /home/bhaa1/public_html/members/public/index.php on line 28

I can see that the lib and app dir's are on the path, and I've checked the permissions on various files and folders in my lib's dir and the default 755. Not sure what i'm missing.

emeraldjava
Your "require_once" is wrong i think. The L is an capital-letter in your command, but it muste be :require_once 'Zend/Loader/Autoloader.php';
ArneRie
A: 

You should place your project's Public folder to www folder in the host, so your address will become yourdomain.com/. Your source code folder such as library, applications... should be place at same level with www folder, not within it. This method will promote the security of your site

Thang Nguyen
A: 

Many thanks! One question: If the project is not in the webroot zend, but in a subfolder?

Example webroot: - Files - Project zend --- .htaccess --- application --- library --- public --- tests

I tried to put the htaccess in the subfolder you reported zend project, but by error 404!

How can I fix? Thanks

JellyBelly