ThinkPHP is a PHP development framework. If you download the source code of ThinkPHP and want to run it locally, you need to perform the following steps.
Step one: Decompress the source code
Extract the downloaded ThinkPHP source code to the root directory of your web server (for example: /var/www/html/ or C: /xampp/htdocs/).
Step 2: Start the Web server
Enter the console of your Web server and start the Apache or Nginx server. Under Windows, you can use XAMPP or WAMP to start the Apache server. On Linux servers, you can use LAMP or LNMP.
Step 3: Set up Apache or Nginx configuration
Open the configuration file of your web server and set the root directory of the website to the directory where the ThinkPHP source code you just decompressed is located. Usually this file is httpd.conf in Apache and nginx.conf in Nginx.
For example, in the Apache configuration file httpd.conf, you can use the following statement to point the website root directory to the decompression directory of the ThinkPHP source code:
<Directory "你的thinkphp目录"> AllowOverride All Require all granted </Directory>
Step 4: Modify the ThinkPHP configuration file
In the ThinkPHP source code file, there is a file named database.php
. This file saves the configuration information related to the database connection. You need to modify these configuration information according to your own needs.
Taking the MySQL database as an example, the following is the configuration information that needs to be modified:
return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => 'localhost', // 数据库名 'database' => '数据库名', // 用户名 'username' => '用户名', // 密码 'password' => '密码', // 端口 'hostport' => '3306', ... ];
Step 5: Create a database
Open the MySQL database client and create a new database , and execute the SQL file in the ThinkPHP source code. Database files are usually located under ThinkPHP/Database/
, including two files: think_auth.sql
and think_log.sql
. Execute these two files to create the required tables and data.
Step 6: Visit the website
After completing the above operations, you can access your ThinkPHP website through the URL. If you want to run the ThinkPHP sample program, enter http://your IP address/your thinkphp directory/public
in the browser. In this way, you can see the official demo page provided by ThinkPHP.
The above is the detailed content of How to run the downloaded thinkphp source code (steps). For more information, please follow other related articles on the PHP Chinese website!