Page not found on request url in zend 2 framework application

I am newbie to zend framework and i am trying to configure the zend. I was sucessfully installed zendskeleton applicaion on window 7 and XAMPP

After installation I am creating new module Album as per define in user guide. I was make all code and pages according to guide, but after that i was enable to open Album module. i got error 404 not found.

here code

  1. application.config

     return array(
     'modules' => array(
    'module_paths' => array(
    'config_glob_paths' => array(
  2. module.config

     return array(
        'controllers' => array(
         'invokables' => array(
         'Album\Controller\Album' => 'Album\Controller\AlbumController',
          'router' => array(
           'routes' => array(
             'album' => array(
              'type' => 'segment',
                 'options' => array(
                     'route' => '/album[/][:action][/:id]',
                         'constraints' => array(
                             'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                 'id' => '[0-9]+',
                                 'defaults' => array(
                                     'controller' => 'Album\Controller\Album',
                                         'action' => 'index',
                                 'view_manager' => array(
                                 'template_path_stack' => array(
                                 'album' => __DIR__ . '/../view',
  3. Module.php

    namespace Album;
     // Add these import statements:
     use Album\Model\Album;
     use Album\Model\AlbumTable;
     use Zend\Db\ResultSet\ResultSet;
     use Zend\Db\TableGateway\TableGateway;
     class Module
      // getAutoloaderConfig() and getConfig() methods here
     // Add this method:
      public function getServiceConfig()
          return array(
          'factories' => array(
          'Album\Model\AlbumTable' => function($sm) {
           $tableGateway = $sm->get('AlbumTableGateway');
           $table = new AlbumTable($tableGateway);
           return $table;
         'AlbumTableGateway' => function ($sm) {
          $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
          $resultSetPrototype = new ResultSet();
          $resultSetPrototype->setArrayObjectPrototype(new Album());
          return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
  4. httpd-vhosts.conf

     <VirtualHost *:81>
     ServerName zf2-tutorial.localhost
     DocumentRoot "C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public"
     SetEnv APPLICATION_ENV "development"
     <Directory C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public>
      DirectoryIndex index.php
      AllowOverride All
      Order allow,deny
      Allow from all
  5. host entry at system32       zf2-tutorial.localhost

enter image description here

How can i handle it.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

when you point with your apache document root to C:/xampp\htdocs/ZendSkeletonApplication/ZendSkeletonApplication-master/public

you need to use in your browser this url http://zf2-tutorial.localhost:8081/album
and not like you wrote http://zf2-tutorial.localhost/ZendSkeletonApplication/ZendSkeletonApplication-master/public/album

this url points internal to a different module/location.


if this not work check your zf2 /public folder if there is a .htaccess file present otherwise use the file from the zend skeleton application here

please check also your apache vhost entry if the port is equal to your windows host file port.

make sure apache ModRewrite is loaded!

Solution 2

Basic misconfigurations in your setup causes this error.

  1. I don’t use windows for along time but you’re using both forward and backslashes in your paths. Firstly, you should find the correct directory separator for windows and stick with it. This seems problematic: C:/xampp\htdocs/foo/bar/public
  2. You’re defining a virtualhost which listens any IP address on port 81 (*:81), a system32 hosts entry which points to port 8081 as zf2-tutorial.localhost alias and trying to call zf2-tutorial.localhost/album url using port 80. Getting this kind of error pretty normal.

After completely reading the official Getting Started and Using Apache Web Server documentations, you’ll easily figure out the solution.

Solution 3

It seems you missing a vhost entry in your webserver. This could the reason why your application doesn’t resolve your request right. Check the “getting startet: A skeleton application” again, to provide a proper configuration.

Solution 4

You need this hostfile entry. Adding ports is not possible in this file. zf2-tutorial.localhost

The website is now available at zf2-tutorial.localhost:81 (and not 8081, you set 81 as the portnumber in the first line of httpd-vhosts.conf)

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply