Skip to content
cayman edited this page Aug 5, 2016 · 9 revisions

1. Download phprs source to your own path

For example: /home/www/phprs-restful-master

2. Setting webserver

Route RESTful requests to index.php, for example:

Nginx

location /api {
    rewrite ^(/.*)?$ /index.php;
}

Samples:

server {
    listen       80 default_server;
    server_name  localhost;
    root         /home/www/phprs-restful-master/example/public; 
    index  index.php index.html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location /api {
        rewrite ^(/.*)?$ /index.php;
    }
    location ~ \.php$ {
        root /home/www/phprs-restful-master/example/public;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi.conf;
    }
}

Apache

DocumentRoot "/var/www/phprs-restful-master/example/public"
<Directory "/var/www/phprs-restful-master/example/public">
    Options Includes ExecCGI FollowSymLinks 
    AllowOverride All 
    Require all granted
</Directory>

3. Result

Request

GET http://localhost/api/hw

Response

{"msg":"Hello World!"}

Request

GET http://localhost/api/apis/

Response

Documents

Clone this wiki locally