1. 程式人生 > >lumen安裝後輸出hello world

lumen安裝後輸出hello world

gis index 自己 完全 iter 無法 span .com bsp

1.安裝composer,具體請百度

2.composer 切換中國鏡像,好處自己體會,命令如下

composer config -g repo.packagist composer https://packagist.phpcomposer.com

3.下載安裝lumen框架

composer create-project --prefer-dist laravel/lumen blog

這樣安裝下來的lumen框架是完全的,即是有vendor目錄的。

接下來如何輸出hello world,

1.首先得對你的服務器做url美化配置準備,主要是忽視入口文件。

Apache

框架通過 public/.htaccess

文件來讓網址不需要 index.php。如果你的服務器是使用 Apache,請確認是否有開啟 mod_rewrite 模塊。

如果 Lumen 附帶的 .htaccess 文件在 Apache 中無法使用的話,請嘗試下方的做法:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
 

Nginx

若你使用了 Nginx,則可以在網站設置中增加以下設置,以開啟「優雅鏈接」:

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

2.新版的lumen在boatstrap/app.php 最後定義了route定義文件在routes/web.php文件裏面,所以可以直接在web.php裏面定義如下路由規則

$router->get(‘/‘, function () use ($router) {
    return ‘hello world‘;
});

然後在瀏覽器直接輸入自定義的域名就可以看到信息了,結果如下:

技術分享

最後祝大家都能成功。

lumen安裝後輸出hello world