一,用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
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,测试运行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