405 Method Not Allowed

10 posts / 0 new
Last post
#1 Mon, 04/07/2014 - 19:02
codewarrior_777

405 Method Not Allowed

I'm getting '405 Method Not Allowed' error and a general '500 internal server error' when the iOS app I'm working on is making an API request to my server with VirtualMIn installed.

http://api.fillesmag.com/confirmpurchase/com.prismstudios.fillesmagazine...

Is this a server configuration error? Maybe something to do with security?

If so, how do I fix this?

Mon, 04/07/2014 - 22:29
andreychek

Howdy,

What errors do you see in the Apache error logs when that occurs?

Those are available in $HOME/logs/error_log.

-Eric

Mon, 04/07/2014 - 23:33
codewarrior_777

I've looked in several logs, but I think you're talking about the log in "Logs and Reports > Apache Error Log".

Unfortunately, I haven't seen any errors showing up in the logs. Only client side.

I tried using Charles Proxy to further debug, but haven't been able to pinpoint the error:

https://www.dropbox.com/s/ydygkde6q1jiaym/Charles_overview.png

https://www.dropbox.com/s/wbn1jruium322h0/Charles_request.png

https://www.dropbox.com/s/thanen85i9nddk7/Charles_Response.png

From what I've researched, a 405 error is a server configuration error. Is this true?

Tue, 04/08/2014 - 03:18
Locutus

The full message reads like so: "HTTP method not allowed for the requested resource. Use one of these instead: POST"

This sounds like a problem with the web software that's handling the request. You might want to review your code.

Also, it's somewhat unlikely that a 500 error does not log anything into the Apache log. At least in the access log you should see the error and URL requested. If nothing gets logged to the Apache error log, it might be an issue with the web software too when it doesn't output any PHP errors or similar. I don't think this is an Apache issue.

Tue, 04/08/2014 - 04:06
codewarrior_777

Your right, I'm an idiot. I was looking at the logs in the top level domain instead of api.fillesmag.com. However, from my own research (I may be wrong) the 500 internal server error and the 405 error can mean several things. I haven't ruled out the web software since it hasn't been tested with a server running VirtualMin, but it is powering several production apps.

Here is the error from the apache error log from this sub-server:

[Mon Apr 07 17:29:18 2014] [warn] [client 66.25.153.86] mod_fcgid: stderr: PHP Fatal error:  Call to undefined function curl_init() in /home/fillesmag/domains/api.fillesmag.com/public_html/index.php on line 851
[Mon Apr 07 18:06:59 2014] [error] [client 80.218.68.77] script not found or unable to stat: /home/fillesmag/domains/api.fillesmag.com/cgi-bin/php
[Mon Apr 07 18:06:59 2014] [error] [client 80.218.68.77] script not found or unable to stat: /home/fillesmag/domains/api.fillesmag.com/cgi-bin/php5
[Mon Apr 07 18:07:00 2014] [error] [client 80.218.68.77] script not found or unable to stat: /home/fillesmag/domains/api.fillesmag.com/cgi-bin/php-cgi
[Mon Apr 07 18:07:00 2014] [error] [client 80.218.68.77] script not found or unable to stat: /home/fillesmag/domains/api.fillesmag.com/cgi-bin/php.cgi
[Mon Apr 07 18:07:00 2014] [error] [client 80.218.68.77] script not found or unable to stat: /home/fillesmag/domains/api.fillesmag.com/cgi-bin/php4

Here's the block of code at line 851:

 $ch = curl_init($endpoint);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    $response = curl_exec($ch);
    $errno = curl_errno($ch);
    $errmsg = curl_error($ch);
    curl_close($ch);

Should there be cgi-bin in this folder? I've also come across that this error can be cgi files that aren't properly configured or in the correct folder.

This is from the access log:

66.25.153.86 - - [03/Apr/2014:04:41:04 -0400] "GET /purchases/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD?environment=debug HTTP/1.1" 200 332 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"
66.25.153.86 - - [03/Apr/2014:04:42:19 -0400] "GET /issues/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD?environment=debug HTTP/1.1" 200 523 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"
66.25.153.86 - - [03/Apr/2014:04:42:19 -0400] "POST /confirmpurchase/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD HTTP/1.1" 500 267 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"
66.25.153.86 - - [03/Apr/2014:04:42:20 -0400] "POST /confirmpurchase/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD HTTP/1.1" 500 267 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"
66.25.153.86 - - [03/Apr/2014:04:42:20 -0400] "POST /confirmpurchase/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD HTTP/1.1" 500 267 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"
66.25.153.86 - - [03/Apr/2014:04:42:20 -0400] "POST /confirmpurchase/com.prismstudios.fillesmagazine/B88C837F-A662-44CC-B291-7CB0291CD4CD HTTP/1.1" 500 267 "-" "Filles%20Magazine/4.2.1 CFNetwork/672.1.13 Darwin/14.0.0"

These are the errors from the /var/log/apache2/error.log:

[Tue Apr 01 01:22:06 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03\x01
[Tue Apr 01 01:22:06 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03\x01
[Tue Apr 01 01:22:06 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03
[Tue Apr 01 01:22:17 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03\x01
[Tue Apr 01 01:22:17 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03\x01
[Tue Apr 01 01:22:17 2014] [error] [client 66.25.153.86] Invalid method in request \x16\x03
Tue, 04/08/2014 - 04:11
Locutus

The key error would seem to be this:

[Mon Apr 07 17:29:18 2014] [warn] [client 66.25.153.86] mod_fcgid: stderr: PHP Fatal error:  Call to undefined function curl_init() in /home/fillesmag/domains/api.fillesmag.com/public_html/index.php on line 851

Do you have the CURL extension active in PHP? You can verify that in the PHP ini file/editor of the domain in question.

Googling for the error message usually helps. ;)

http://stackoverflow.com/questions/6382539/call-to-undefined-function-cu...

Tue, 04/08/2014 - 09:08
andreychek

Howdy,

One of the errors in your Apache logs was the following:

Call to undefined function curl_init()

That can occur if the PHP Curl module isn't installed/enabled.

Is the PHP Curl package installed on your system?

-Eric

Tue, 04/08/2014 - 14:16
codewarrior_777

Yes, that was it. My main problem for the last couple of days was that I was looking for errors in the top level domain and not the sub domain.

My server is an Ubuntu 12.04.4

I fixed the issue by installing the PHP curl extension:

sudo apt-get install php5-curl

Then in /etc/php5/apache2/php.ini in the Dynamic Extensions block I added this one line:

extension=curl.so

Then rebooted the server:

sudo reboot
Tue, 04/08/2014 - 14:26
codewarrior_777

I solved it. My main problem for the last couple of days was that I was looking for errors in the top level domain and not the sub domain i.e api.fillesmag.com

Also, I'm managing my own server. It may be that managed servers install this extension by default? My server is an Ubuntu 12.04.4

I fixed the issue by installing the PHP curl extension:

    sudo apt-get install php5-curl

Then in /etc/php5/apache2/php.ini in the Dynamic Extensions block I added this one line:

    extension=curl.so

Then rebooted the server:

    sudo reboot

Now everything is working as it should.

Tue, 04/08/2014 - 17:18
Locutus

You wouldn't even have needed to reboot the server, an Apache restart would have sufficed. :) Just so you know for the next time you need to activate a PHP extension.

Topic locked