以下是在Ubuntu上用PHPStorm配置API接口的步骤:
sudo apt update和sudo apt install php php-cli php-fpm安装PHP。server { listen 80; server_name your_domain.com; root /var/www/api; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 然后重启Nginx。 3. 在PHPStorm中创建API项目:打开PHPStorm,选择“Create New Project”,选“PHP”类型,设置项目名称和位置。 4. 编写API代码:在项目目录下创建如api.php的文件,编写处理HTTP请求和返回响应的代码,例如:
<?php header('Content-Type: application/json'); $data = ['message' => 'Hello, World!', 'status' => 200]; echo json_encode($data); ?>