Interview Questions

Getting Started with Zend Framework

Regardless of your programming skills, you have decided to make your way into the Zend Framework world. Some of you might be new to programming; others might be seasoned developers heading a large team. Regardless of your status or reasons why you want to enter the Zend Framework world, everyone starts on the same page.Yes,stop your groaning; that means setting up the environment and dealing with the technology that will get you up and running toward building your application powered by Zend Framework.

You might be wondering why you need to go through this process. That’s fair; when I started developing PHP applications, I asked the same question—but I continued to follow the steps to set up the environment. Looking back to my experience, I can say that setting up the environment will give you a few things right away. For new developers, it will introduce the technology Zend Framework needs to successfully start developing applications. Think about it like this: if I gave you a box of tools and asked you to build a house, how on earth would you go about accomplishing that task if you didn’t know how to use each of the tools in the box? So you also need to learn which tools you need to build your figurative house: a Zend Framework application.

If you know which tools are needed to run applications, you will understand the limitations of those applications. If your boss came up to you, stared into your eyes, and (besides telling you that you rock) said, “I need a Zend Framework application that will handle ten million users per month, a few hundred thousand hits per minute and have a response time of less than a second. Can you do it?” You should be able to tell him, “Yeah, I rock. What’s new?” You can also say, “Yes! You’ll have it in a month, with all the bells and whistles you asked for.” I can’t promise that Zend Framework will handle 1,000 hits per second because that’s for your load balancer to handle, but I do promise that Zend Framework will make it fun for you to deliver the product on time.

The goal of this chapter is to set up a development environment with all the free tools available:

  • Apache 2.2
  • MySQL 5.1 or later
  • PHP 5.2.4 or later.
  • Zend Framework 1.8

You will also create your first Hello World application powered by Zend Framework and review the basic components required to power all Zend Framework applications efficiently.

The Tools

Let’s open up that toolbox now and see what’s in there. You see a hammer, some nails, and a blow torch,enough to start a house. Don’t worry; installing your tools will be an easy process. If you’re a senior developer, take a look at the list of software and determine whether you need to read this section or not.If you feel comfortable installing the tools on your own, or if you already have a development environment that will run the required PHP version, skip these few sections and start with the “Installing Zend Framework” section later in this chapter.

Regardless of your experience, take the time to read through the installation and setup process of Zend Framework and create the small Hello World application outlined in this chapter. Trust me;it will prove invaluable to read the section and create the test application.  Let’s begin installing the development environment step by step.


You will start with the base software that most web applications need: Apache. Without Apache, most web applications installed on computers could not communicate with the world.

Installing Apache on Windows

As of this writing, Apache has released version 2.2.x of its free web server. If you have a hosted web server you can use it; depending on your setup you might need to skip this section and head toward the “Installing Zend Framework” section. For everyone else, let’s start the process of installing Apache on your computer.

Pull up the Apache web site (, click the “Download! from a mirror” link on the left side, and select from one of the mirror sites shown on the following page. Windows users:download the Windows installer file apache_2.2.x-win32-x86-no_ssl-r2.msi.

After the file has completely downloaded, open the installer. The initial window will be a security warning. Depending on your version of Windows, ignore it and click Run to get into the installation.

The next window is the Apache setup window. If you have a previous version of Apache installed, you might see another pop-up window that asks you to remove the previous installation before you begin the new one.

In the License Agreement window that displays, select “I accept the terms in the license agreement” and click Next. Click Next in the following window.

The Server Information window displays. You need to fill in all the fields.Because this will be a web server operating on your desktop, you can add any domain name and network name into the Network Domain and Server Name fields, respectively. I chose to enter localhost for both of those fields. Enter your e-mail address in the Administrator’s Email Address field and then click Next.

Next, start installing the software. You need to tell the Apache Installation Wizard where to install it. The window shown allows you to do just that. Click Custom and then click Next.

In the Custom Setup window shown below, click Change.

For ease of use throughout this book, I recommend that you change the location of the installation directory in the Change Current Destination Folder window to C:Apache (if you want to save Apache in an alternative location, that’s fine, too).


Finally you’re at the last window. Click Install and watch it go. That’s all there is to it. You have successfully installed a web serveron your computer.

Installing a Mac Development Environment

Mac users, you’re in luck. Installing a complete development environment with Apache, MySQL, and PHP requires you to download only one all-in-one package, MAMP (Macintosh, Apache, MySQL, and PHP). The package can be found here: ahead and load the URL in your browser as you continue reading.

After the page loads, click the Downloads link. You’ll see two available versions of the package at this point. For your environment, you’ll be okay with the basic MAMP version, not the MAMP & MAMP Pro version. Click the Download link and wait for it to download.

As soon MAMP completely downloads, double-click the .dmg file saved to your computer and install MAMP into the Applications folder.

Caution It’s critical that you do not install MAMP in a subfolder; it will not work properly if this is done.

The manager will appear. If everything worked as expected, you should see the MAMP manager display a green indicator on both the Apache Server status and the MySQL Server status.

You’re almost done. Click Preferences, and you’ll be presented with a window much like Figure

Click “Set to default Apache and MySQL ports” and then click OK. This will allow you to disregard the port number when loading a URL on your browser. You now have installed not only a web server but also a database server.

Note The default installation of MAMP sets the MySQL and HTTP port number to X and X, respectively. The port numbers, though effective, are not the standard for both services. By default, MySQL should operate under port number 3306; Apache should operate under port number 80.

Post-Apache Installation

If there were no errors during the installation of Apache on Windows, you should see the Apache Monitor icon in the task bar. Right-click it and then click Open Apache Monitor, which is the tool that allows you to start and stop the web server. Mac users open the MAMP manager and verify that the status indicators on both Apache and MySQL are green.

Tip For easier access to the manager, I suggest you install the MAMP widget included in the installation bundle.

Note During this process, you might have to go back to this tool to restart Apache, so remember where this icon is located.

Now make sure that Apache is running on the computer. To do this, you need to call Apache from the web browser. Pull up your favorite web browser and type in the following URL: href= "http: //localhost" http: //localhost. You should now see the result.

Tip If you have any issues and can’t see the page, look in the Apache error logs located at APACHE_ HOME /logs /error.log. The problem can often be found here and easily taken care of by simply reading the errors saved to these files.


You have turned your computer into a nice web server in which you can begin creating your application. Great! The next piece of the puzzle is installing a database to store user-entered data for the application. By doing this, you can ask customers to enter data such as favorite bands, favorite songs, and usernames they want to use. You can then save this data for later use so you don’t have to ask them every time they visit the site.

There are many database software packages available, but here’s one that works well with PHP: MySQL. You will now turn your computer not only into a web server but also into a database server.

Installing MySQL on Windows

Installing MySQL 5.1 or later is very straightforward. Head to the web site and download the latest software by clicking the Downloads link on the top menu bar. After you reach the new page, click the Download button under MySQL Community Server and scroll down until you reach a portion of the page containing the different download options.

Like Apache, MySQL gives you the option to install the software in either Windows or Linux. Windows users should download the Windows MSI installer (x86) ; Linux users should download the appropriate installer for the Linux flavor by clicking any of the installers under the specific distribution you have. Once you select a package (by clicking “Pick a mirror”), you are asked to log into your account. Click “No thanks, just take me to the downloads!”, and a list of mirror links displays. Select one of the mirror links and start downloading.

As soon as the download is complete, run the setup file to start installing MySQL. On the initial welcome window, click Next.

In the Setup Type window, you’re presented with the option of setting up a typical installation or a custom installation. Click Custom and then click Next. This process enables you to install MySQL in a directory of your choice.

As soon as the Custom Setup window displays, click Change. The Change Current Destination Folder displays. For simplicity, install your MySQL files in the location C:mysql.

Click OK and then click Next. The Ready to Install the Program window displays. Click Install and watch MySQL install. If you’re prompted with additional screens, click Next.

If there were no errors during the MySQL installation process, MySQL has been installed on your computer, and a configuration window will pop up. Let’s now go through the steps of configuring yourinstance of MySQL.

Configuring MySQL

Configuring MySQL takes only a minute. In the first window that displays, click Next to start the configuration process.

In the MySQL Server Instance Configuration window, click the Standard Configuration button to speed up the process of configuration and then click Next to continue.

In the screen, choose the default Install As Windows Service option and click Next

Almost done. In the window, you need to set up a password. Enter a password for all the fields, leaving Modify Security Settings checked, and then click Next.

Finally, click Execute and watch the check marks come up. If the installation and configuration completed successfully, you’ll see four check marks that indicate no errors. Congratulations! You finished the setup. Click Finish and relax.

Installing MySQL GUI Tools

At this point, all basic tools are on your workstation. To make things easier for you as a Windows user, download and install a free MySQL GUI tool: MySQL Query Browser. The tool allows you to connect to the newly installed database server, view table schemas on the fly by simply clicking a button, and (most importantly) run SQL queries on the data.

Head back to the MySQL home page, located at and click the Downloads link. After the Downloads page loads, click the GUI Tools link located on the left navigation bar. The MySQL GUI Tools Downloads page displays.

There are two types of installers: a Windows version and a Linux version. Windows users can download the Windows (x86) installer; Linux users should select the appropriate installer by clicking the “Pick a mirror” option next to the specific Linux distribution you have installed. When the next window comes up, it prompts you to log in. Ignore it and click the “No thanks, just take me to the downloads!” link. After the page loads, scroll down until you locate a mirror in your country and start to download.

After your download completes, open the downloaded file to start the installation process. In the initial MySQL Tools welcome window, shown below, click Next.

Accept the terms and conditions presented by MySQL on the next window by clicking “I accept the terms in the license agreement” button and then click Next to continue. The MySQL Tools Destination Folder window displays. Click Change. In the Folder name field, type in the MYSQL_HOME/tools path, click OK, and then click Next.

The MySQL Tools Setup Type window displays. Click Complete and then click Next to reach the Ready to Install the Program window. Click Install and let the setup do the rest. If you encounter any additional windows after this point, simply click Next until you reach the MySQL Tools Wizard Complete window. Click Finish, and you’re done.

Post-MySQL Installation

All should have gone well, but let’s make sure. You’ll create a database and add a table into the new database in the MySQL instance. Windows users: click the Start Windows button, typically located in the bottom-left of the screen, and open the MySQL folder. In the folder you’ll find a few other applications, but you’re currently interested only in the MySQL Query Browser, so click it and wait for it to load. You should see a window that prompts you for a few pieces of information.

Type in the information you used during the MySQL server installation and then click OK. If you’ve been following along, you should enter localhost in the Server Host field, root in the Username field, and the password you used during the installation of MySQL.

You should now see the MySQL GUI window shown below. By default, it contains a list of all your databases on the right side of the window, a place to write your SQL queries, and an Execute button with a lightning bolt on it. You will use these tools to write and execute your SQL statements.

Mac users: open the MAMP manager once more and click the “Open start page” button on the right side of the manager. This will open up a web browser with a link to phpMyAdmin, a web-based MySQL manager, on the top navigation menu. Click the phpMyAdmin link and wait for the application to load. After phpMyAdmin has loaded, click the SQL icon on the left menu bar and continue to the next section to create your first database.

Creating a Test Database

Create a test database by typing the following SQL command into the command window on the GUI tool for Windows users or the phpMyAdmin SQL window for Mac users:


Click OK or the lightning bolt icon to run the SQL. If all went well, right-click the list of databases on the right side and click Refresh on the GUI tool, or look at the list of databases currently present in the left side of the phpMyAdmin window. You will see your zend_test database appear.

Now, select zend_test as the database you want to use (or click the database if you’re using phpMyAdmin):

USE zend_test;

The database name should now be bold, indicating that you’re working with the zend_test database (or the phpMyAdmin window should load a new window containing only zend_test options): Create a table called Accounts, as follows:

CREATE TABLE Accounts (id int(11));

If all these commands ran without errors, MySQL is installed and waiting for calls from your application.

Pragna Meter
e-University Search
Related Jobs