linux(ubuntu 20.10):安裝composer 2.0.8及thinkphp 6.0.5(php 7.4.9)
阿新 • • 發佈:2020-12-22
一,安裝前的準備工作
1,檢視當前的php版本:root@ku:/data/php# php --version PHP 7.4.9 (cli) (built: Oct 26 2020 15:17:14) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies2,安裝curl 檢查是否已安裝curl
root@ku:/data/php# whereis用apt-get 安裝curlcurl curl:
root@ku:/data/php# apt-get install curl 正在讀取軟體包列表... 完成 正在分析軟體包的依賴關係樹 正在讀取狀態資訊... 完成 下列【新】軟體包將被安裝: curl 升級了 0 個軟體包,新安裝了 1 個軟體包,要解除安裝 0 個軟體包,有 1 個軟體包未被升級。 需要下載 161 kB 的歸檔。 解壓縮後會消耗 411 kB 的額外空間。 獲取:1 http://mirrors.aliyun.com/ubuntu groovy-updates/main amd64 curl amd64 7.68.0-1ubuntu4.2 [161 kB]已下載 161 kB,耗時 0秒 (863 kB/s) 正在選中未選擇的軟體包 curl。 (正在讀取資料庫 ... 系統當前共安裝有 287815 個檔案和目錄。) 準備解壓 .../curl_7.68.0-1ubuntu4.2_amd64.deb ... 正在解壓 curl (7.68.0-1ubuntu4.2) ... 正在設定 curl (7.68.0-1ubuntu4.2) ... 正在處理用於 man-db (2.9.3-2) 的觸發器 ...
說明:劉巨集締的架構森林是一個專注架構的部落格,地址:https://www.cnblogs.com/architectforest
對應的原始碼可以訪問這裡獲取: https://github.com/liuhongdi/
說明:作者:劉巨集締 郵箱: [email protected]
二,下載/安裝composer
1,檢視是否已安裝composerroot@ku:/data/php# composer -version Command 'composer' not found, but can be installed with: apt install composer2,下載composer
root@ku:/data/php# curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading... Composer (version 2.0.8) successfully installed to: /data/php/composer.phar Use it: php composer.phar從提示可以看到:下載後文件儲存到了 /data/php目錄,也就是當前目錄下
root@ku:/data/php# ls composer.phar3,移動到/usr/local/bin目錄下
root@ku:/data/php# mv composer.phar /usr/local/bin/composer
4,測試安裝效果:
root@ku:/data/php# composer --version Do not run Composer as root/super user! See https://getcomposer.org/root for details Continue as root/super user [yes]? yes Composer version 2.0.8 2020-12-03 17:20:38說明:實際應用composer時,應該不使用root賬號 演示用普通使用者賬號檢視composer的版本:
liuhongdi@ku:~$ composer --version Composer version 2.0.8 2020-12-03 17:20:38
三,測試使用composer:
1,配置composer使用國內源:liuhongdi@ku:~$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/檢視當前composer的所有配置:
liuhongdi@ku:~$ composer config -l -g [repositories.packagist.org.type] composer [repositories.packagist.org.url] https://mirrors.aliyun.com/composer/ [process-timeout] 300 [use-include-path] false [preferred-install] auto [notify-on-install] true [github-protocols] [https, ssh] [vendor-dir] vendor (/home/liuhongdi/vendor) [bin-dir] {$vendor-dir}/bin (/home/liuhongdi/vendor/bin) [cache-dir] /home/liuhongdi/.cache/composer [data-dir] /home/liuhongdi/.local/share/composer [cache-files-dir] {$cache-dir}/files (/home/liuhongdi/.cache/composer/files) [cache-repo-dir] {$cache-dir}/repo (/home/liuhongdi/.cache/composer/repo) [cache-vcs-dir] {$cache-dir}/vcs (/home/liuhongdi/.cache/composer/vcs) [cache-ttl] 15552000 [cache-files-ttl] 15552000 [cache-files-maxsize] 300MiB (314572800) [cache-read-only] false [bin-compat] auto [discard-changes] false [autoloader-suffix] [sort-packages] false [optimize-autoloader] false [classmap-authoritative] false [apcu-autoloader] false [prepend-autoloader] true [github-domains] [github.com] [bitbucket-expose-hostname] true [disable-tls] false [secure-http] true [cafile] [capath] [github-expose-hostname] true [gitlab-domains] [gitlab.com] [store-auths] prompt [archive-format] tar [archive-dir] . [htaccess-protect] true [use-github-api] true [lock] true [platform-check] php-only [home] /home/liuhongdi/.config/composer2,更新composer:
root@ku:/data/php# composer selfupdate You are already using composer version 2.0.8 (stable channel).3,測試安裝thinkphp6:
liuhongdi@ku:/data/php$ composer create-project topthink/think mytp Creating a "topthink/think" project at "./mytp" Installing topthink/think (v6.0.5) - Downloading topthink/think (v6.0.5) - Installing topthink/think (v6.0.5): Extracting archive Created project in /data/php/mytp Loading composer repositories with package information Updating dependencies Lock file operations: 15 installs, 0 updates, 0 removals - Locking league/flysystem (1.1.3) - Locking league/flysystem-cached-adapter (1.1.0) - Locking league/mime-type-detection (1.5.1) - Locking psr/cache (1.0.1) - Locking psr/container (1.0.0) - Locking psr/log (1.1.3) - Locking psr/simple-cache (1.0.1) - Locking symfony/polyfill-mbstring (v1.20.0) - Locking symfony/polyfill-php72 (v1.20.0) - Locking symfony/polyfill-php80 (v1.20.0) - Locking symfony/var-dumper (v4.4.18) - Locking topthink/framework (v6.0.5) - Locking topthink/think-helper (v3.1.4) - Locking topthink/think-orm (v2.0.34) - Locking topthink/think-trace (v1.4) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 15 installs, 0 updates, 0 removals - Downloading psr/cache (1.0.1) - Downloading league/mime-type-detection (1.5.1) - Downloading league/flysystem (1.1.3) - Downloading league/flysystem-cached-adapter (1.1.0) - Downloading psr/container (1.0.0) - Downloading symfony/polyfill-php80 (v1.20.0) - Downloading symfony/polyfill-php72 (v1.20.0) - Downloading symfony/polyfill-mbstring (v1.20.0) - Downloading symfony/var-dumper (v4.4.18) - Downloading topthink/think-helper (v3.1.4) - Downloading psr/simple-cache (1.0.1) - Downloading psr/log (1.1.3) - Downloading topthink/think-orm (v2.0.34) - Downloading topthink/framework (v6.0.5) - Downloading topthink/think-trace (v1.4) - Installing psr/cache (1.0.1): Extracting archive - Installing league/mime-type-detection (1.5.1): Extracting archive - Installing league/flysystem (1.1.3): Extracting archive - Installing league/flysystem-cached-adapter (1.1.0): Extracting archive - Installing psr/container (1.0.0): Extracting archive - Installing symfony/polyfill-php80 (v1.20.0): Extracting archive - Installing symfony/polyfill-php72 (v1.20.0): Extracting archive - Installing symfony/polyfill-mbstring (v1.20.0): Extracting archive - Installing symfony/var-dumper (v4.4.18): Extracting archive - Installing topthink/think-helper (v3.1.4): Extracting archive - Installing psr/simple-cache (1.0.1): Extracting archive - Installing psr/log (1.1.3): Extracting archive - Installing topthink/think-orm (v2.0.34): Extracting archive - Installing topthink/framework (v6.0.5): Extracting archive - Installing topthink/think-trace (v1.4): Extracting archive 13 package suggestions were added by new dependencies, use `composer suggest` to see details. 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!檢視已安裝的thinkphp
liuhongdi@ku:/data/php$ cd mytp liuhongdi@ku:/data/php/mytp$ ls app composer.json composer.lock config extend LICENSE.txt public README.md route runtime think vendor view測試執行thinkphp6
root@ku:/etc/nginx/sites-enabled# cd /data/php/mytp/ root@ku:/data/php/mytp# php think run ThinkPHP Development server is started On <http://127.0.0.1:8000/> You can exit with `CTRL-C` Document root is: /data/php/mytp/public [Tue Dec 22 15:44:01 2020] PHP 7.4.9 Development Server (http://0.0.0.0:8000) started從瀏覽器訪問:
http://127.0.0.1:8000/返回:
四,檢視linux的版本:
root@ku:/data/php# more /etc/os-release NAME="Ubuntu Kylin" VERSION="20.10 (Groovy Gorilla)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.10" VERSION_ID="20.10" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=groovy UBUNTU_CODENAME=groovy