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