First, we need to install an Apache server locally to run PHP and MySQL. XAMPP is recommended for setting up a local development environment, as it integrates Apache, MySQL, and PHP, making it easy to install and use.
Download and install XAMPP, choosing the installation path based on the prompts. Once installed, launch the XAMPP control panel and click the 'Start' button to start the Apache server.
Composer is a PHP dependency management tool used to manage the installation of ThinkPHP. You will need Composer to install the ThinkPHP framework.
Visit the Composer official website to download the installer. Choose the installation method based on your operating system and complete the installation.
After installing Composer, open the command line tool and navigate to your project folder. Run the following command to create a new ThinkPHP project:
<span class="fun">composer create-project topthink/think tp</span>
This command will create a new folder called 'tp' in your current directory and install the ThinkPHP framework inside it. Make sure your working directory is empty or does not contain important files to avoid installation issues.
To access your ThinkPHP project in the browser, you need to configure a virtual host.
Open the file apache\conf\extra\httpd-vhosts.conf inside the XAMPP installation directory and add the following configuration:
<VirtualHost *:80>
DocumentRoot "ProjectPath\tp\public"
ServerName thinkphp.test
<Directory "ProjectPath\tp\public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Replace 'ProjectPath' with the actual path of your project.
Next, edit the file C:\Windows\System32\drivers\etc\hosts and add the following line:
<span class="fun">127.0.0.1 thinkphp.test</span>
Save and close the file.
Once the configuration is done, open your browser and type 'thinkphp.test' in the address bar. If you see the ThinkPHP welcome page, the installation was successful.
Now you've successfully set up a ThinkPHP development environment and can start building your own applications!