26 June 2009

Zend Quickstart Guide

Setting up and using the Zend Framework will definitely be something daunting to the first time user of Zend. And if you moved over from procedural to Object Oriented Programming [OOP] it will also be very confusing. This article covers setting up and running the Quickstart guide from the Zend’s website. Firstly, the Zend Framework is a library you use. Download it here. Secondly, you need to get the quickstart guide as well. That can be downloaded here. Let’s first set up our development environment. What you need to development locally on your machine, is a server, the PHP engine and a database. I’m sure most developers use Apache, MySql and PHP in one package. I use wampserver but there is also a xamp for a Mac. What I like about WampServer is that it installs everything for you and gives a you nice tray icon. Now you need to know where your root folder is. If you installed WampServer it will be c:\wamp\www which is equivalent to http://localhost/ in a browser. PHP files in the root folder will be processed by the server, but files outside of the root folder will not be touched by the server (Apache server using the PHP engine). Now let’s put the framework we downloaded in the root folder, e.g. c:\wamp\www\library\zend\ it should be about 18MB. Then extract the quickstart you downloaded and move that folder to the root as well, e.g. c:\wamp\www\ZendFrameworkQuickstart-20090430. Then open your IDE of choice and add the project directory, i.e. ZendFrameworkQuickstart-20090430, as the project folder. So everything is almost set up, so let’s get started running the application. Open public/index.php and preview the file in your browser. All projects start by running this file. However, you should be getting an Internal Server Error in your browser. That’s because of the .htaccess file in the public folder, which redirects requests. I’ll cover .htaccess in a later post, but for now realize that this rule in the
file: RewriteRule ^.*$ index.php [NC,L]
Makes use of Apache commands/functions. To fix this you need to open your httpd.conf file for Apache. It should be in your Apache folder otherwise search for it. You can open the file the quickest using wampserver’s tray icon and clicking on the filename under the Apache menu. With the file open, you are looking for this line:
LoadModule rewrite_module modules/mod_rewrite.so
There should be an # in front which you need to remove – this will uncomment the line and apache will read and use that command from now on. Restart your server's services. If you refresh the page it will remove the Internal Server Error, however, there should be a new error. The new error should be a PHP warning: Warning: require_once(Zend/Application.php) This is because the index.php file can't find the Zend Framework's library file. If you open the index.php file in the public folder you will see on lines 6-9 the following snippet:
set_include_path(implode(PATH_SEPARATOR, array(
  realpath(dirname(__FILE__) . '/../library'),
  get_include_path(),
)));
What you need to do is change the path to the library, which is one more folder further down. Change it to:
set_include_path(implode(PATH_SEPARATOR, array(
  realpath(dirname(__FILE__) . '/../../library'),
  get_include_path(),
)));
Running that should work. And that's it for this article. I highly recommend reading the quickstart guide on Zend's website. I'll be covering each portion of the set up in detail in future articles.

1 comment:

  1. Hi I was wondering if you could help me.

    I have never used zend and i have inherited this website. I can't find the main page where I can change the divs and add new containers. Is there a main folder and filename which has all the main info like the layout/theme.

    ReplyDelete