1 download Composer

Composer is a PHP tool for managing dependency relationships.

Windows version 1.1

Download it at getcomposer.org/

If an error is reported:

Program Output:
PHP Deprecated:  Directive 'track_errors' is deprecated in Unknown on line 0
Copy the code

Then modify php.ini:

; Track_errors = On track_errors = OffCopy the code

After the HTTP service is restarted, the installation succeeds.

MacOS version 1.2

Perform:

curl -sS https://getcomposer.org/installer | php
Copy the code

If the following information is incorrect, or the download is delayed:

Failed to decode zlib stream
Copy the code

Go to the website directly (getcomposer.org/download/) download the latest version of the composer. The phar

After downloading, run the following command in the directory where composer. Phar resides:

mv composer.phar /usr/local/bin/composer
Copy the code

To use Composer globally, run the following command to check the version number:

composer -v
Copy the code

Install/upgrade ThinkPHP6

Run the following command to switch to Ali Cloud image for accelerated download:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
Copy the code

Select a directory and run the following command:

composer create-project topthink/think projectName
Copy the code

After installation, go to the project directory and execute:

php think run
Copy the code

Browser access:

http://localhost:8000/
Copy the code

To change the port, run the following command:

php think run -p 80
Copy the code

To upgrade ThinkPHP6, go to the project root directory and execute:

composer update
Copy the code

In actual deployment, bind domain names to the public directory to ensure that other directories are not under the WEB directory.

3 Configure the debugging mode

Rename.example.env from the root directory to.env and set the following code:

 APP_DEBUG = true
Copy the code

4 Deployment of multiple applications

The directory structure

│ ├─common. PHP │ │ ├─/ WWW WEB Application directory │ │ ├─common Son son application controller │ │ ├ ─ / model application model directory │ │ ├ ─ / view child application view directory │ │ ├ ─ / config son application configuration directory │ │ ├ ─ / route son application routing directory │ │ └ ─... Child application more libraries directory │ │ | ├ ─ BaseController. The default PHP based controller class │ ├ ─ common. PHP file public function │ ├ ─ event. PHP event definition file | ├ ─ ExceptionHandle. PHP Apply the exception definition file (be sure to keep this! Otherwise the ERROR 500) | | ─ middleware. PHP global middleware definition file │ ├ ─ the provider. The PHP service definition file | └ ─ Request. PHP application Request object (be sure to keep this! Otherwise ERROR 500)Copy the code

Multi-application mode extension think-multi-App

To use multi-application mode, you need to install think-multi-App and run the following command in the project root directory to install it:

composer require topthink/think-multi-app
Copy the code

Example Modify the path of a controller

Open the app/myApp/controller/Index. PHP, adjust the namespace

-   namespace app\controller;
+   namespace app\myApp\controller;
    use app\BaseController;
Copy the code

It can then be accessed via the HTTP service:

http://127.0.0.1/thinkphp6/public/index.php/myApp
Copy the code

The URL rewrite

If you want to omit index.php, access it as follows

http://127.0.0.1/thinkphp6/public/myApp
Copy the code

Add to public/.htAccess:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/The $1 [QSA,PT,L]
</IfModule>
Copy the code

URL rewriting has been done through the default installation of official Composer, so this is just a reminder.

5 Multi-level Controller

The directory structure is as follows:

├─/ app │ ├─/ myApp │ ├─/ API │ ├─/ API │ ├─/ login. PHP │ ├─/ API │ ├─/ API │ ├─/ API │ ├─/ API │ ├─/Login. PHPCopy the code

The Login. The PHP code:

<? php namespace app\myApp\controller\api; use app\BaseController; class Login extends BaseController { publicfunction index()
    {
        return 'Secondary controller Login'; }}Copy the code

Once set, it can be accessed through the following URL:

http://127.0.0.1/thinkphp6/public/myApp/api/login
Copy the code

Automatically create API controllers

The controller can also be generated automatically from the command line, and the newly generated controller contains the default code. Execute in the root directory:

php think make:controller app\myApp\controller\api\Login --api
Copy the code

Through the above Settings, basically completed the most basic deployment of ThinkPHP6. More application development, please read the official document: www.kancloud.cn/manual/thin…

Please follow my personal wechat official number to get the latest articles ^_^