In this chapter we will get our development environment set up and configured in order to start development with Zend Framework 2.0. We will set up a PHP Application Server, install MySQL, and create a development database that will be used in subsequent chapters for our Zend Framework learning exercises. So, let's get started.
The last major release of Zend Framework, which happened in 2007, was version 1.0; during the last five years, Zend Framework has undergone a lot of changes to be a successful PHP-based framework. But by merely updating the framework, Zend Framework has retained some of the issues that were inherently present in Zend Framework 1.0.
Zend Framework 2.0 is an attempt to make Zend Framework better by rearchitecting the framework right from the core. Some of the key features of Zend Framework 2.0 over its previous version are listed as follows:
We will get to know about implementing the new features of Zend Framework 2.0 in the coming chapters.
In this chapter we will cover the installation and configuration of some of the prerequisites of Zend Framework 2.0. ZF2 can be installed on most PHP-enabled web servers that support PHP 5.3.3 or later.
We have used Zend Server Community Edition as our default web server; however, any other PHP stack that supports PHP 5.3.3 can be used. Alternatively, you can also download Apache and PHP separately and install PHP over Apache.
Zend Server Community Edition is the free version of the popular Zend Server stack. The Zend Server stack provides a pre-integrated PHP application stack that could be used across development, testing, and production. This enables application development teams to have a consistent environment across all stages of development.
Zend Server CE also provides features such as Zend Optimizer+ for PHP bytecode caching and Zend Guard for encoding files.
More details on the installation requirements can be found at http://www.zend.com/en/products/server/system-requirements.
Our next step will be to download and install Zend Server CE; I am running Ubuntu 12.04 Precise Pangolin. The installation procedure for other operating systems could be different; you can always refer to the Zend Server website for installation instructions. The following are the steps to install the Zend Server CE:
Visit the Zend Server Community Edition website (http://www.zend.com/en/community/zend-server-ce) and download the latest version of Zend Server that is applicable to your operating system. In this case, we will be downloading the Linux installer.
$ tar -zxvf ZendServer-5.6.0-RepositoryInstaller-linux.tar.gz
After extracting, the installer needs to be started with administrator privileges:
$ cd ZendServer-RepositoryInstaller-linux/ $ sudo ./install_zs.sh 5.3 ce
During the installation, the installer will request you to download various packages:
Zend Server will be installed into
/usr/local/zendby default; the default document root will point to
/var/www. You can use the following files to make configuration changes to the Zend Server instance:
Apache master configuration is available in
PHP configuration is controlled by
The following screenshot shows the installed location of Zend Server:
Zend Server CE is installed and ready to be used. Now we have a web server and a compatible version of PHP running—this satisfies the core requirements for running Zend Framework 2.0.
Your next task will be to install Git. We will be making use of Git when we are setting up our Zend Framework project.
Git binaries can either be downloaded from http://www.git-scm.com/ or installed from your operating system's repositories.
Installation instructions for Git can be found at the following link:
Managing PHP extensions
Configuring PHP directives
Managing Zend Server components
Monitoring PHP status, extension status, and application/server logs
In our next task, we will be making a configuration change to Zend Server by using its Administration Interface.
Open the admin console of Zend Server in your default browser (
When opening the Zend Server Administration Interface for the first time, you will be presented with a configuration wizard. Review and accept the terms and conditions of Zend's End User License Agreement page:
After the initial configuration wizard is completed, you will be redirected to the Zend Server Administration Interface's home page.
Navigate to Directives in Server Setup.
Set the value to
Click on Save Changes and then Restart PHP.
MySQL doesn't need an introduction—it is the world's most widely used open source database application. It's free and is available on the Internet to individuals and businesses that wish to develop their websites and applications using the MySQL database.
Zend Framework 2.0 has driver support for MySQL along with SQLite, PostgreSQL, and Microsoft SQL Server.
Our next exercise will be to install MySQL on our development machine. MySQL is available for download from all Linux repositories. Windows and Mac users will have to download the installer from the MySQL website (http://dev.mysql.com/downloads/).
In a standard Ubuntu installation, MySQL can be installed by executing the following command in the shell prompt:
$ sudo apt-get install mysql-server mysql-client
After the installation is complete, MySQL Server will start automatically. To check if MySQL Server is running, run the following command:
$ sudo netstat -tap | grep mysql
The command should give an output that is similar to the following; this means that the MySQL daemon is running:
tcp 0 0 localhost:mysql *:* LISTEN 923/mysqld
If, for some reason, MySQL Server is not running, you can start the server by running the
$ sudo service mysql restart
Having gone through this section, feel free to attempt the task in the following section.
phpMyAdmin is a free, open source web-based database administration tool written in PHP. phpMyAdmin provides a web-based UI to manage MySQL Database Server; add / remove / manage databases, users, privileges; and so on. In this book, we will be using phpMyAdmin as the database Administration Interface for managing our database(s).
Now that we have Apache, PHP, and MySQL installed, our next step will be to create a blank database in MySQL Server.
For doing this, we need to install and configure phpMyAdmin in the Zend Server.
phpMyAdmin can either be downloaded from http://www.phpmyadmin.net/ or installed from your operating system's repositories.
In our next task we will be creating a MySQL database, creating users in the MySQL server and also grant them access permissions to connect to the database and perform database operations.
Open phpMyAdmin in your web browser by visiting
After doing this you will get the following screen:
In the Database-specific privileges section, select the
You will be redirected to the privileges section of the
zf_appdatabase for the
zf_useruser. Choose Check All and click on Go.
We just created our first database in MySQL. We have also created a user in the database and mapped the user to the database with administrative rights; we can now use these credentials in the application that we will be building in our next chapters.
Now that you have the PHP web server up and running and also have a MySQL database, create a simple table called
Students and add a few records to the table using phpMyAdmin.
Your task will be to create a simple PHP web page that will display all the records in the
Students table in the page.
Q1. What is the minimum version of PHP needed to run Zend Framework 2.0?
PHP 4.3 and above
PHP 5.2.0 and above
PHP 5.3.3 and above
PHP 5.4.7 and above
Q2. What is the default location of
php.ini in the new Zend Server installation?
In this chapter we have learned the setup and configuration of Zend Server's PHP application stack. We went on to install MySQL Server and created our first database. In your exercises, you have learned about the installation of Git and phpMyAdmin.
In the next chapter, we will learn about the structure of a Zend Framework project and core MVC components such as views and controllers.