nginx安装laravel 7.3

安装php72w

安装mysql57

安装nginx

 

下面说安装 laravel7.3

安装下载composer,然后拷贝到bin目录

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/bin/composer

chmod +777 /usr/bin/composer

#查看版本

composer -V

#更新国内镜像源

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

cd /usr/share/nginx/html

#composer create-project laravel/laravel test "5.5.*"  #指定版本,但是没有安装成功

#安装test应用

composer create-project laravel/laravel test

如果遇到目录已经存在test,就删除。

编辑nginx.conf,将根目录指定到test的public目录

 server {
        listen       80;
        listen       [::]:80;
        server_name  _;
 #       root         /usr/share/nginx/html;
        root  /usr/share/nginx/test/public;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /{
        root /usr/share/nginx/test/public;
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;
        }
      


         location ~\.php($|/) {                        # 后缀关键,~\ 之间无空格

            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;      #关键,访问二级目录时必须
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param    PATH_TRANSLATED    $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

 

安装完毕后,进入test目录,接着安装laravel-admin

cd test

composer require encore/laravel-admin

php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"

这一步需要编辑  test目录下的.env文件,写上数据库连接信息,并且在mysql中建立 laravel 数据库

php artisan admin:install

安装完毕后,登录 ,用户名admin,密码admin

 

回到test根目录

创建控制器

php artisan admin:make UserController  --model=App\\User

创建路由

vim test/routes/web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

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


Route::get('/u',function(){

 return view('test');
});
~                   

在resource目录下views建立 test.blade.php 文件,即可实现访问。http://47.104.226.34/u

 

posted @ 2022-03-03 10:09  琴声清幽  阅读(106)  评论(0编辑  收藏  举报