Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#39935 closed defect (bug) (worksforme)

rest-api not working on PHP Built-in server instance

Reported by: thinkholic's profile thinkholic Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: REST API Keywords: reporter-feedback close
Focuses: rest-api Cc:

Description

HI. I use PHP built-in server for wordpress development instea of using WAMP/MAMP like stack.

I noticed rest-api not working on PHP built-in server and it getting no error or warning messages too.

Reproduce Steps:

  • Get fresh copy of WordPress latest
  • Create DB and update wp-config.php
  • Run the server with php -S localhost:8888 ./
  • Install rest-api plugin
  • Try to get results with 'localhost:8888/wp-json`

Actually I use to run these steps with https://github.com/thinkholic/wordpress-cli/ tool. I am doing some improvement on it and found the issue.

Change History (6)

#1 @MattyRob
8 years ago

  • Keywords reporter-feedback added

@thinkholic

I have to admit I don't fully understand the processes you are following but 2 thoughts have occurred to me with respect to your issues that may or may not help.

First is that the REST API is now a core part of WordPress activated by default in WordPress 4.7.x so why the need for the plugin?

Second, is what URL are you using to access the API? If you are not using Permalinks you'll need to use a link like this http://example.com/?rest_route=/, if permalinks are enabled you can use a prettier link like this, http://example.com/wp-json/

#2 @thinkholic
8 years ago

HI @MattyRob

Thanks! for your reply.

First is that the REST API is now a core part of WordPress activated by default in WordPress 4.7.x so why the need for the plugin?

Actually, I was planing to develop a command-line tool for introduce a different approach and a process for custom WordPress development. I am more of a nodejs developer and working on WordPress stuffs too since in early stage of the WordPress.

The focus of my project is mainly for code generation and a deployment solution. Right now, I am developing a wrapper for it.

I am thinking to integrate WP-CLI as a core of the project to archive some functions without re-inventing the wheel.

It seems, I am about to face a WordPress trademark policy violation because of the name I put to it. [Thanks to @danielbachhuber for reminding me that :)]. So I also going to change the name.

If you are not using Permalinks you'll need to use a link like this http://example.com/?rest_route=/, if permalinks are enabled you can use a prettier link like this, http://example.com/wp-json/

Actually, I have enabled the Permalinks. Anyway, ?rest_route is working fine.

#3 @MattyRob
8 years ago

  • Keywords close added

@thinkholic

Your project sounds ambitious - good luck with it - perhaps using the REST-API would allow you to interact with the WordPress core cleanly. You might find this resource helpful:
https://developer.wordpress.org/rest-api/

Based on your last comment above - do you now have the REST-API links working? Can we close the ticket?

#4 @thinkholic
8 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

@MattyRob

Yep. It'll definetly use wp-resr-api with this.

Based on your last comment above - do you now have the REST-API links working? Can we close the ticket?

With the raw URL param: yes. But still same as with pretty url. Anyway I'll close the ticket for now.

Thanks! for the help.

#5 @dd32
8 years ago

  • Milestone Awaiting Review deleted

With the raw URL param: yes. But still same as with pretty url.

FWIW; I've just tested this scenario and it works for me, although your example of suffixing ./ seems wrong, if you want to pass the docroot in you need to use -t, passing a path after as in your example appear to mean "Direct all HTTP requests to this file" - and $ php -S 10.1.2.3:8888 wordpress-develop/src/index.php seems to work in that case.

$ php -S 10.1.2.3:8888
PHP 7.1.1 Development Server started at Fri Feb 24 16:44:11 2017
Listening on http://10.1.2.3:8888
Document root is /www
Press Ctrl-C to quit.
[Fri Feb 24 16:44:16 2017] 10.1.2.3:57506 [200]: /info.php                        - Just checking $_SERVER vars
[Fri Feb 24 16:44:43 2017] 10.1.2.3:57522 [301]: /wordpress-develop/src/          - It's normally hosted on port 80, so Canonical kicked in and redirected the homepage here
[Fri Feb 24 16:45:04 2017] 10.1.2.3:57554 [200]: /wordpress-develop/src/wp-json/  - The JSON index came up as expected.
[Fri Feb 24 16:45:04 2017] 10.1.2.3:57555 [200]: /favicon.ico

#6 @thinkholic
8 years ago

@dd32

Ah! If so, as you say, the problem may occur because of the ./. It's a kinda js way to indicate current directory and possibly it's not valid here. :/

Big thanks! for helping for figure out what was the problem. :)

Hoping to write a routing file and use it for start the server. Hopefully it'll fix all those kind of issues I guess.

Note: See TracTickets for help on using tickets.