Deploying Zend Framework applications on a shared host

Hello everybody!

Usually I have direct access (shell) in all the servers that host my Zend Framework applications, but, some clients already have a shared host, so I have to deploy the application there too.

I was thinking how can I never thought this before! There are a lot of ways to deploy a Zend Framework application, but in a shared host we can’t have access to create Virtual Hosts on Apache.

Folder structure

On a shared host you have your own folder, which you can upload your PHP files. That’s my client’s folder structure:

Take a look on the public_html folder. It’s the folder where usually we upload our PHP files. Some hosts call it htdocs too.

Zend Framework’s structure

Basically, the default ZF’s structure has 5 folders: application, docs, library, public and tests.


Inside ZF’s public folder we have images, javascript files, css files, etc, all that have direct access through url. In other words, we put only the public folder’s content in the public_html folder on our shared host.

Let’s create another folder and let’s call it php_apps. Inside it let’s create another folder, to host our application files (app1 folder). That folder will receive all the ZF’s folders (except public folder, of course).

So let’s put our application, docs, library and tests folder inside it.

New, all we need is tell the index.php to access the new folder. Let’s edit it (line 4):


// Define path to application directory  
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../php_apps/app1/application'));

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

// Ensure library is on include_path  
set_include_path(implode(PATH_SEPARATOR, array(  
    realpath(APPLICATION_PATH . '/../library'),  

/** Zend_Application */  
require_once 'Zend/Application.php';

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


Now, accessing your public_html folder (or we’ll call the index.php file, that calls our application folder (inside php_apps/app1).

To work with images, css, etc, in your view files, is exactly the same:

<?php echo $this->baseUrl('/img/my_image.gif'); ?>

That’s all! Thanks!

Subscribe to my Weekly Newsletter (on every Monday) and be emailed when a new blog post is published on my blog.

Published by

Junior Grossi

Senior PHP Engineer with TDD focus. Husband & Dad. Creator of Corcel PHP. Organizer of PHPMG. Software Engineer at InterNACHI. Loves coffee and music.