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.
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.
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.
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.
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!