打開官網,找到這裏點擊手冊
或者直接訪問 這裏
可以看到TP6已經有了贊助商
然後往後面閱讀,發現他推薦我們讀這個
這個入門必讀還是不錯的,簡單的看看就行
後面就開始安裝吧
首先注意自己的環境php版本以及composer是否已經安裝配置了
後面有這個提示說composer太慢可以這樣配置,我覺得華爲雲的挺好的,我們就採用這個
composer config -g repo.packagist composer https://repo.huaweicloud.com/repository/php/
然後就是初步安裝
composer create-project topthink/think tp6
這個tp6就是你要存儲的代碼的文件夾,這裏你可以隨便改,之後就創建了我們的項目代碼了.
執行過程
Creating a "topthink/think" project at "./tp6" Installing topthink/think (v6.0.13) - Installing topthink/think (v6.0.13): Loading from cache Created project in /home/zhaoyao/script/php/tp/tp6 Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 16 installs, 0 updates, 0 removals - Installing topthink/think-helper (v3.1.6): Loading from cache - Installing psr/log (1.1.4): Loading from cache - Installing psr/simple-cache (1.0.1): Loading from cache - Installing topthink/think-orm (v2.0.54): Loading from cache - Installing symfony/polyfill-php80 (v1.26.0): Loading from cache - Installing symfony/polyfill-php72 (v1.26.0): Loading from cache - Installing symfony/polyfill-mbstring (v1.26.0): Loading from cache - Installing symfony/var-dumper (v4.4.44): Loading from cache - Installing psr/container (1.1.2): Loading from cache - Installing psr/cache (1.0.1): Loading from cache - Installing league/mime-type-detection (1.11.0): Loading from cache - Installing league/flysystem (1.1.9): Loading from cache - Installing league/flysystem-cached-adapter (1.1.0): Loading from cache - Installing psr/http-message (1.0.1): Loading from cache - Installing topthink/framework (v6.0.13): Loading from cache - Installing topthink/think-trace (v1.4): Loading from cache symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump) symfony/var-dumper suggests installing symfony/console (To use the ServerDumpCommand and/or the bin/var-dump-server script) league/flysystem suggests installing league/flysystem-eventable-filesystem (Allows you to use EventableFilesystem) league/flysystem suggests installing league/flysystem-rackspace (Allows you to use Rackspace Cloud Files) league/flysystem suggests installing league/flysystem-azure (Allows you to use Windows Azure Blob storage) league/flysystem suggests installing league/flysystem-webdav (Allows you to use WebDAV storage) league/flysystem suggests installing league/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2) league/flysystem suggests installing league/flysystem-aws-s3-v3 (Allows you to use S3 storage with AWS SDK v3) league/flysystem suggests installing spatie/flysystem-dropbox (Allows you to use Dropbox storage) league/flysystem suggests installing srmklive/flysystem-dropbox-v2 (Allows you to use Dropbox storage for PHP 5 applications) league/flysystem suggests installing league/flysystem-sftp (Allows you to use SFTP server storage via phpseclib) league/flysystem suggests installing league/flysystem-ziparchive (Allows you to use ZipArchive adapter) league/flysystem-cached-adapter suggests installing ext-phpredis (Pure C implemented extension for PHP) Writing lock file Generating autoload files > @php think service:discover Succeed! > @php think vendor:publish Succeed! 6 packages you are using are looking for funding. Use the `composer fund` command to find out more!
然後進入tp6文件夾
cd tp6
進行列表查看 ls -l
total 80 drwxrwxr-x 3 zhaoyao zhaoyao 4096 5月 31 12:54 app/ -rw-rw-r-- 1 zhaoyao zhaoyao 1099 5月 31 12:54 composer.json -rw-rw-r-- 1 zhaoyao zhaoyao 32490 8月 8 09:52 composer.lock drwxrwxr-x 2 zhaoyao zhaoyao 4096 8月 8 09:52 config/ drwxrwxr-x 2 zhaoyao zhaoyao 4096 5月 31 12:54 extend/ -rw-rw-r-- 1 zhaoyao zhaoyao 1822 5月 31 12:54 LICENSE.txt drwxrwxr-x 3 zhaoyao zhaoyao 4096 5月 31 12:54 public/ -rw-rw-r-- 1 zhaoyao zhaoyao 1459 5月 31 12:54 README.md drwxrwxr-x 2 zhaoyao zhaoyao 4096 5月 31 12:54 route/ drwxrwxr-x 2 zhaoyao zhaoyao 4096 5月 31 12:54 runtime/ -rw-rw-r-- 1 zhaoyao zhaoyao 180 5月 31 12:54 think drwxrwxr-x 8 zhaoyao zhaoyao 4096 8月 8 09:52 vendor/ drwxrwxr-x 2 zhaoyao zhaoyao 4096 5月 31 12:54 view/
好了,代碼已經好了,你可以選擇直接將站點部署到 public/ 目錄下,也可以選擇直接
php think run
然後就跑起來了 訪問 http://127.0.0.1:8000/ 即可.
後續思考:
我們使用命令行方式運行起這個站點,等於讓php做了web server服務器,那麼這個終端就要一直運行掛着,不能中斷,不然ctrl+c就把服務斷了.
使用命令行運行,那些代碼就等於在用命令行執行的身份在跑,那權限和身份是不是會有變化呢?普通的apache/nginx的權限跑的代碼是沒有那麼高的權限的,現在用命令行跑,肯定權限高了不少,到時候又該如何防止權限氾濫呢?
正因爲權限提高了,我們是不是可以做一些權限的事情呢?比如利用這個做一個svn代碼拉取工具,執行svn up,同理git,進行git pull 命令,拉取代碼,就相當與我們只要頁面上面點擊一下就能實現服務器上面的代碼拉取自動更新了.
命令行這樣執行和直接php fpm這樣執行效率上面有什麼差異嗎?代碼需要每次都重新加載嗎?fpm的壓力是否會減小?服務器是否可以減小CPU消耗呢?