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

1. 下载phprs并解压代码到本地目录

如/home/www/phprs-restful-master/

2. 配置webserver

将接口请求指向到index.php

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

完整的例子:

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. 效果

请求

GET http://localhost/api/hw

响应

{"msg":"Hello World!"}

请求

GET http://localhost/api/apis/

响应

输出文档

Clone this wiki locally