Home >PHP Framework >ThinkPHP >Share thinkphp download and installation tutorial

Share thinkphp download and installation tutorial

PHPz
PHPzOriginal
2023-04-11 10:31:103045browse

thinkphp is a PHP development framework that is lightweight, efficient, easy to learn, etc., so it is very popular among developers. This article will introduce the download and installation tutorial of thinkphp for the reference of developers.

1. Download thinkphp

1. Download the source code package from thinkphp’s official website at http://www.thinkphp.cn/download.html.

2. Select the latest version and click download. After the download is complete, unzip it to any local directory.

2. Install thinkphp

1. Configure the environment

To build a development environment locally, you need to install Web Server, PHP and MySQL. The specific installation tutorials will not be described here. Developers can check the relevant tutorials by themselves.

2. Configure virtual host

Add a virtual host in Apache's virtual host configuration file (httpd-vhosts.conf), and set the thinkphp decompression directory to the root directory of the virtual host.

Sample code:

<VirtualHost *:80>
    ServerAdmin test@test.com
    DocumentRoot "D:/xampp/htdocs/tp5/public"
    ServerName tp5.com
    ErrorLog "logs/tp5.com-error.log"
    CustomLog "logs/tp5.com-access.log" common
    <Directory "D:/xampp/htdocs/tp5/public">
    #此处建议设置为All。如果只想允许访问某些目录,可以使用对应的目录名称。 
        Require all granted 
    </Directory>
</VirtualHost>

3. Set up the database

In the application directory of thinkphp, find the database.php file and modify the database configuration information in it to local MySQL information.

Sample code:

return [
    // 数据库类型
    'type'            => 'mysql',
    // 服务器地址
    'hostname'        => 'localhost',
    // 数据库名
    'database'        => 'database',
    // 用户名
    'username'        => 'root',
    // 密码
    'password'        => 'root',
    // 端口
    'hostport'        => '',
    //连接dsn
    'dsn'             => '',
    // 数据库连接参数
    'params'          => [],
    // 数据库编码默认采用utf8
    'charset'         => 'utf8',
    // 数据库表前缀
    'prefix'          => '',
    // 数据库调试模式
    'debug'           => false,
    // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
    'deploy'          => 0,
    // 数据库读写是否分离 主从式有效
    'rw_separate'     => false,
    // 读写分离后 主服务器数量
    'master_num'      => 1,
    // 指定从服务器序号
    'slave_no'        => '',
    // 是否严格检查字段是否存在
    'fields_strict'   => true,
    // 数据集返回类型
    'resultset_type'  => 'array',
    // 自动写入时间戳字段
    'auto_timestamp'  => false,
    // 时间字段取出后的默认时间格式
    'datetime_format' => 'Y-m-d H:i:s',
    // 是否需要进行SQL性能分析
    'sql_explain'     => false,
];

3. Run thinkphp

1. Create a new application under the domain name corresponding to the virtual host (such as tp5.com).

Example command (needs to be run in the decompression directory of thinkphp):

php think build your_app

Here, your_app refers to the name of the created application, which can be modified according to your own preferences.

2. Enter the domain name corresponding to the virtual host (such as tp5.com) in the browser to enter the default interface of the application.

After completing all the above steps, you have successfully installed the thinkphp framework. Developers can carry out secondary development on this basis to achieve more interesting functions.

The above is the detailed content of Share thinkphp download and installation tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn