All Products
Search
Document Center

Elastic Compute Service:Build the ThinkPHP framework

Last Updated:Dec 31, 2025

ThinkPHP is a free, open source, and lightweight PHP development framework released under the Apache 2.0 license. It is fast, simple, object-oriented, and designed to support agile web application development and simplify enterprise application development. This topic describes how to build the ThinkPHP 8.0 framework on Elastic Compute Service (ECS) instances that run Alibaba Cloud Linux 3, Alibaba Cloud Linux 2, or CentOS 7.x.

Prerequisites

This tutorial is for developers who are learning PHP or building applications with the ThinkPHP framework. Your ECS instance must meet the following prerequisites:

  • The instance has a public IP address or is associated with an elastic IP address (EIP).

  • The operating system is Alibaba Cloud Linux 3, Alibaba Cloud Linux 2, or CentOS 7.x.

  • The inbound rules of the instance's security group allow inbound traffic on ports 22, 8000 (the default port for ThinkPHP), and 443. For more information, see Add a security group rule.

Procedure

  1. Install PHP 8.0.

    Note

    ThinkPHP 8.0 requires PHP 8.0 or later.

    1. If your ECS instance runs Alibaba Cloud Linux 3, you can install the `compat-openssl10` dependency package.

      sudo yum install -y compat-openssl10
    2. Install PHP.

      Alibaba Cloud Linux 3/2

      1. Update the Yellowdog Updater, Modified (YUM) source.

        sudo rpm -Uvh https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
      2. Enable the PHP 8.0 repository.

        sudo yum-config-manager --enable remi-php80
      3. Install PHP.

        sudo yum install -y php php-cli php-fpm php-common php-mysqlnd php-gd php-mbstring

      CentOS 7.x

      1. Update the YUM source.

        1. Install the EPEL source and the Remi repository.

          sudo yum install -y epel-release
          sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
        2. Enable the PHP 8.0 repository.

          sudo yum-config-manager --enable remi-php80
      2. Install PHP.

           sudo yum install -y php php-cli php-fpm php-mysqlnd php-devel php-gd php-pecl-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath
    3. Check the PHP version.

      php -v

      The following output indicates that the installation is successful.

      PHP 8.0.30 (cli) (built: Aug  3 2023 17:13:08) ( NTS gcc x86_64 )
      Copyright (c) The PHP Group
      Zend Engine v4.0.30, Copyright (c) Zend Technologies           
  2. Install Composer.

    Composer is a dependency management tool for PHP projects. It allows developers to define and manage required external dependencies and automatically handles the installation, updating, and loading of these dependencies. For more information, see the official Composer website.

    1. Install the dependencies required for Composer.

      sudo yum install -y unzip git
    2. Install Composer.

      curl -sS https://getcomposer.org/installer | php
      sudo mv composer.phar /usr/local/bin/composer
    3. Check the Composer version.

      composer --version

      The following output indicates that Composer is installed.

      image

  3. Install ThinkPHP.

    1. Use Composer to create a new ThinkPHP application.

      This command creates a directory named my-thinkphp-app in the current directory and downloads the ThinkPHP core files and dependencies.

      composer create-project topthink/think my-thinkphp-app
    2. Switch to the newly created ThinkPHP application directory and start the built-in ThinkPHP development server.

      cd my-thinkphp-app
      php think run

      The following output indicates that ThinkPHP has started.

      image

    3. In the address bar of your local browser, enter http://<Public IP address of the ECS instance>:8000.

  4. Configure the web server (production environment).

    In a production environment, you must use a web server, such as Apache or Nginx, to deploy your ThinkPHP application. You must also correctly configure the server's URL rewrite rules to ensure that the framework's routing works properly.

    Apache configuration example (mod_rewrite module enabled)

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks -Indexes
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>
    

    Nginx configuration example

    location / {
        if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
           break;
        }
    }
    

References

For more information about the development specifications and directory structure of ThinkPHP, see Development specifications and Directory structure.