首页 > 解决方案 > 如何将 Lumen API 投入生产?什么主机?

问题描述

我在 PHP Lumen 中制作了一个 API,并尝试将其投入生产。这是我第一次这样做,所以我有点迷路了^^'

我通常使用启动服务器

php -S localhost:3000 -t public

您能解释一下如何将我的项目投入生产吗?

抱歉,我看了很多文章,但无法理解这一点!

谢谢你的帮助=)

标签: phplumenproduction

解决方案


我遇到了同样的问题。这是您的问题的解决方案。

  1. 为您的项目创建服务器块。我正在使用 nginx
server {
        server_name <<domin name>>;
        root /srv/<<project name>>/public;
        index index.php index.html;
        client_max_body_size 20M;
        location / {
           try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php {
                fastcgi_index index.php;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED 
                $document_root$fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME 
                $document_root$fastcgi_script_name;
        }
        
        location ~* \.(css|less|js|jpg|png|gif)$ {
                add_header Cache-Control "no-cache, no-store, must-revalidate";
                add_header Pragma "no-cache";
                expires 0;
        }
}

推荐阅读