laravel centos7.5 nginx 开发

其他项目组改为laravel进行开发,最近需要加入该项目,之前只用过thinkphp,所以需要从头开始,网上各种百度搜集。目前完成了开发环境搭建([使用宝塔面板][1]),并部署laravel项目,使用composer加载项目中引用的文件,主要是vendor文件夹中的文件,进行api配置,访问后返回了helloworld。

1 搭建环境

安装centos7.5,并安装宝塔面板,使用命令行安装

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh

安装完成后,在宝塔面板中安装lnmp,并创建网站。

2 下载laravel的git项目

下载https://github.com/laravel/laravel项目的源码放置到网站目录,指定public为网站根目录。

3安装composer

系统命令行执行

wget https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer
chmod a+x /usr/local/bin/composer

使用下列命令查看是否安装成功,以及版本

composer --version

4查看laravel的官方文档

官方文档:https://laravel.com/docs/5.7

5启用api测试

5.1 修改路由

修改文件 laravel根目录/routes/api.php

//之前的路由注释掉
//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});

//增加api的路由
Route::namespace('Api')->group(function(){

    Route::any('index','IndexController@index');
    
});

增加对应的控制器
在这里插入图片描述
增加控制器函数
在这里插入图片描述
输入网址访问http://localhost/api/index
但是访问出现404错误,需要修改nginx中对应网站的server配置,

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

之后即可查看到hello world字符串

6使用php artisan

安装laravel

composer global require “laravel/installer”

执行php artisan 创建模型
出现错误 Could not open input file artisan
是需要cd 到网站目录,然后再执行

php artisan make:model test

即可再app目录下生成model文件

[1]:宝塔面板安装说明 https://www.bt.cn/bbs/thread-1186-1-1.html

猜你喜欢

转载自blog.csdn.net/w88193363/article/details/83544927