Lumen 项目

本文介绍了Lumen的运行环境要求,包括PHP版本和必要的PHP拓展。通过Composer安装Lumen,并展示了如何创建Lumen项目。接着详细说明了如何配置应用程序,包括设置应用密钥。最后,提供了本地和Nginx服务器上运行Lumen应用的步骤,特别是Nginx的配置细节,以确保http请求正确转为https并解决路由访问问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Lumen 运行环境要求

  • PHP >= 7.2
  • OpenSSL PHP 拓展
  • PDO PHP 拓展
  • Mbstring PHP 拓展

安装 Lumen

Lumen 使用 Composer 来管理它的代码依赖,所以在使用 Lumen 之前,请先确认你的电脑上安装了 Composer。

使用 Composer 下载 Lumen 安装包:

composer global require "laravel/lumen-installer"

创建一个 Lumen 项目 

使用 lumen new projectName 命令在您指定的目录中创建一个lumen项目。

lumen new projectName

配置

  • 将 .env.example 文件重命名为 .env
  • 设置一个随机字符串到应用程序密钥

运行你的应用程序

1.本地运行

内置的 PHP 开发服务程序:

php -S localhost:8000 -t public

 在浏览器中输入:localhost:8000 即可访问 public\index.php中的内容

2. Nginx 服务器运行

nginx.conf 配置:

配置 http 请求转为 https

server {
        listen       80;
        server_name  localhost;
        # 配置 http 请求转到 https
        return 301    https://$host$request_uri;   
}

必须设置 root ,否则 配置完https后访问https提示 No input file specified.

server {
         listen       443  ssl;
         server_name  www.test.com;
         # 设置 root 指向 public 文件夹
         root "C:\phpstudy_pro\WWW\course_study\public";
}

必须添加如下配置,否则路由不能正常访问。在你的站点配置中加入以下配置,所有的请求将会引导至 index.php 前端控制器。

location / {
       try_files $uri $uri/ /index.php?$query_string;
}

完整 nginx.conf 配置如下:

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile  on;
    keepalive_timeout 65;
    map $time_iso8601 $logdate {
        '~^(?<ymd>\\d{4}-\\d{2}-\\d{2})' $ymd;
        default                       'date-not-found';
    }
	include vhosts/*.conf;

    server {
        listen       80;
        server_name  localhost;
        return 301    https://$host$request_uri;
        root    "C:\phpstudy_pro\WWW";
        location / {
	            try_files $uri $uri/ /index.php?$query_string;
            	index  index.html index.htm index.php l.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php(.*)$  {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }

    # HTTPS server
    server {
         listen       443  ssl;
         server_name  www.test.com;
         root "C:\phpstudy_pro\WWW\course_study\public";

         ssl                  on;
         ssl_certificate      test.crt;
         ssl_certificate_key  test.key;
         #ssl_certificate      cert/www.test.com.pem;
         #ssl_certificate_key  cert/www.test.com.key;
         ssl_session_timeout  5m;
         ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
         ssl_ciphers   ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_prefer_server_ciphers   on;

         add_header X-Frame-Options "SAMEORIGIN";
         add_header X-XSS-Protection "1; mode=block";
         add_header X-Content-Type-Options "nosniff";

         index index.html index.htm index.php;

         charset utf-8;

         location / {
                  try_files $uri $uri/ /index.php?$query_string;
         }

         location = /favicon.ico { access_log off; log_not_found off; }
         location = /robots.txt  { access_log off; log_not_found off; }

         error_page 404 /index.php;

         location ~ \.php(.*)$  {
                  fastcgi_pass   127.0.0.1:9000;
                  fastcgi_index  index.php;
                  fastcgi_param HTTPS on;
                  fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
                  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                  fastcgi_param  PATH_INFO  $fastcgi_path_info;
                  fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                  include        fastcgi_params;
        }

         location ~ /\.(?!well-known).* {
                  deny all;
         }
     }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值