1. 程式人生 > 其它 >php8.0.14: 建立thinkphp專案(composer2.2.1/thinkphp6.0.9)

php8.0.14: 建立thinkphp專案(composer2.2.1/thinkphp6.0.9)

一,用composer建立thinkphp專案

1,建立專案所在的目錄
liuhongdi@lhdpc:/usr/local/soft$ mkdir /data/
liuhongdi@lhdpc:/usr/local/soft$ cd /data/
liuhongdi@lhdpc:/data$ mkdir php
liuhongdi@lhdpc:/data$ cd php
2,建立專案,名字叫admapi
liuhongdi@lhdpc:/data/php$ composer create-project topthink/think admapi
說明:因為thinkphp6.0.9還不支援php8.1, 所以我們使用已支援 php 8.0.14版本 3,檢視效果:
liuhongdi@lhdpc:/data/php$ cd admapi/
liuhongdi@lhdpc:
/data/php/admapi$ php think version v6.0.9
看到已建立的thinkphp專案的版本是v6.0.9 4,升級專案中的thinkphp
liuhongdi@lhdpc:/data/php/admapi$ composer update topthink/framework
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to 
install, update or remove Generating autoload files > @php think service:discover Succeed! > @php think vendor:publish File /data/php/admapi/config/trace.php exist! Succeed! 6 packages you are using are looking for funding. Use the `composer fund` command to find out more!

說明:劉巨集締的架構森林是一個專注架構的部落格,地址:

https://www.cnblogs.com/architectforest

對應的原始碼可以訪問這裡獲取:https://github.com/liuhongdi/
或:https://gitee.com/liuhongdi

說明:作者:劉巨集締 郵箱: [email protected]

二,測試執行thinkphp:

1,執行:
liuhongdi@lhdpc:/data/php/admapi$ php think run
ThinkPHP Development server is started On <http://0.0.0.0:8000/>
You can exit with `CTRL-C`
Document root is: /data/php/admapi/public
[Thu Dec 23 12:09:29 2021] PHP 8.0.14 Development Server (http://0.0.0.0:8000) started

此處不要關閉控制檯

2,從瀏覽器訪問:
http://127.0.0.1:8000/
效果如圖:

三,thinkphp的相關命令:

1,list: 用來列出thinkphp的可用命令
liuhongdi@lhdpc:/data/php/admapi$ php think list
version 6.0.9
 
Usage:
  command [options] [arguments]
 
Options:
  -h, --help            Display this help message
  -V, --version         Display this console version
  -q, --quiet           Do not output any message
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 
Available commands:
  clear             Clear runtime file
  help              Displays help for a command
  list              Lists commands
  run               PHP Built-in Server for ThinkPHP
  version           show thinkphp framework version
make
  make:command      Create a new command class
  make:controller   Create a new resource controller class
  make:event        Create a new event class
  make:listener     Create a new listener class
  make:middleware   Create a new middleware class
  make:model        Create a new model class
  make:service      Create a new Service class
  make:subscribe    Create a new subscribe class
  make:validate     Create a validate class
optimize
  optimize:route    Build app route cache.
  optimize:schema   Build database schema cache.
route
  route:list        show route list.
service
  service:discover  Discover Services for ThinkPHP
vendor
  vendor:publish    Publish any publishable assets from vendor packages

四,通過nginx訪問thinkphp專案

1,配置 nginx的site如下:
root@lhdpc:/etc/nginx/sites-enabled# vi admapi.conf
內容:
root@lhdpc:/etc/nginx/sites-enabled# more admapi.conf
server {
        listen       8000;
        root   /data/php/admapi/public;
        server_name admapi;
        index  index.php;
        location ~ \.php {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
    }

2,檢視效果:

訪問:
http://127.0.0.1:8000/
返回:

五,檢視composer版本

liuhongdi@lhdpc:/usr/local/soft$ composer --version
Composer version 2.2.1 2021-12-22 22:21:31

六,檢視php版本:

liuhongdi@lhdpc:/data/php$ php --version
PHP 8.0.14 (cli) (built: Dec 23 2021 11:52:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies