Web Development

Setup Xdebug with Zend Server CE

January 20th, 2012 0 Comments

Open Zend Server page, http://localhost:10081/

Disable “Zend Debugger”

Download xdebug.so binary which I suggest to download at -> http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging

Extract the archive and browse into ’5.3′ folder then copy ‘xdebug.so’ to ‘/usr/local/zend/lib/php_extensions’

Open ‘/usr/local/zend/etc/php.ini’ and add the following lines above [zend] section:

zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_host=”localhost”
xdebug.remote_port=9000
xdebug.show_local_vars=On
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20

Now restart your Zend Server by ‘sudo /usr/local/zend/bin/zendctl.sh stop’ and ‘sudo /usr/local/zend/bin/zendctl.sh start’

Everything You Wanted To Know About Zend Server CE for Mac OSX 10.7 Lion

August 17th, 2011 1 Comments

Zend Server CE is one of the best stacks available for development, and for Mac OSX. These are some simple instructions to get you up and running quickly (and you may learn a few things along the way as well).

Hint: You can copy-paste in terminal so just copy-paste when you can to save yourself time.

Step 1: Download
+ Download Zend Server CE for OSX from http://www.zend.com/en/products/server-ce/downloads. (I recommend the PHP 5.3 version)
+ Follow the prompts and install to the default locations

Step 2: .bash_profile Updates
Let’s edit the bash_profile so you can access the controls from the terminal much easier.

+ Open Terminal
+ Type Open .bash_profile
+ Copy-paste the following

PATH=$PATH:/usr/local/zend/bin:/usr/local/zend/mysql/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zend/lib

+ Save file (close)

While were making changes, let’s shortcut Zend Framework too so you can access easily in Terminal to create new projects:

+ Open Terminal
+ alias zf=/usr/local/zend/share/ZendFramework/bin/zf.sh

+ Now restart your computer for the changes to take effect.

Step 3. Welcome Back!… Let’s Change Localhost Port
The Apache in Zend Server is configured for localhost to use port 10088. Let’s make your life easy and change this.

+ Open Terminal
+ sudo zendctl.sh stop
+ sudo vi /usr/local/zend/apache2/conf/httpd.conf
+ Arrow down to line that says Listen 10088 and type the letter i
+ Change to Listen 80
+ Esc, then save/exit by typing :x

+ sudo vi /usr/local/zend/apache2/bin/apachectl
+ Arrow down to line that says STATUSURL=”http://localhost:10088/server-status” and type the letter i
+ Change to STATUSURL=”http://localhost:80/server-status”
+ Esc, then save/exit by typing :x

+ sudo zendctl.sh start

Step 4. Change root passwords for MySQL / phpmyadmin
Do not login to phpmyadmin until you have changed root password!
By default, Zend Server CE doesn’t setup a password for root access to MySQL. Although this is likely a development environment, this is a security issue. Let’s change the root password.
+ Open Terminal
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD(‘NEW_PASSWORD’) WHERE User=’root’;
mysql> flush privileges;
mysql> quit

Step 5. Change Server Root To Sites Folder
Although it’s easy enough to create a shortcut to your htdocs folder, it’s also just as easy to change the root folder. The Sites folder is the standard location used on OSX, and is a convenient place for your projects.
+ Open Terminal
+ sudo vi /usr/local/zend/apache2/conf/httpd.conf
+ Arrow down to the following line and type i to start editing:
change DocumentRoot “/usr/local/zend/apache2/htdocs”
to DocumentRoot “/Users/COMPUTER_ACCOUNT_USERNAME/Sites”
+ Arrow down to the following line to start editing:
change <Directory "/usr/local/zend/apache2/htdocs"></code>
to <Directory "/Users/COMPUTER_ACCOUNT_USERNAME/Sites">
+ Esc, then save/exit by typing :x

Step 6. PEAR and PHPUnit
Let’s upgrade PEAR and install PHPUnit

+ Open Terminal
+ Type the following one line at a time:
sudo pear update-channels
sudo pear upgrade-all
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
sudo pear install phpunit/PHPUnit

Step 7. date.timezone
Don’t forget to date.timezone for PHP. You can do this in the php.ini file, however, Zend Server CE makes this very easy to do from the control panel. Simply launch the control panel, agree to Terms of Use and other basics.
+ Select Server Setup
+ Select Directives
+ Select Date
+ Add America/New_York to input field
+ Save and restart PHP

Reminders:
From Terminal:
Start: sudo zendctl.sh start
Stop: sudo zendctl.sh stop
Restart: sudo zendctl.sh restart
Zend Framework: zf (see list of controls to create projects, files, etc.)
PHPUnit: phpunit

And at any point if you need to uninstall Zend Server CE for some reason, it’s simple to do:
+ Open Terminal
+ sudo /usr/local/zend/bin/uninstall.sh

Alternatives:
And you can always try a nice alternative called MAMP which you can download at http://www.mamp.info/en/downloads/index.html, but remember, it doesn’t have all of the features that are found with Zend Server CE (but everything most people need for LAMP development).

Happy Programming with Zend Server CE
Note: These instructions will work with OSX 10.6 as well.

5 Things When Considering A Web Development Framework

May 10th, 2011 0 Comments

There are so many frameworks in web development that, to be frank, most developers find it confusing at times. Many developers are jumping around from one to another, if for no other reason, to add it to their resume. This article is designed to help cut through the confusion, and the bias online, and provide some thoughts that will help in your decisions.

This is a basic list of things to consider when choosing a framework:

1. Who’s behind the framework? Is it backed and endorsed by a large company, or perhaps a small group of developers looking to make a name, or otherwise just a new company looking to emerge? This should be very important in making a decision with not only the current framework you use with your projects, but even deeper, the platform and technology direction overall.

2. Is the code constantly being updated, tested, and maintained by a large professional team of developers? Technology changes, and so should the frameworks you use. It’s a constant pursuit to improve and debug that requires a lot of resources and man hours.

3. The code base should be of the highest quality, fully standardized and professional coding practices that will stand the test of time. It’s not about being a perfectionist, but it is about creating real solutions with solid products that have a reasonable life cycle.

4. A framework is only as good as it’s documentation and support. If it’s not easy to use, if it’s doesn’t produce better products, if it’s not speeding the time of development, then there is no point at all in even attempting to use it. This happens from great efforts to clearly document and to demonstrate common scenarios with written and video tutorials, etc.

5. What kind of work do you want? Do you want to work with professional organizations and long term contract work or jump from client to client with short turn around low level work? You must choose the technology path that meets your goals, and just the same, the framework goes nearly hand in hand with that direction.

Now that we know how you should choose, let’s look at the current options:

Tier 1:
Microsoft – .NET
JAVA – JSF

Tier 1 options are driven by large commercial for-profit companies with a large number of developers supporting and maintaining them, a large amount of money backing them, and are solid “enterprise worthy” directions. As a result, they are found as your tier 1 options.

Tier 2:
JAVA – Struts
JAVA – Spring
PHP – Zend Framework
Python – Django

Tier 2 options are also driven by quality companies with a large number of developers supporting them, and are solid directions that are considered “enterprise worthy” in many cases. Django may be a surprise by some, however, Python has proven to be a force to reckon with in the development community, and Django has played a large part in that movement. The other options in this tier should be no surprise.

Tier 3:
Ruby – Rails
PHP – Yii
PHP – Symfony
PHP – CodeIgniter

Tier 3 options are solid options, however, they are for the most part community driven by a smaller group of developers. Tier 3 options tend to be popular for a few years, then lose traction. They are also prone to complete overhauls where the framework is built again from the ground up to address issues and poor long term vision, which may break functionality of existing projects.

Tier 4:
If you’re not in the first 3 tiers, one should question whether you’re willing to roll the dice on such a development path for your projects. Sure, anyone can build their own framework, and many of the tier 4 and lower options are just not stable enough to guarantee their future.

Some may agree with the assessments, and of course, some will not as their favorite framework falls lower on the scale then expected. However, the vast majority of non-biased software/web/mobile architects will agree with these findings. With that said, there is no “wrong” framework to use provided it eases your development process, but if you’re looking for career paths and long term life cycles, you should consider these 5 points.

12 Regular Expressions To Improve Your PHP Development

September 6th, 2010 0 Comments

In programming, regular expressions are a very useful tool designed to validate, search, and match text patterns. In this article, I have compiled more than 10 incredibly useful regular expressions, for any language, that will probably be very beneficial to you.

Validate an URL
Is a particular url valid? The following regexp will let you know.

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \?=.-]*)*\/?$/
Source: http://snipplr.com/view/19502/validate-a-url/

Validate US phone number
This regexp will verify that a US phone number is valid.

/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/
Source: http://snippets.dzone.com/posts/show/597

Test if a password is strong
Weak passwords are one of the quickest ways to get hacked. The following regexp will make sure that:

Passwords will contain at least (1) upper case letter
Passwords will contain at least (1) lower case letter
Passwords will contain at least (1) number or special character
Passwords will contain at least (8) characters in length
Password maximum length should not be arbitrarily limited

Get code within
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
Source: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=297

Get code within
If for some reason you need to grab all the code contained within the tags, this regexp will do the job:

<\?[php]*([^\?>]*)\?>
Source: http://snipplr.com/view/12845/get-all-the-php-code-between/

Match tel: urls
In a recent post, I showed you how you can use iPhone special link prfixes to automatically call someone.
This regular expression will match those tel: urls.

^tel:((?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*’().-]|%[\dA-F]{2})+)?)*;phone-context=(?:\+[\d().-]*\d[\d().-]*|(?:[a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*(?:[a-z]|[a-z][a-z0-9-]*[a-z0-9])))(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*’().-]|%[\dA-F]{2})+)?)*(?:,(?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*’().-]|%[\dA-F]{2})+)?)*;phone-context=\+[\d().-]*\d[\d().-]*)(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*’().-]|%[\dA-F]{2})+)?)*)*)$
Source: http://tools.ietf.org/html/rfc3966#section-3

Validate US zip code
When building a registration form, it is common to ask the user’s zip code. As forms are often boring, there’s a strong chance that the user will try to register false data. This regular expression will make sure he entered a valid American zip code.

^[0-9]{5}(-[0-9]{4})?$
Source: http://reusablecode.blogspot.com/2008/08/isvalidzipcode.html

Validate Canadian postal code
This regexp is very similar to the previous one, but it will match Canadian postal codes instead.

^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$
Source: http://reusablecode.blogspot.com/2008/08/isvalidpostalcode.html

Grab unclosed img tags
As you probably know, the xhtml standard requires all tags to be properly closed. This regular expression will search for unclosed img tags. It could be easily modified to grab any other unclosed html tags.

]+)(\s*[^\/])>
Source: http://snipplr.com/view/6632/grab-any-unclosed-xhtml-img-tags/

Find all CSS attributes
This regexp will find CSS attributes, such as background:red; or padding-left:25px;.

\s(?[a-zA-Z-]+)\s[:]{1}\s*(?[a-zA-Z0-9\s.#]+)[;]{1}
Source: http://snipplr.com/view/17903/find-css-attributes/

Validate an IBAN
I have recently worked on a banking application and this one was definitely a life-saver. It will verify that the given IBAN is valid.

[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}
Source: http://snipplr.com/view/15322/iban-regex-all-ibans/

Validate a BIC code
Another one very useful for any banking application or website: This regexp will validate a BIC code.

([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)
Source: http://snipplr.com/view/15320/bic-bank-identifier-code-regex/

If you’re interested in regular expressions, make sure you have read our “15 PHP regular expression for developers” post.

Adobe Dreamweavers Future For Developers

August 1st, 2010 0 Comments

OK, Dreamweaver has reused the recordset code for too long, but let’s look at the big picture for Dreamweaver CS5. The easiest front end development tool that exists… period. No one can take that away. In CS5, Adobe has finally stepped up their development game a notch.

As a PHP developer, it’s the changes in Code view that really excite me. When you start typing a PHP script in Dreamweaver CS5, you’ll immediately notice a red marker in the line numbers column and an alert about a syntax error. Complete the line without errors, and the marker and warning disappear. Dreamweaver constantly checks your syntax on the fly. It doesn’t tell you what the errors are, but it highlights all lines with errors, making the debugging process much quicker. PHP code hints have also been improved dramatically. There’s full support for all core functions, constants, and classes (as of PHP 5.2).

Code hinting is also much smarter. Instead of needing to search through code hints alphabetically, Dreamweaver CS5 searches for substrings. This is helpful when you can’t remember the exact name of function or class—just type the part of the name that you remember, and Dreamweaver includes it in the list. You can also work out your own shortcuts. For example, if you press Ctrl+spacebar and type gesi, the code hints take you straight to getimagesize() by recognizing the ge of “image” and the si of “size”. And in case you don’t know how a function or class works, the official manual page—complete with code examples—appears as a tooltip at the bottom of the selected code hint.

For serious PHP developers, it gets even better. Dreamweaver CS5 is capable of code introspection, so it builds code hints on the fly for your own functions and classes, as well as for third-party libraries, such as the Zend Framework. The definition files don’t even need to be directly attached to the page you’re working in. With Site-Specific Code Hints, you tell Dreamweaver where your library files are located, and it scans them for you automatically.

So should you upgrade? Seriously, you’re asking that? YES… it’s the best version of Dreamweaver that’s existed.