【问题标题】:How to put Lumen API to production? What host?如何将 Lumen API 投入生产?什么主机?
【发布时间】:2020-11-02 17:01:10
【问题描述】:

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

我通常使用启动服务器

php -S localhost:3000 -t public

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

对不起,我看了很多文章,但无法理解这个!

感谢帮助 =)

【问题讨论】:

  • 您将在哪个系统上部署应用程序?在 c-panel 或某些云上?
  • 你不需要在服务器上运行命令!
  • 使用pm2服务启动app并在vhost文件中添加proxy pass

标签: php lumen production


【解决方案1】:

在服务器上传lumen项目的步骤。

  1. 将您的项目上传到服务器根目录。

  2. 将公共文件夹移动到项目文件夹中的根目录。

  3. 更新 public/index.php 文件这一行

    $app = 需要 DIR.'/../bootstrap/app.php';

    $app = 需要 DIR.'/../your-project-folder-name/bootstrap/app.php';

  4. 访问您的项目www.example.com/public/

  5. 您也可以更改公用文件夹名称。

【讨论】:

    【解决方案2】:

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

    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;
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-25
      • 2020-11-02
      • 2014-11-05
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      相关资源
      最近更新 更多