在共享托管服务器上安装 ZF2 [英] ZF2 installation on shared hosting server

查看:30
本文介绍了在共享托管服务器上安装 ZF2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的共享托管服务器上安装 ZF2.我按照以下步骤操作:

I am trying to install ZF2 on my shared hosting server. I followed these steps:

  1. 在我的电脑上下载并解压 Zend Framework 2.

  1. Downloaded and extracted Zend Framework 2 on my computer.

在我的public_html"上创建了一个名为zendPrj"的目录.

Created a directory on my "public_html" with the name of "zendPrj".

使用 Filezilla 将Zend"目录上传到zendPrj"文件夹中.

Uploaded the "Zend" directory using Filezilla into the "zendPrj" folder.

使用以下命令创建php.ini":

Created a "php.ini" with the following commands:

include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/public_html/mycpanalusername/zndPrj/Zend/library"
allow_url_fopen = On
allow_url_include = On

并将其上传到Zend"文件夹(其中包含library"、bin"、resources"文件夹).

and uploaded it into the "Zend" folder (which has got the "library", "bin", "resources" folders in it).

使用以下指令创建了一个.htaccess"文件:

Created a ".htaccess" file with the following instruction:

SetEnv PHPRC /home/mycpanalusername/public_html/zendPrj/Zend/php.ini

  • 创建一个测试文件如下:

  • Created a testing file as follows:

    require_once 'Zend/Mail.php';
    $mail=new Zend_Mail();
    print_r($mail);
    echo 'it is working';
    

  • 但是我没有得到任何结果.而是显示一个空白页.我哪里出错了?

    But I don't get any results. Instead, a blank page is shown. Where am I going wrong?

    推荐答案

    好的,这就是我在共享主机中设置 ZF2 应用程序的方式

    OK, this is how I had setup ZF2 application in my shared hosting

    我的应用程序的文件夹结构,应复制到子域文件夹(与zf2应用程序结构相同)

    folder structure for my application which should be copied to the sub domain folder (which is same as zf2 application structure)

    第 1 步:将 zf2 库(即 zendframework 下载中的 ZEND 文件夹)复制到主机的根文件夹,即复制后它看起来像这样(在我的情况下)/home/username/zf2lib/ZEND(任何位置无法通过公开)

    Step 1: copy zf2 library (i.e ZEND folder inside zendframework download) to the root folder of your host i.e. after copy it looks like this(in my case) /home/username/zf2lib/ZEND (any location not accessible by public)

    第 2 步:编辑 .htaccess

    Step 2: edit .htaccess

    #SetEnv ZF2_PATH /home/username/zf2lib
    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]
    

    第 3 步:编辑 init_autoloader.php 以指向 zf2 库,在此我们有两个选项 1. 如果您的主机支持 .htaccess 中的 SetEnv 标记,则只需取消注释上述 .htaccess 中的第一行(主要是共享主机不t 提供这些选项,特别是在我的情况下)如果选项 1 是不可能的,那么你必须编辑 init_autoloader.php 文件如下

    Step 3: edit init_autoloader.php to point to zf2 library, in this we have two option 1. if your host support SetEnv tag in .htaccess then simply uncomment the first line in the above .htaccess (mostly shared host don't provide these option, especially in my case) if the option 1 is not possible then you have to edit the init_autoloader.php file as below

    注释掉第 24 行到第 32 行,这段代码负责初始化 zend 库的各种选项,在我们的例子中我们知道 zf2 库的加载位置,所以我们将硬编码路径,添加第 33 行并更改username 到您的主机用户名.

    Comment out from line 24 to 32, this code is responsible for various option to init the zend library, in our case we know where zf2 lib are loaded, so we are going to hard code the path, add line 33 and change username to your host user name.

    最后一步:将所有这些内容复制到您的子域文件夹并通过 subdomain.domain.com 访问该站点,这对我来说一切正常,希望它也对您有用,祝您好运!

    Final step: copy all this content to your sub domain folder and access the site with subdomain.domain.com it all works well for me, hope it work for you too, good luck!

    这篇关于在共享托管服务器上安装 ZF2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆