微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 @R_310_4045@ion
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 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐