2

Since I migrated to AWS and update to PHP 5.4 and Zend 1.12, I have a problem with the PUT & DELETE methods.

A quick exemple :

/** Zend 1.12 **/

/** bootstrap / routes **/

$front = \Zend_Controller_Front::getInstance();
$front->setParam('bootstrap',$this);
//REST API
$router = $front->getRouter();
$restRoute = new Zend_Rest_Route($front, array(), array(
    'default' => array('rest'),
));
$router->addRoute('rest', $restRoute);

/** restController **/

//module : default 

class RestController extends  \Zend_Rest_Controller
public function init(){
    parent::init();
    $this->_helper->viewRenderer->setNoRender(true);
    $this->_helper->layout->disableLayout();
}
public function headAction(){}

public function indexAction()
{
    Throw new AppException(Translator::translate('index not yet implemented...'));
}
public function getAction()
{
    die('get');
}
public function putAction(){
 die('put');
}

/* TestCase */

curl -X GET http://XXXX/rest/MS4xMjU2LjEyNTguMTI2MS4tbW9kZWxzXGNvcmVcbW9kZWxcZXhlcmNpc2VcZXhlcmNpc2VfcXVlc3Rpb24tMTQy

Result : get ===> OK

curl -X PUT http://XXXX/rest/MS4xMjU2LjEyNTguMTI2MS4tbW9kZWxzXGNvcmVcbW9kZWxcZXhlcmNpc2VcZXhlcmNpc2VfcXVlc3Rpb24tMTQy

Result :

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /index.php.</p>
<hr>
<address>Apache/2.2.16 (Debian) Server at XXXXX Port 80</address>
</body></html>

===> Not OK

I don't have to use WebDav (or other) Apache plugin to enable PUT/DELETE request. The PHP Handler deals with that, not Apache. So why, the GET is OK, and the PUT not? Why Apache says something about index.php instead of /rest/RestController.php?

I saw that Zend update its Zend_Rest_Controller since 1.12. Now, I've to declare the "headAction" function, but I didn't find documentation on this point...

If you have any idea...

Thanks,

Crash
  • 172
  • 2
  • 7
  • Possible duplicate of [How to enable and use HTTP PUT and DELETE with Apache2 and PHP?](http://stackoverflow.com/questions/2934554/how-to-enable-and-use-http-put-and-delete-with-apache2-and-php) – Paul Sweatte Mar 15 '16 at 07:55

1 Answers1

0

Probably the problem is rooted in Apache configuration. Maybe you should go ahead and add something like

<Directory />
    AllowOverride All
    <Limit GET HEAD POST PUT DELETE OPTIONS>
        Order Allow,Deny
        Allow from all
    </Limit>
</Directory>

to your apache configuration.

Check out this answer.

Community
  • 1
  • 1
akond
  • 15,865
  • 4
  • 35
  • 55
  • I already tried this solution, but it didn't work neither. And on my previous configuration, I didn't need to change the Apache configuration. Options FollowSymLinks AllowOverride All RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] Order allow,deny Allow from all – Crash Oct 17 '12 at 12:59
  • The problem is not in ZF anyway. In my environment your snippet works just fine. – akond Oct 17 '12 at 13:07