Updated on 2025-08-06 GMT+08:00

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.

Table 2 Resources and costs

Resource

Description

Cost

VPC

VPC CIDR block: 192.168.0.0/16

Free

VPC subnet

  • AZ: AZ1
  • CIDR block: 192.168.0.0/24

Free

ECS

  • Billing mode: Yearly/Monthly
  • AZ: AZ1
  • Flavor: c7.large.2
  • Image: CentOS 7.2 64bit
  • System disk: 40 GiB
  • EIP: Auto assign
  • EIP type: Dynamic BGP
  • Billed by: Traffic
  • Bandwidth: 5 Mbit/s

The following resources generate costs:

  • Cloud servers
  • EVS disks
  • EIP

For billing details, see Billing Modes.

PHP

An open-source software used for web development

Download URL:

https://rpms.remirepo.net/enterprise/remi-release-7.rpm

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:

https://getcomposer.org/installer

Free

ThinkPHP

Object-oriented lightweight PHP development framework.

Free

Procedure

  1. Log in to the ECS.
  2. Install PHP.
    1. 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
    2. Run the following commands to enable the PHP 8.0 repository:
      sudo yum -y install yum-utils
      sudo yum-config-manager --enable remi-php80
    3. 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
    4. 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  
  3. Install Composer.
    1. Run the following command to install the dependencies required by Composer:
      sudo yum install -y unzip git
    2. Run the following commands to install Composer:
      curl -sS https://getcomposer.org/installer | php
      sudo mv composer.phar /usr/local/bin/composer
    3. 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)
  4. Install ThinkPHP.
    1. 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
    2. 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:

    3. 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.