laravel 安装 windows下nginx环境

安装的时候本想安最新的laravel8 结果发现本地php版本是7.0.13,最终只能安装laravel5.5

 1,查看php版本

PS D:\Visual-NMP-x64\www\Demo1\feng_app> php -v
PHP 7.0.13 (cli) (built: Nov  8 2016 13:33:09) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans

2,查看composer 版本

PS D:\Visual-NMP-x64\www\Demo1\feng_app> composer -V
Composer version 2.1.9 2021-10-05 09:47:38

3,执行安装

PS D:\Visual-NMP-x64\www\Demo1> composer create-project laravel/laravel feng_app
Creating a "laravel/laravel" project at "./feng_app"
Installing laravel/laravel (v5.5.28)
  - Downloading laravel/laravel (v5.5.28)
  - Installing laravel/laravel (v5.5.28): Extracting archive
Created project in D:\Visual-NMP-x64\www\Demo1\feng_app

 

php 默认安装后,需要解禁函数
putenv()
proc_open()
proc_get_status()


默认安装扩展:
fileinfo

 

4,因为使用的是nginx 需要配置nginx的环境

server {
        #sitename    Demo1
        listen       20081;
        server_name  localhost;
        root         D:/Visual-NMP-x64/www/Demo1/feng_app/public; 
        #error_log    D:/Visual-NMP-x64/logs/Nginx/D__Visual-NMP-x64_www_Demo1-error.log;
        #access_log   D:/Visual-NMP-x64/logs/Nginx/D__Visual-NMP-x64_www_Demo1-access.log;       
        autoindex    on;
        index        index.php index.html index.htm;
        
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";

 
        location / {
        try_files $uri $uri/ /index.php?$query_string;
        
        }                
        location  ~ [^/]\.php(/|$) {
                fastcgi_split_path_info  ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }
                fastcgi_pass   127.0.0.1:9002;
                fastcgi_index  index.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;
        }
    }

 

5,查看效果如图

 

6,创建控制器

PS D:\Visual-NMP-x64\www\Demo1\feng_app> php artisan make:controller  IndexController
Controller created successfully.
PS D:\Visual-NMP-x64\www\Demo1\feng_app> php artisan make:controller  Admin/IndexController
Controller created successfully.

控制器代码

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class IndexController extends Controller
{
     public function index()
    {
        return view('index');
    }
}

显示效果

 

路由web.php代码

Route::get('/index',  'IndexController@index');

Route::get('/', function () {
    return view('welcome');
});

Route::get('/test', function () {
    return 'feng_app is working';
});

访问test的显示效果

7,配置数据库mysql和redis

env文件

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=feng_app
DB_USERNAME=root
DB_PASSWORD=123456

 

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

安装redis包

PS D:\Visual-NMP-x64\www\Demo1\feng_app> composer require predis/predis

 

修改IndexController

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;


class IndexController extends Controller
{
     public function index(Request $request)
    {
        $n = $request->input('name','nnn');
        $t = Redis::get('test');
        Redis::set('name', $n);
        Redis::setex('str', 10, 'bar');
        $c=Redis::exists('foo');
        if($c){Redis::del('name');}
        $users = DB::select('select * from admin_users where id = ?', [1]);
        return view('index',['users' => $users,'redis_test'=>$t]);
    }
}

 

修改index.blade.php模板

 <div class="content">
                <div class="title m-b-md">
                    index
                </div>
                redis:{{$redis_test}}<br>
                mysql:
                @foreach ($users as $r)
                    {{ $r->id }}  {{ $r->name }} {{ $r->username }} <br> 
                @endforeach
                
            </div>

显示效果

 

 

 

 

 

 

 

 

 

posted @ 2021-10-22 10:09  fsl  阅读(528)  评论(0编辑  收藏  举报