Home >PHP Framework >ThinkPHP >How to set up a ThinkPHP3.2 environment on a virtual host
With the development of the Internet, website construction has become increasingly simpler and more convenient. If you are a developer or webmaster, you will definitely choose some frameworks or tools to help you build a website quickly. In PHP development, ThinkPHP is an excellent framework with wide applications and many fans in China. So, for those who want to try ThinkPHP on their own computers, how to set up a local development environment? This article will introduce you in detail how to set up a ThinkPHP3.2 environment on a virtual host.
1. What is a virtual host
First of all, we need to know what a virtual host is. Simply put, virtual host is a virtualization technology through which multiple independent hosts can be built on a physical server. These virtual hosts are isolated from each other. Each virtual host has its own domain name, disk space, system environment and other resources. In a virtual hosting environment, each site becomes a complete host independently, with its own operating system, website directory and access rights. Web hosting is a low-cost, high-performance website hosting solution that meets the needs of individuals and small and medium-sized businesses.
2. Choose a virtual host
Before we build a development environment, we need to choose a suitable virtual host. Compared with physical hosting, the advantages of virtual hosting are low cost and easy maintenance, making it more suitable for website construction by individuals and small and medium-sized enterprises. Currently, there are many virtual host providers on the market, such as Tencent Cloud, Alibaba Cloud, Huawei Cloud, Blue Ocean Cloud, etc. However, their prices are generally higher and may not be economical for individual webmasters. Therefore, when choosing a virtual host, we can consider some low-cost virtual host providers, such as Xinwang, Wanwang, Western Digital, etc. Their prices are relatively low, ranging from about 50 yuan to 200 yuan. .
3. Install PHP
Installing PHP is our first task in building a ThinkPHP environment. Below we take XAMPP as an example to introduce how to install PHP.
XAMPP is a software package that integrates Apache server, MySQL database, PHP, Perl and other tools. It supports multiple operating systems such as Windows, OS X, and Linux. Among the many web server support software on the existing market, XAMPP has won the favor of the majority of users with its cross-platform, easy installation, and free nature. Therefore, we here strongly recommend everyone to use XAMPP.
You can download the XAMPP installation package for the corresponding platform from its official website https://www.apachefriends.org/zh_cn/download.html.
After downloading the installation package, unzip it to the directory where the installation package is installed, then double-click the .exe file to enter the XAMPP startup interface, as follows Display:
Select Apache and MySQL in the interface, and then start these two services. Here we only need to enable Apache server.
After enabling the Apache server, open the browser and enter localhost. If the page shown below appears, the installation is successful.
Here, we modify the PHP configuration file php.ini so that it is the same version as ThinkPHP. Select the PHP configuration file php.ini in the page that opens. After editing, remove the ";" in front of extension=php_mbstring.dll and extension=php_pdo_mysql.dll, and finally save and exit.
4. Install ThinkPHP
Everything is ready, let’s start installing ThinkPHP.
Download the latest version of ThinkPHP from the official ThinkPHP website https://www.thinkphp.cn/, and then unzip it to the root directory of the website.
After installing the new version of ThinkPHP, you need to create a new database in the database. We can use MySQL and start the MySQL service in the XAMPP control panel. Then open the MySQL command line tool and enter the following statement in the command to create the database.
CREATE DATABASE `thinkphp`;
After creating the database, you need to create a new table and use the following SQL statement to create a user table:
CREATE TABLE `user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户名', `password` varchar(50) NOT NULL DEFAULT '' COMMENT '密码', `email` varchar(100) NOT NULL DEFAULT '' COMMENT '邮箱', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='测试用用户表';
Modify the configuration file of ThinkPHP. By modifying the configuration file database connection, we can allow ThinkPHP to access the newly created database. The specific operation method is as follows:
Open the Application directory under the thinkPHP root directory and find the file in the directory. database.php, modify the following information in it:
/* 数据库设置 */ 'type' => 'mysql', //数据库类型 'hostname' => '127.0.0.1', //数据库连接地址 'database' => 'thinkphp', //数据库名称 'username' => 'root', //数据库连接用户名 'password' => '', //数据库连接密码 'hostport' => '', //连接端口 'dsn' => '', //连接dsn 'debug' => true, //打开调试模式 'charset' => 'utf8', //数据库编码 'prefix' => '', //数据表前缀 'auto_timestamp' => true, //自动时间戳 'secure' => false, //启用安全链接
After installation, we can try it and enter http://localhost/ in the browser thinkphp/index.php/Home/Index/index, if you see the following interface:
, then ThinkPHP is installed successfully. !
5. Summary
Through the introduction of this article, I believe that readers have successfully set up a ThinkPHP3.2 environment on their own virtual host. In this process, we learned about the concept of virtual hosting, learned to install frameworks such as PHP and ThinkPHP, and conducted testing and verification. Virtual hosting is a very suitable environment for developing websites. It not only allows us to develop and test on our own computers, but also allows us to migrate the website to an online environment at a more appropriate time. At the same time, by putting our website on a virtual host, we can also learn more knowledge about server maintenance and security.
The above is the detailed content of How to set up a ThinkPHP3.2 environment on a virtual host. For more information, please follow other related articles on the PHP Chinese website!