2009-07-12 68 views
16

我是Zend Framework的新手。我想知道如何在共享主機上實現zend框架。由於zend框架文件夾結構 所有視圖文件都放在「公共」文件夾中。Zend Framework共享主機

假設

「/」是我主要的根文件夾和公共就像 「/公衆」

,使URL成爲「http://site/public/ .. .bla喇嘛......」

這是正確的嗎?

還是還有其他方法嗎?

我沒有任何權限來創建虛擬主機。

那該怎麼辦?

我希望你能理解我的問題。如果沒有,請問我。

謝謝!

回答

12

我認爲最好的方法是刪除從(Zend Framework的目錄結構)公共目錄中的.htaccess,並把它與下面的內容到你的「根」目錄:


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]

+0

嗨 - 只是想知道你能發現我在這個帖子底部發布的細節有什麼問題嗎? – emeraldjava 2009-09-03 12:30:27

+0

可能的n00b問題:這對ZF路由有什麼影響?也就是說,「/ public」前綴不會成爲ZF看到的url的一部分(我猜想通過$ request對象)?因此,現在所有的ZF路線都需要「/公衆」意識嗎?這將是不可取的,不是嗎? – 2009-12-10 07:10:19

+0

在哪裏放置環境的設置? – JellyBelly 2012-04-19 09:04:35

1

事實上,它不是在共享主機上運行Zend Framework應用程序的最佳理想選擇。我真的會推薦一個虛擬私人主機(VPS)。 Zend Framework和已經安裝並定期更新的其他框架有非常好的和便宜的主機。我在servergrove,到目前爲止一直很棒!

但這並不意味着你不能使它在共享主機上工作。你只需要使用.htacess。將公用文件夾的內容放入webroot中,並在bootstrap.php中調整路徑,確保所有其他文件夾不能直接訪問,並使用通常的ZF方法將所有內容路由到index.php。

+0

關於我自己實現這種方法的詳細信息:http://bit.ly/btQGbh – 2010-05-08 17:22:16

-1

我建議最簡單的方法是:以index.php位於根目錄的方式開發應用程序(甚至更好 - 總是在index.php中定義PUBLIC_PATH - dirname(__FILE__);並使鏈接相對於此常量)。與應用程序和庫文件夾一起。使用.htaccess中的deny from all可以輕鬆地使其無法訪問。

當你的公衆不公開時,PUBLIC_PATH常量也有幫助。 (public html或/ public html/www(在我的情況下))

0

我一直處於相同的情況,並已將zend庫放在公共文件夾下,如'src' - 並使用.htaccess Deny所有。你將不得不玩弄幾條路徑,但它工作正常。

10

包含該.htacces文件的基本路徑下(即/../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] 

並留下那是publc目錄,它是下的.htaccess。

所以你會有2。htaccess文件,一個在公共目錄下(來自Zend Framework文檔的普通文件),另一個在你的基本路徑下(我在上面發佈的)。

0

。 。 。 Magento如何使用Zend框架?我使用的是XAMPP,並且我在本地安裝了Magento,而無需修改php.ini,http.conf和虛擬主機。

2

您應該將項目的公用文件夾放在主機的www文件夾中,這樣您的地址將成爲yourdomain.com/。 您的源代碼文件夾如庫,應用程序...應與www文件夾放在同一層,而不是放在它之內。這種方法將促進您的網站的安全

1

ArneRie的答案不適合我,我最終結束了使用Lorenzo Albertons solution。希望這有助於他人獲得更快的解決方案。

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

其實我已經搜索了一下,發現很多答案(其中大部分在這裏SO),但他們沒有爲我工作。所以,我終於找到了解決辦法 - 的.htaccess的根目錄:

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

這一個從http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter 和index.php文件的根目錄:

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

這一個從http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/ 它爲我的作品即使有其他項目目錄在根文件夾 - 如論壇等。 認爲它可能是有用的人:)

1

而且Rob Allen wrote a good solution

我使用Zend框架2,它爲我工作。 Alghough我還沒有做過「參考公共文件」從上面的鏈接。

我只是改變代碼在我layout.phtml來自:

$basePath = $this->basePath(); 

到:

$basePath = $this->basePath(); 
if (defined('RUNNING_FROM_ROOT')) { 
    $basePath .= 'public/'; 
} 
0

最近我遇到了這個問題,並通過這個線程我能找到一個解決方案。我正在使用zf2。所以我所要做的就是在一個目錄中有zend相關的文件,我們可以命名爲src。該目錄將駐留在公共或根目錄下(如/www

  1. 在「SRC」目錄創建一個.htaccess文件,並添加來自所有指令拒絕。

  2. 在索引文件中,通過做工作目錄​​更改爲src文件夾下面的:

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

...你是好去!

0

設置虛擬主機通常在httpd.conf或extra/httpd-vhosts.conf中完成。如果您使用的是httpd-vhosts。conf,確保這個文件包含在你的主httpd.conf文件中。一些Linux發行版(例如:Ubuntu)打包Apache,以便配置文件存儲在/ etc/apache2中,併爲啓用/ etc/apache2/sites-enabled的文件夾中的每個虛擬主機創建一個文件。在這種情況下,您可以將下面的虛擬主機塊放入文件/ etc/apache2/sites-enabled/zf2-tutorial中。

確保了NameVirtualHost被定義並設置爲「*:80」或類似的,然後定義沿着這些線路虛擬主機:

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.

確保您更新/ etc/hosts或c:\ windows \ system32 \ drivers \ etc \ hosts文件,以便將zf2-tutorial.localhost映射到127.0.0.1。