Abstracted Method

  • Random
  • Archive
  • RSS
  • Ask me anything

Zend Server CE and Framework, VHost OS X Dev

So lately I’ve thought about switching my PHP development over to Zend Framework. The main reason for this is that I am just tired of rewriting the wheel. Most of the common problems with developing a PHP application have been solved and for once it would be nice to just build an application, instead of building a framework.

To get started in my efforts, I needed to set myself up with a local development environment. While I do have a production web server hosted with Slice Host (which this website is served from) and a local server at home, I wanted something that was a little less configuration heavy. After looking into several Mac OS X solutions, like XAMPP and Entropy PHP, I ran into Zend Server Community Edition. The first two, while decent solutions, were no where near as complete as the Zend provided solution. It was a clear winner for me.

Fast forward a bit, after downloading, installing and running the Zend Server CE, I was up and running. Much more quickly than I had anticipated actually. Now, the server control panel not only has modules predefined for most of the most common php suspects, it also has several already available that are a little more exotic, like DBLib (for accessing MSSQL servers with PDO). I initially had some questions on how to ensure the MySQL database was working correctly. After consulting a great article on setting up Zend CE in Leopard, I was off and running.

I do suggest one change to his post. In order to have access to the zend command line tools for Zend Framework you path should be adjusted like this in your ~/.bash_profile file:

PATH="/usr/local/zend/bin:/usr/local/zend/mysql/bin:/usr/local/zend/share/ZendFramework/bin:$PATH"

After changing this, be sure to restart your terminal window. You should now have access to the zf.sh file from where ever you are.

Adding Development VHosts

Personally I prefer to use fake local domains for my development. I prefer to type something like http://mysite.local/ in my browser than http://localhost:8181/, which is just non-descriptive and difficult to remember. Especially being that I tend to juggle projects. So, I created some simple instructions for making the Zend Server aware of your local development environment.

My personal taste is to reuse the /Users/Drew/Sites/ directory, as this keeps the information that I want my Time Machine to back up in an easy to find place. Plus it just seem more proper to edit and work with files there, than in the /usr/local/zend/ directory. The first step is to create an apache config file to help find our vhost entries.

$ vim /usr/local/zend/apache2/conf.d/vhosts.conf

Now insert this into that file. Of course change the username to be your own, not mine (Drew).

NameVirtualHost *:80
Include /Users/Drew/Sites/vhosts/*.conf

This will tell Apache to look for any vhost files we create in our home directory to parse. So let’s create a site.

Creating A New Zend Framework Site

Now, assuming that you followed my recommendation for adding Zend Framework into the path, the following should run without any issues.

$ cd ~/Sites
$ zf.sh create project mysite
$ rm mysite/public/.htaccess

I added the last line in, because we do not need to standard htaccess, as we will be doing this ourselves. Now, let’s create our vhost, so the app can be found by Apache.

$ vim /Users/Drew/Sites/vhosts/mysite.conf

Now insert the following into the file and be sure to adjust the username again.

<VirtualHost *:80>
  ServerName mysite.local
  DocumentRoot "/Users/Drew/Sites/mysite/public"
  SetEnv APPLICATION_ENV development

  RewriteEngine off

  <Directory /Users/Drew/Sites/mysite/public>
    Order deny,allow
    Allow from all

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ /index.php [NC,L]
  </Directory>
</VirtualHost>

Now, I’m assuming the url we’ll be using is http://mysite.local/. In reality this could be anything you want, as our next step is to actually define it. So feel free to change it. In this case I’ve decided to keep the Mac convention of defining local urls with the .local postfix. So, let’s edit the hosts file and add your new host in, so the browser will know how to find it.

$ vim /etc/hosts

Edit the local line and add your url to the end, like so:

127.0.0.1   localhost mysite.local

And finally, we finish it off by restarting Apache:

$ sudo zendctl.sh restart-apache
/usr/local/zend/bin/apachectl stop [OK]
/usr/local/zend/bin/apachectl start [OK]

And that’s it! You should now be able to go to http://mysite.local in your browser and see your new Zend Framework site ready to go. You can now just start these instructions from the site creation point next time, to set up a new site. Now, you could put all the vhosts in the same file, but I prefer having them in separate files for easier management. I’ll likely be posting some more about using Zend Framework in the near future as I start to learn it and hopefully come up with some tips and tricks. For now though, if you need a resource for getting started, try Zend’s Quickstart Guide.

    • #php
    • #mac os x
    • #zend server
    • #quick start
    • #development
    • #tutorial
    • #zend framework
    • #virtual host
  • 2 years ago
  • 1
  • Comments
  • Permalink
  • Share

1 Notes/ Hide

  1. abstractedmethod posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

My name is Drew and I am a self-professed geek and technology enthusiast. My day job involves me building web sites and maintaining frameworks. My dream is to perhaps write a novel (or ten) one day.
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

© 2010 Drew Butler. All Rights Reserved.. Effector Theme by Carlo Franco.

Powered by Tumblr