●ABOUT
●INSTALL
●DOCUMENTATION
●TRAINING
●BLOG
●PARTICIPATE
Documentation
Caution: The documentation you are viewing is
for an older version of Zend Framework.
You can find the documentation of the current version at:
https://docs.zendframework.com/
Getting started: A skeleton application — Zend Framework 2 2.1.5 documentation
User Guide
●Getting Started with Zend Framework 2
●Modules
Getting started: A skeleton application
In order to build our application, we will start with the
ZendSkeletonApplication
available on github. Use Composer (http://getcomposer.org)
to create a new project from scratch with Zend Framework:
php composer.phar create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application path/to/install
Note
Another way to install the ZendSkeletonApplication is to use github. Go to
https://github.com/zendframework/ZendSkeletonApplication and click the “Zip”
button. This will download a file with a name like
ZendSkeletonApplication-master.zip or
similar.
Unzip this file into the directory where you keep all your vhosts and rename the
resultant directory to zf2-tutorial.
ZendSkeletonApplication is set up to use Composer (http://getcomposer.org) to
resolve its dependencies. In this case, the dependency is Zend Framework 2
itself.
To install Zend Framework 2 into our application we simply type:
php composer.phar self-update
php composer.phar install
from the zf2-tutorial folder. This takes a while. You should see an output like:
Installing dependencies from lock file
- Installing zendframework/zendframework (dev-master)
Cloning 18c8e223f070deb07c17543ed938b54542aa0ed8
Generating autoload files
Note
If you see this message:
[RuntimeException]
The process timed out.
then your connection was too slow to download the entire package in time, and composer
timed out. To avoid this, instead of running:
php composer.phar install
run instead:
COMPOSER_PROCESS_TIMEOUT=5000 php composer.phar install
We can now move on to the virtual host.
Virtual host
You now need to create an Apache virtual host for the application and edit your
hosts file so that http://zf2-tutorial.localhost will serve index.php from the
zf2-tutorial/public directory.
Setting up the virtual host is usually done within httpd.conforextra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure
that this file is included by your main httpd.conf file. Some Linux distributions
(ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2
and create one file per virtual host inside folder /etc/apache2/sites-enabled. In
this case, you would place the virtual host block below into the file
/etc/apache2/sites-enabled/zf2-tutorial.
Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then
define a virtual host along these lines:
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Make sure that you update your /etc/hostsorc:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost
is mapped to 127.0.0.1. The website can then be accessed using
http://zf2-tutorial.localhost.
127.0.0.1 zf2-tutorial.localhost localhost
Restart your web server.
If you’ve done it right, you should see something like this:
To test that your .htaccess file is working, navigate to
http://zf2-tutorial.localhost/1234 and you should see this:
If you see a standard Apache 404 error, then you need to fix .htaccess usage
before continuing. If you’re are using IIS with the URL Rewrite Module, import the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
You now have a working skeleton application and we can start adding the specifics
for our application.
●Getting Started with Zend Framework 2
●Modules
●Getting started: A skeleton application
●Virtual host
About
Overview
FAQ
License
Changelog
Security
Issues
Install
Get started
MVC skeleton app
Expressive skeleton app
Archives
Documentation
Overview
Training and Certification
Support and Consulting
Webinars
Blog
Zend Framework 2 - API
Zend Framework 1 - API
Participate
Overview
Slack
Forums
Contributor guide
Code Manifesto
Contributors
Logos
Get certified
Privacy Policy
Copyright
© 2006-2022 by ZendbyPerforce. Made with by awesome contributors.
This website is built using zend-expressive and it runs on PHP 7.
Contacts
We use cookies to allow you to dismiss dialogs such as the Laminas
Project notification.