tp6 的基本安裝配置


1)學習環境:

運行環境:phpstudy
PHP版本大於7.1.0
用PHPstudy啟動composer下載安裝

 2)基礎dos命令

進入某個目錄:cd 目錄名
退回上級目錄:cd ..

 3)下載安裝

安裝的目錄必須是空文件夾
默認安裝最新穩定版:composer create-project topthink/think www.blog.com(自定義安裝目錄)
thinkPHP所有的版本:https://packagist.org/packages/topthink/think
安裝指定版本:composer create-project topthink/think=6.0.x-dev tp

4) 開啟debug模式

把文件前面的名稱刪掉    

5)訪問首頁

http://www.blog.com/public/index.php
安裝版本ThinkPHP V6.0.5

 6)url中去掉public目錄

http://www.blog.com/public/index.php //調整前
http://www.blog.com/index.php        //調整下

方法1:綁定域名的時候直接綁定到public目錄下

方法2:移動入口文件

第1步:把public目錄下:index.php .htaccess nginx.htaccess favicon.ico robots.txt router.php 六個文件移動到根目錄下

第2步:修改index.php的文件引入路徑:
require __DIR__ . '/../vendor/autoload.php'; //原路徑
require __DIR__ . './vendor/autoload.php';   //現路徑

7 )開啟多應用

1 composer下載多應用拓展
composer require topthink/think-multi-app//下載多應用


2 下載后的目錄地址
G:\phpstudy_pro\WWW\www.blog.com\vendor\topthink\think-multi-app

3 多應用模式部署后,記得刪除app目錄下的controller目錄(系統根據該目錄作為判斷是否單應用的依據)。

4 訪問前台:http://www.blog.com/index.php/index/index/index

 訪問后台:http://www.blog.com/index.php/admin/index/index

8)隱藏 index.php

phpstudy配置一個網站后,會在nginx 和 apache下各配置一個 .conf文件

nginx下隱藏index.conf

server {
listen 80;
server_name www.blog.com;
root "G:/phpstudy_pro/WWW/www.blog.com/public";
location / {
index index.php index.html error/index.html;
error_page 400 /error/400.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 500 /error/500.html;
error_page 501 /error/501.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;
error_page 504 /error/504.html;
error_page 505 /error/505.html;
error_page 506 /error/506.html;
error_page 507 /error/507.html;
error_page 509 /error/509.html;
error_page 510 /error/510.html;
include G:/phpstudy_pro/WWW/www.blog.com/public/nginx.htaccess;
autoindex off;

if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=/$1 last;
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}

 
         

}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
} 

 Apache下 .conf

<VirtualHost *:80>
    DocumentRoot "G:/phpstudy_pro/WWW/www.blog.com/public"
    ServerName www.blog.com
    ServerAlias 
    FcgidInitialEnv PHPRC "G:/phpstudy_pro/Extensions/php/php7.3.4nts"
    AddHandler fcgid-script .php
    FcgidWrapper "G:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php
  <Directory "G:/phpstudy_pro/WWW/www.blog.com/public">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
      DirectoryIndex index.php index.html error/index.html
  </Directory>
  ErrorDocument 400 /error/400.html
  ErrorDocument 403 /error/403.html
  ErrorDocument 404 /error/404.html
  ErrorDocument 500 /error/500.html
  ErrorDocument 501 /error/501.html
  ErrorDocument 502 /error/502.html
  ErrorDocument 503 /error/503.html
  ErrorDocument 504 /error/504.html
  ErrorDocument 505 /error/505.html
  ErrorDocument 506 /error/506.html
  ErrorDocument 507 /error/507.html
  ErrorDocument 510 /error/510.html
</VirtualHost>

 9)目錄結構

www WEB部署目錄(或者子目錄) 
├─app 應用目錄
│ ├─controller 控制器目錄 
│ ├─model 模型目錄 
│ ├─ ... 更多類庫目錄 
│ │ 
│ ├─common.php 公共函數文件 
│ └─event.php 事件定義文件 
│
├─config 配置目錄 
│ ├─app.php   應用配置 
│ ├─cache.php 緩存配置 
│ ├─console.php 控制台配置 
│ ├─cookie.php  Cookie配置 
│ ├─database.php   數據庫配置 
│ ├─filesystem.php 文件磁盤配置 
│ ├─lang.php 多語言配置 
│ ├─log.php  日志配置 
│ ├─middleware.php 中間件配置 
│ ├─route.php      URL和路由配置 
│ ├─session.php Session配置 
│ ├─trace.php   Trace配置 
│ └─view.php    視圖配置 
│
├─view 視圖目錄 
├─route 路由定義目錄 
│ ├─route.php 路由定義文件 
│ └─ ... 
│
├─public WEB目錄(對外訪問目錄) 
│ ├─index.php 入口文件 
│ ├─router.php 快速測試文件 
│ └─.htaccess 用於apache的重寫 
│
├─extend 擴展類庫目錄
├─runtime 應用的運行時目錄(可寫,可定制) 
├─vendor Composer類庫目錄[框架核心目錄] 
├─.example.env 環境變量示例文件 
├─composer.json composer 定義文件 
├─LICENSE.txt 授權說明文件 
├─README.md README 文件 
├─think 命令行入口文件

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM