Deployment of ThinkPHP6.0 Development Environment
Preface
Starting from the ThinkPHP6.0
version, it is no longer possible to download and install via Git
. It must be installed and updated using the Composer
method.
Installing Composer
-
Windows: Download and run Composer-Setup.exe.
-
Linux, MacOS
1
2curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Switching Sources
The official server of Composer
is located abroad, and accessing it from within China will be very slow, so we need to switch to a domestic mirror.
-
Alibaba Cloud:
1
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
-
Huawei Cloud:
1
composer config -g repo.packagist composer https://repo.huaweicloud.com/repository/php/
Installing the Stable Version of ThinkPHP6
If you are installing for the first time, switch to your WEB root directory in the command line and execute the following command:
1 | composer create-project topthink/think tp |
The directory name tp
here can be changed arbitrarily. This directory is what we will often refer to as the application root directory.
If you have already installed it before, switch to your application root directory and then execute the following command to update:
1 | composer update topthink/framework |
The update operation will delete the
thinkphp
directory and重新 download and install the new version, but it will not affect theapp
directory. Therefore, do not add any application code and libraries to the core framework directory.
The directories for the installation and update commands are different. The update must be executed under your application root directory.
Installing the Development Version of ThinkPHP6
Generally, composer
installs the latest stable version, which may not be the latest version. If you need to install a version that is updated in real-time (suitable for the learning process), you can install the 6.0.x-dev
version.
1 | composer create-project topthink/think=6.0.x-dev tp |
Enabling Debug Mode
By default, the application is in deployment mode. During development, you can modify the environment variable APP_DEBUG
to enable debug mode. After going live, switch to deployment mode.
When developing locally, you can define a .env
file under the application root directory.
After installation with
create-project
, an.example.env
file (environment variable example) will be included in the root directory. You can rename it to.env
and modify it according to your requirements. This example file already enables debug mode.
Testing the Run
Enter the command line and execute the following command:
1 | php think run |
Enter the address in the browser:
1 | http://localhost:8000/ |
You will see the welcome page. Congratulations, you have now completed the installation of ThinkPHP6.0
!
If your local port 80 is not occupied, you can also directly use
1 | php think run -p 80 |
Then you can directly access:
1 | http://localhost/ |
Running the Project with Apache
It is highly recommended to use Apache to run ThinkPHP projects. Point the Apache runtime directory to the /public
directory and configure for pseudo-static.
Modify the .htaccess
file to hide index.php
Note: Modify the .htaccess
file under the public
directory
1 | <IfModule mod_rewrite.c> |