Configuring Zend Framework

The following procedure describes how to configure Zend Server to run Zend Framework projects in a development environment, using port-based virtual hosts. The advantage of port-based virtual hosts is in the ease of running several isolated applications on the same Web server. This overall solution allows developers working on a Zend Framework project in Zend Studio to immediately test any code changes locally.

Tip:

The following procedure uses instructions suitable for Zend Studio for Eclipse and the Apache bundled with Zend Server. A similar procedure with some modifications can apply for other IDEs and web servers.

Instructions on how to complete a procedure

To configure Zend Server to run a Zend Framework application:

  1. Create a new Zend Framework project.
    If you have not already done so, create a new Zend Framework project using the New Zend Framework Wizard in Zend Studio for Eclipse.

  2. Define a virtual host on Zend Server that will point to the new project's public directory:

    1. Find the full path to your project's public directory.
      In Zend Studio for Eclipse, go to the project browser and right-click on the public directory from the menu select Properties. The full path is listed in the Resource Tab's location field.

    2. Open your Apache configuration file (in most cases it will be httpd.conf and located in your Apache installation directory).
      Where is my Apache configuration file?

    3. Go to the end of the file and add the following section:

Listen 10089

<VirtualHost *:10089

    DocumentRoot "DOCUMENT_ROOT

    <Directory "DOCUMENT_ROOT">

        Order allow,deny

        Allow from all

    AllowOverride all

</Directory>

</VirtualHost>

  1. Replace "DOCUMENT_ROOT" with the full path to the public directory, enclosed in double quotes ("DOCUMENT_ROOT")
    Replace the port number with a unique port number dedicated to this Virtual Host. The port number (10089) has to be the same value for "Listen" and "VirtualHost".

  2. Zend Framework's MVC implementation makes use of the Front Controller pattern. You must therefore rewrite all incoming requests (except those for static resources, which your application need not handle) to a single script that will initialize the FrontController and route the request. If you're using mod_rewrite for the Apache web server, create the file <Project_Name>/public/.htaccess with the following contents:

# public/.htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ /index.php [NC,L]

Note:

Some web servers may ignore .htaccess files unless otherwise configured. Make sure that your web server is configured to read the .htaccess file in your public directory.

  1. Restart your Web server from the command line (windows users can use the Apache Monitor tool).

Your Zend Framework projects will now be accessible from a browser through: http://localhost:10089/ (the port number 10089 should be replaced with the unique port you dedicated to this virtual host).

Where is My Apache Configuration File?

Apache uses a main configuration file for all its settings, typically this file is called httpd.conf or apache2.conf. The location of this file varies depending on your installation:

  • Windows:
    <install_dir>\Apache24\conf\httpd.conf
    If you changed the location of your Zend Server installation, your document root will be located at <installation_directory>\ Apache24\conf\httod.conf, where <installation_directory> is the location of the directory in which Zend Server is installed.

  • Linux:
    If you installed Zend Server from a repository (DEB or RPM packages), the location of your configuration file is defined by your distribution's Apache packages, and will vary depending on your distribution and configuration.

If you changed the location of your Zend Server installation, your document root will be located at <installation_directory>/ apache2/conf/httpd.conf, where <installation_directory> is the location of the directory in which Zend Server is installed.

  • IBM i:
    /www/zendzvr/conf/httpd.conf