Updated on 2024-07-31 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. The 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 rules listed in the following table have been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
    Table 1 Security group rules

    Direction

    Type

    Protocol

    Port/Range

    Source

    Inbound

    IPv4

    TCP

    22

    0.0.0.0/0

    Inbound

    IPv4

    TCP

    443

    0.0.0.0/0

    Inbound

    IPv4

    TCP

    8000

    0.0.0.0/0

  • To obtain and update the system and software, you are advised to update the image source to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)?

Procedure

  1. 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 commands 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  
  2. Install 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.

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