Backend Development 5 min read

How to Set Up a ThinkPHP 6.x Project with Composer, ORM, and Bootstrap UI

This tutorial walks through configuring the development environment, installing Composer, ThinkPHP 6.x, ORM extensions, setting up database credentials, running the built‑in server, and integrating Bootstrap UI components with proper view configuration and sample code snippets.

php中文网 Courses
php中文网 Courses
php中文网 Courses
How to Set Up a ThinkPHP 6.x Project with Composer, ORM, and Bootstrap UI

First, configure the environment by adding the Composer China mirror, installing the ORM extension, Composer itself, and the required PHP PDO and MySQLi packages, then create a ThinkPHP 6.x project in the chosen directory.

composer config -g repo.packagist composer https://packagist.phpcomposer.com

composer require topthink/think-orm

apt install composer

apt install php-pdo php-mysqli

composer create-project topthink/think tp6demo

Next, rename the .example.env file to .env and edit it to provide the database username, password, and enable debug mode.

root 123456 student true

Start the built‑in development server (or configure a virtual host) with the command:

php think run // localhost:8000

To add a UI, copy the Bootstrap js and css directories into public/static , then adjust config/view.php to set the static template paths.

// template replacement output

'tp1_replace_string' => [

'__JS__' => '../static/js',

'__CSS__' => '../static/css',

],

Create a test method in a controller to verify the UI import, then install the view driver:

composer require topthink/think-view

Update config/view.php to use PHP templates:

'view_suffix' => 'php'

Create the template file view/index/test.php and include the Bootstrap CSS and JS assets in the <head> section:

<!-- 引入Bootstrap CSS -->

{css href="/static/css/bootstrap.min.css"}

{css href="/static/css/style.css"}

<!-- 移动设备优先 -->

&lt;meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit-no"&gt;

Also add the JavaScript files at the end of the body :

<!-- 引入js文件 -->

{js href="/static/js/jquery-3.3.1.min.js"}

{js href="/static/js/bootstrap.bundle.min.js"}

Finally, a simple HTML snippet demonstrates a button and a table layout using Bootstrap classes:

&lt;div class="container pt-5 mt-5"&gt;

&lt;div class="row"&gt;

&lt;div class="col-3"&gt;

&lt;button class="btn btn-secondary"&gt;用户管理&lt;/button&gt;

&lt;/div&gt;

&lt;div class="col-9"&gt;

&lt;table class="table table-bordered"&gt;

&lt;thead class="bg-light"&gt;

&lt;tr&gt;&lt;th&gt;1&lt;/th&gt;&lt;th&gt;2&lt;/th&gt;&lt;th&gt;3&lt;/th&gt;&lt;th&gt;4&lt;/th&gt;&lt;th&gt;5&lt;/th&gt;&lt;/tr&gt;

&lt;/thead&gt;

&lt;/table&gt;

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;

BackendPHPTutorialBootstrapComposerThinkPHP
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.