Reputation: 2089
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 :
in my production server (linux), I get '404 file not found' from:
http://107.22.255.126/api/catalog
but this is working
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.
Upvotes: 8
Views: 22651
Reputation: 5896
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.
Upvotes: 5
Reputation: 2143
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
Upvotes: 1
Reputation: 2089
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.
Upvotes: 17