Zend Framework Intro Step by Step Tutorial
Get started with Zend Framework from scratch. Covers installation, folder structure, Apache configuration, and your first controller-action-view cycle.
What Is Zend Framework?
Zend Framework is a component-based PHP framework that follows the MVC pattern. It was created by Zend Technologies (the company behind the PHP engine) and became one of the most widely used enterprise PHP frameworks. The project has since evolved into Laminas, but thousands of applications still run on Zend Framework 1.x.
This pack is your starting point. It covers everything you need to go from a fresh download to a working application skeleton.
Pack Overview
Four articles guide you through setup. The basic tutorial handles installation and your first page. Two folder structure articles explore the conventional directory layout from different angles. The .htaccess article ensures clean URLs work with Apache.
Read them in order. Each one builds on the previous.
Walkthrough
Step 1 - Download and Install
Download the Zend Framework library and extract it. You need the Zend/ folder from the library/ directory. Place it somewhere on your PHP include path or within your project:
1 | myproject/ |
The framework is just PHP files. There is no compilation step, no binary dependencies. Drop the files in place and you are ready.
Step 2 - Create the Entry Point
All requests go through public/index.php. This file does three things:
- Defines path constants (
APPLICATION_PATH,APPLICATION_ENV) - Sets the include path to find the Zend library
- Creates a
Zend_Applicationinstance and callsbootstrap()->run()
A minimal version looks like:
1 | defined('APPLICATION_PATH') |
Step 3 - Set Up the Folder Structure
The framework expects a specific layout. Controllers go in application/controllers/, view scripts in application/views/scripts/, and models in application/models/. Configuration files live in application/configs/.
The two folder structure articles explain the naming rules:
- Controller files are named
SomethingController.php - Controller classes are named
SomethingController - View scripts are organized in subdirectories matching controller names
- The
IndexControllerhandles the default route
Getting the folder structure right the first time prevents confusing errors. The framework’s autoloader relies on these conventions to find classes.
Step 4 - Configure Apache and .htaccess
Create public/.htaccess with rewrite rules that send all non-file requests to index.php:
1 | RewriteEngine On |
The conditions check whether the request matches an existing file, symlink, or directory. If it does, Apache serves it directly (images, CSS, JavaScript). Otherwise, everything goes to index.php.
Make sure AllowOverride All is set for your document root in the Apache virtual host config. Without it, .htaccess files are ignored silently.
Your First Page
With everything in place, visiting http://localhost/myproject/public/ should trigger IndexController::indexAction(). Create the controller and a view script:
application/controllers/IndexController.phpapplication/views/scripts/index/index.phtml
The view script is plain HTML with embedded PHP. The controller passes data to it through $this->view->variableName.
Common Pitfalls
Include path not set correctly. If you get “Class not found” errors for Zend classes, the include path does not reach the library directory. Verify with echo get_include_path().
mod_rewrite disabled. On Ubuntu/Debian, run a2enmod rewrite and restart Apache. On XAMPP it is usually enabled by default.
Wrong document root. Apache should point to the public/ directory, not the project root. If the document root is wrong, the .htaccess file will not be found.
FAQ
Do I need Composer?
Not for Zend Framework 1. The library is self-contained. Composer support was added later and is more common with Zend Framework 2 and Laminas.
Can I use Nginx instead of Apache?
Yes. Replace the .htaccess rewrite rules with a try_files directive in your Nginx server block. The concept is the same: send all requests to index.php.
Is this framework still maintained?
Zend Framework 1 reached end-of-life. Security patches are not released. For legacy projects it is fine to study and maintain. For new work, look at Laminas.
How long does it take to learn?
If you know PHP and basic OOP, you can have a working project in an afternoon by following this pack. Mastering the full component library takes longer, but you do not need all of it at once.
What if I see a white screen?
Enable display_errors in php.ini or add ini_set('display_errors', 1) at the top of index.php. The white screen usually means a fatal error that PHP is hiding.
Articles in This Pack
Pack Checklist
- PHP 5.2.4 or later installed
- Apache web server with mod_rewrite
- Zend Framework library downloaded
- A terminal or command line for file operations
- Basic familiarity with PHP and object-oriented concepts