Installing ZF2 on a shared hosting server

advertisements

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

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

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

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

  4. 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
    
    

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

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

    SetEnv PHPRC /home/mycpanalusername/public_html/zendPrj/Zend/php.ini
    
    
  6. 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?


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

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

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)

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]

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

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.

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!