Prerequisites
Before you get started with setting up your first ZF2 Project, make sure that you have the following software installed and configured in your development environment:
◆ PHP Command Line Interface
◆ Git: Git is needed to check out source code from various github.com repositories
◆ Composer: Composer is the dependency management tool used for managing PHP dependencies
ZendSkeletonApplication provides a sample skeleton application that can be used by developers as a starting point to get started with Zend Framework 2.0. The skeleton application makes use of ZF2 MVC, including a new module system.
ZendSkeletonApplication can be downloaded from GitHub (https://github.com/zendframework/ZendSkeletonApplication).
To set up a new Zend Framework project, we will need to download the latest version of ZendSkeletonApplication and set up a virtual host to point to the newly created Zend Framework project. The steps are given asfollows:
1. Navigate to a folder location where you want to set up the new Zend Framework project:
$ cd /var/www/
2. Clone the ZendSkeletonApplication app from GitHub:
$ git clone git://github.com/zendframework/ ZendSkeletonApplication.git CommunicationApp
3. Install dependencies using Composer:
$ cd CommunicationApp/
$ php composer.phar self-update
$ php composer.phar install
The following screenshot shows how Composer downloads and installs the necessary dependencies:
4. Before adding a virtual host entry we need to set up a hostname entry in our hosts file so that the system points to the local machine whenever the new hostname is used. In Linux this can be done by adding an entry to the /etc/hosts file:
$ sudo vim /etc/hosts
5. Add the following line to the hosts file:
127.0.0.1 comm-app.local
The final hosts file should look like the following:
6. Our next step would be to add a virtual host entry on our web server; this can be done by creating a new virtual host's configuration file:
$ sudo vim /usr/local/zend/etc/sites.d/vhost_comm-app-80.conf
7. Add the following configuration to the virtual host file:
<VirtualHost *:80> ServerName comm-app.local
DocumentRoot /var/www/CommunicationApp/public SetEnv APPLICATION_ENV "development"
<Directory /var/www/CommunicationApp/public>
DirectoryIndex index.php AllowOverride All
Order allow,deny Allow from all
</Directory>
</VirtualHost>
8. After configuring the virtual host file, the web server needs to be restarted:
$ sudo service zend-server restart
local on your web browser. This should take you to the following test page :
What just happened?
We have successfully created a new ZF2 project by checking out ZendSkeletonApplication
from GitHub and have used Composer to download the necessary dependencies including
Zend Framework 2.0. We have also created a virtual host configuration that points to the
project's public folder and tested the project in a web browser.
Không có nhận xét nào:
Đăng nhận xét