Setting Up a ThinkPHP Framework
Overview
ThinkPHP, a free, open-source, fast, and simple object-oriented lightweight PHP development framework, is released under the Apache2 open source protocol and is designed for developing agile web applications and simple enterprise applications. This section guides you through the setup of ThinkPHP using an ECS running CentOS 7.2 on Huawei Cloud.
Prerequisites
- You have purchased an ECS and bound an EIP to it.
- The rule listed in the following table has been added to the security group that the target ECS belongs to. For details, see Adding a Security Group Rule.
Table 1 Security group rules Direction
Priority
Action
Type
Protocol & Port
Source
Inbound
1
Allow
IPv4
TCP: 22
0.0.0.0/0
Inbound
1
Allow
IPv4
TCP: 443
0.0.0.0/0
Inbound
1
Allow
IPv4
TCP: 8000
0.0.0.0/0
Resource Planning
Table 2 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.
Resource |
Description |
Cost |
---|---|---|
VPC |
VPC CIDR block: 192.168.0.0/16 |
Free |
VPC subnet |
|
Free |
ECS |
|
The following resources generate costs:
For billing details, see Billing Modes. |
PHP |
An open-source software used for web development Download URL: |
Free |
Composer |
Composer is a package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. Download URL: |
Free |
ThinkPHP |
Object-oriented lightweight PHP development framework. |
Free |
Procedure
- Log in to the ECS.
- Install PHP.
- Run the following commands to install the EPEL and REMI repositories:
sudo yum install -y epel-release sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- Run the following commands to enable the PHP 8.0 repository:
sudo yum -y install yum-utils sudo yum-config-manager --enable remi-php80
- Run the following command to install PHP:
sudo yum install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
- Run the following command to check the version of the installed PHP:
php -v
Information similar to the following is displayed:
PHP 8.0.30 (cli) (built: Jun 4 2024 15:19:49) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.30, Copyright (c) Zend Technologies
- Run the following commands to install the EPEL and REMI repositories:
- Install Composer.
- Run the following command to install the dependencies required by Composer:
sudo yum install -y unzip git
- Run the following commands to install Composer:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer
- Run the following command to check the version of the installed Composer:
composer --version
Information similar to the following is displayed:Composer version 2.7.7 2024-06-10 22:11:12 PHP version 8.0.30 (/usr/bin/php)
- Run the following command to install the dependencies required by Composer:
- Install ThinkPHP.
- Use Composer to create a new ThinkPHP application.
Run the following command to create my-thinkphp-app in the current directory and download the core files and dependencies of ThinkPHP:
composer create-project topthink/think my-thinkphp-app
- Run the following commands to switch to the created directory and start the ThinkPHP built-in server for development:
cd my-thinkphp-app php think run
If information similar to the following is displayed, ThinkPHP has been started:
- After the installation is complete, enter http://ECS EIP:8000 in the address bar of the browser. If the following page is displayed, ThinkPHP has been installed.
- Use Composer to create a new ThinkPHP application.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot