Welcome to a series of tutorials to introduce the most important features of Zend Framework. During this series we will cover many Zend Framework classes and at the end you will be able to have a good overview of this powerful framework.
In this first part, we will cover the setup. So, basically, we will describe how to setup MAMP (if you are using Mac OS X, but the procedure is very similar windows and Linux), followed by setting up Zend Framework, Eclipse PDT, ZendDebugger, XDebugger and finally PHPUnit.
I hope you like it!
Setting Up MAMP
Form now, we will always refer to MAMP, but the procedures are basically the same for Windows and Linux (XAMPP – http://www.apachefriends.org/en/xampp.html)
First of all, download it (http://www.mamp.info/en/index.html) and install it by dragging it MAMP (MAMP Pro is a paid version) to the Applications folder.
Now, go the folder Applications/MAMP and open MAMP. To start your servers (apache and mysql) just click “Start Servers”. You will see that the red lights will become green indicating that the servers are up and running. Now click Open Start page, and your default web browser will open and a welcome page will be displayed.
If everything went as described, you now have apache and mysql running in your machine.
Now, we will change the default ports for apache and mysql. To do this, click in preferences on MAMP, go to tab Ports and pick the port you want (ex: Apache Port: 80, Mysql port: 3306).
Click and Stop Servers, and then Start Servers. If the lights become green, you are ready to go to the next step.
Setting Up Zend Framework Library
Download the Zend Framework Full Package from http://framework.zend.com/download/latest
After downloading, extract the contents to a folder and move the “library/Zend” folder to your MAMP:
By moving the zend folder, now you will have Zend Framework supported by default in your installation and you will not need to copy the Zend framework to the library folder of all of your projects.
Another useful tool that comes with Zend Framework is the zf tool. There is no general rule to install it. Our suggestion is (considering you are in the zend framework extracted files folder):
sudo mv bin/zf.sh /usr/local/bin/zf
sudo chmod +x /usr/local/bin/zf
sudo mv bin/zf.php /Applications/MAMP/bin/php5.3/lib/php/
Now, open “zf” to edit:
And replace @php_bin@ with /Applications/MAMP/bin/php5.3/bin/php and @php_dir@ with /Applications/MAMP/bin/php5.3/lib/php/
Save the file. Now you will need make “php” that comes with MAMP executable, since the zf tool needs to run it. So, type in a terminal:
Test the zf in the terminal. Open the terminal and type “zf” (without the quotes). If usage instructions appear, everything is correct.
Installing Eclipse + PDT
Go to Eclipse PDT website (http://www.eclipse.org/pdt/downloads/) and download the all in one version.
Extract the files and move the entire Eclipse folder to your Applications folder.
We will see how to create PHP Project in the Part 2 of this series.
Adding ZendDebugger and XDebug support
Download the latest Studio Web Debugger from http://www.zend.com/products/studio/downloads (i.e. ZendDebugger-20100729-darwin-uni.tar.gz.gz – 32bit – for Mac OS X). Extract the files, type the following commands:
sudo mkdir -p /Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/
sudo mv ZendDebugger-20100729-darwin-uni/5_3_x_comp/ZendDebugger.so /Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/
Now, edit the php.ini file (/Applications/MAMP/conf/php5.3/php.ini) and add the following lines at the end of the file (inside the [Zend] section):
zend_extension=/Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1/32
Comment the following lines (adding “;” in the beginning of the line):
And finally uncomment the line (to enable XDebugger):
Now, restart MAMP, open Start Page and click on phpInfo. You should see something like this:
If you can see that XDebug and Zend Debugger are installed, you can proceed to the next step.
We will see how to use eclipse to debug your project using Zend Debugger in the Part 2 of this series.
Setting Up PHPUnit
Download the latest stable release from http://pear.phpunit.de/get/ and extract it. Move the PHPUnit folder to php5.3 lib:
Now, edit phpunit.php and replace the @php_bin@ with ‘/Applications/MAMP/bin/php5.3/bin/php’. And replace the first line “#!/usr/bin/env php” to “#!/Applications/MAMP/bin/php5.3/bin/php”.
Finally, rename phpunit.php to phpunit and move the file to /usr/local/bin:
And adjust the permissions to make the file executable
Now type phpunit in a terminal and you should see an usage message.
Another interesting feature is the code coverage. Since we have enabled the XDebug in the MAMP installation, now you can PHPUnit including code coverage support
Configuring Virtual Hosts form your projects
The last step will describe how to create virtual hosts in your machine to allow you to have a different “address” to each project.
First of all, edit the /private/etc/hosts:
Now, add one line for each host name you want, for example:
The nest step is to create/edit an apache configuration file:
And add the following lines:
<VirtualHost *:80>
ServerName zfguide
DocumentRoot /Users/myhome/Workspaces/eclipse/zfguide/public/
<Directory /Users/myhome/Workspaces/eclipse/zfguide>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
You can repeat these steps to as many hosts as you need!
To conclude, let’s enable the Virtual Hosts in Apache.
And add the following lines to the end of the file:
Include /Applications/MAMP/conf/apache/vhosts.conf
Restart MAMP (if you don’t have the folders defined in your vhosts.conf, create them before restarting apache), open your favourite web browser and type “http://zfguide” (or anything you’ve chosen as host name).
And that’s it !! Now you have everything you need to start programming using Zend Framework and also have important tools to help you in the development process.
The next part of this series will describe how to create a project using zend framework.
Popularity: 40% [?]







