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
Install PHP 8.0.
NoteThinkPHP 8.0 requires PHP 8.0 or later.
If your ECS instance runs Alibaba Cloud Linux 3, you can install the `compat-openssl10` dependency package.
sudo yum install -y compat-openssl10Install PHP.
Alibaba Cloud Linux 3/2
Update the Yellowdog Updater, Modified (YUM) source.
sudo rpm -Uvh https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpmEnable the PHP 8.0 repository.
sudo yum-config-manager --enable remi-php80Install PHP.
sudo yum install -y php php-cli php-fpm php-common php-mysqlnd php-gd php-mbstring
CentOS 7.x
Update the YUM source.
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.rpmEnable the PHP 8.0 repository.
sudo yum-config-manager --enable remi-php80
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
Check the PHP version.
php -vThe 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
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.
Install the dependencies required for Composer.
sudo yum install -y unzip gitInstall Composer.
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composerCheck the Composer version.
composer --versionThe following output indicates that Composer is installed.

Install ThinkPHP.
Use Composer to create a new ThinkPHP application.
This command creates a directory named
my-thinkphp-appin the current directory and downloads the ThinkPHP core files and dependencies.composer create-project topthink/think my-thinkphp-appSwitch to the newly created ThinkPHP application directory and start the built-in ThinkPHP development server.
cd my-thinkphp-app php think runThe following output indicates that ThinkPHP has started.

In the address bar of your local browser, enter
http://<Public IP address of the ECS instance>:8000.
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.