Zend Framework on shared hosting

2019-01-13 04:58发布

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!

12条回答
Fickle 薄情
2楼-- · 2019-01-13 05:17

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))

查看更多
Evening l夕情丶
3楼-- · 2019-01-13 05:19

Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.

Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:

Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.

Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:

 <VirtualHost *:80>
     ServerName zf2-tutorial.localhost
     DocumentRoot /path/to/zf2-tutorial/public
     SetEnv APPLICATION_ENV "development"
     <Directory /path/to/zf2-tutorial/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.

Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1.

查看更多
该账号已被封号
4楼-- · 2019-01-13 05:21

i think the best way is to remove the .htaccess from the public directory (Zend Framework Directory structure) , and put it with the following content into your "root" directory :

 
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]

查看更多
成全新的幸福
5楼-- · 2019-01-13 05:22

Actually I've searched for it and found a lot of answers (most of them here on SO), but none of them worked for me. So I finally found a solution - .htaccess on root dir:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php

This one from http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter and index.php on root dir:

<?php 
define('RUNNING_FROM_ROOT', true);
include 'public/index.php';
?>

This one from http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/ And it works for me even if there are other project dir in root folder - like forum or so. Thought it might be useful to someone :)

查看更多
看我几分像从前
6楼-- · 2019-01-13 05:22

I encountered this problem recently and through this thread i was able to find a solution. I am using zf2. So all i had to do was have the zend related files in a directory we can name say src. This directory will reside in the public or root directory (such as /www)

  1. Create a .htaccess file in the 'src' dir and add the Deny from All directive.

  2. In the index file, change the working directory to the src folder by doing the following:

    define('SRC_ROOT', 'src');
    chdir(SRC_ROOT);
    

...and you are good to go!

查看更多
beautiful°
7楼-- · 2019-01-13 05:25

Also Rob Allen wrote a good solution

I'm using Zend Framework 2 and it worked for me. Alghough I haven't done part "Referencing public facing files" from above link.

I just changed code in my layout.phtml from:

$basePath = $this->basePath();

to:

$basePath = $this->basePath();
if (defined('RUNNING_FROM_ROOT')) {
    $basePath .= 'public/';
}
查看更多
登录 后发表回答