Current Location: Home> Latest Articles> How to Set Up a ThinkPHP Development Environment

How to Set Up a ThinkPHP Development Environment

M66 2025-07-15

Install Apache Server

First, we need to install the Apache server as part of our development environment. We recommend using XAMPP to install Apache, MySQL, and PHP together.

Download the XAMPP installer, double-click to run the installation, choose an installation path according to the prompts, and click 'Next' to proceed. Once the installation is complete, launch the XAMPP control panel and click 'Start' to start the Apache server.

Install Composer

Composer is a dependency management tool for PHP. We will use it to install the ThinkPHP framework.

Visit the Composer official website to download the installer suitable for your operating system and follow the instructions to complete the installation.

Create a New ThinkPHP Project

Open the command line interface, navigate to the directory where you want to store your project, and run the following command to create a new ThinkPHP project:

<span class="fun">composer create-project topthink/think tp</span>

Note: This command will install the ThinkPHP framework in the tp subdirectory under the current directory. Make sure the target directory is empty or does not contain important files.

Configure Virtual Host

To access our project through a browser, we need to configure a virtual host.

First, open the file apache\conf\extra\httpd-vhosts.conf in your XAMPP installation directory, and add the following configuration at the end of the file:

<VirtualHost *:80>
    DocumentRoot "project_path\tp\public"
    ServerName thinkphp.test
    <Directory "project_path\tp\public">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Replace 'project_path' with the actual path of your project.

Then, open the file C:\Windows\System32\drivers\etc\hosts and add the following content:

<span class="fun">127.0.0.1 thinkphp.test</span>

Save and close the file.

Test the Project

Now, open your browser, type thinkphp.test in the address bar, and press Enter. If you see the ThinkPHP welcome page, the installation is successful.

That's it! You've successfully set up a ThinkPHP development environment. Now, you can start creating your own applications!