Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework: The requested URL /my/path was not found on this server

I am total new to Zend Framework.

I wrote a simple web service that return mock XML data with Zend Framework, with module structure like this:

AppName
    application
        configs
            application.ini
        modules
            default
                .....
            api
                controller
                    CatalogController.php
                view
        library
        public
            .htaccess
            index.php
        tests

In localhost (windows 7), these are working :

http://localhost

http://localhost/api/catalog

http://localhost/default

in my production server (linux), I get '404 file not found' from:

http://107.22.255.126/api/catalog

http://107.22.255.126/default

but this is working

http://107.22.255.126

I host it in Amazon Web Services.

Here is my .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]

Here is my application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
//resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = "default"
resources.modules[] = "api"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.layout.layout = master

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Here is my Bootstrap.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    protected function _initRoutes()
    {
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        $restRoute = new Zend_Rest_Route($front, array(), array('api'));
        $router->addRoute('api', $restRoute);
    }

}

?>

I had run out of idea. I suspect this is something related with router in bootstraper, but can't find any solution.

like image 978
VHanded Avatar asked Dec 04 '11 11:12

VHanded


3 Answers

Finally, the problem is because httpd.conf disable .htaccess on the directory. I added AllowOverride All to it under VirtualHost, and it works.

like this:

<VirtualHost *:80>
    DocumentRoot "var/www/html/TestMVC/public"

    <Directory "var/www/html/TestMVC/public">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride All
       Order allow,deny
       Allow from all
   </Directory>

</VirtualHost>

Credit to @Corbin in the question's comment.

like image 151
VHanded Avatar answered Nov 18 '22 04:11

VHanded


I had this kind of problem on Ubuntu. I went to apache2.conf and set one directory as below:

<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

The most important point is: AllowOverride All

Remember to set your apache configuration: sudo a2enmod rewrite

Then is should work.

like image 30
Adam Kozlowski Avatar answered Nov 18 '22 05:11

Adam Kozlowski


yeap the solutions is:: http://www.phpcloud.com/help/adding-rewrite-rules-to-your-application

In step 3, I didn't mention but we didn't copy the default Elefant .htaccess file into our public folder. Instead, we're going to use the one provided by Zend in the PHPCloud documentation. Create a public/.htaccess file with the following contents:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
php_flag zend_codetracing.trace_enable on
php_flag zend_codetracing.always_dump on
like image 34
Edy Aguirre Avatar answered Nov 18 '22 04:11

Edy Aguirre