1

So I just finished the implementation of a REST API for my business client using this proposed skeleton as a start: https://github.com/ezimuel/zend-expressive-api

After programming the API as I was required by my client, I managed to get it to work on localhost by opening a console terminal in the root folder of the project and typing:

php -S 0.0.0.0:8080 -t c:/wamp64/www/myAPI/public/

After that, all I had to do in order to see it working was through a HTTPie window by tiping:

http GET :8080/api/users

...and so on. Works like a charm.

So now I have got to publish it on my Apache Webserver, shared hosting, which means no root access whatsoever.

The problem is, I can't get it to work because when I try direct access to the folder http://myswebsite.com/myapi/public the script returns:

Cannot GET http://myswebsite.com/myapi/public/

I expected to see an output in hal+json containing the list of users. When in localhost I can do:

http GET :8080/api/users

The script then returns:

HTTP/1.1 200 OK Connection: close Content-Type: application/hal+json Date: Mon, 07 May 2018 14:54:46 +0200 Host: localhost:8080

{
    "_embedded": {
        "users": [
            {
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/api/users/1"
                    }
                },
                "email": "foo@host.com",
                "id": "1",
                "name": "Foo"
            }
        ]
    },
    "_links": {
            "self": {
                "href": "http://localhost:8080/api/users?page=1"
            }
        },
        "_page": 1,
        "_page_count": 1,
        "_total_items": 1
}

My goal: I would like to be able to have the same results when accessing via URL on internet, PHP + Apache + MySql shared hosting.

Any help would be appreciated. Thanks in advance.

1 Answers1

0

I did it!

After digging a little on htaccess's docs I found a way to route requests from the root folder to the public folder, that's all I needed to do:

RewriteEngine on
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]