ThinkPHP is an open source, fast, simple, lightweight, and object-oriented PHP development framework distributed under the Apache2 open source license. ThinkPHP is designed to develop agile web applications and to 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, and CentOS 7.x.
Prerequisites
This topic is intended for users who are learning PHP or developing applications based on the ThinkPHP framework. The ECS instance must meet the following requirements when you build the ThinkPHP framework:
A public IP address is assigned to the instance or an elastic IP address (EIP) is associated with the instance.
The operating system Alibaba Cloud Linux 3, Alibaba Cloud Linux 3, or CentOS 7.x.
The inbound rules of the security group of the instance allow traffic on ports 22, 8000, and 443. 8000 is the default port of ThinkPHP. For more information, see Add a security group rule.
Procedures
Install the PHP 8.0.
NoteThinkPHP 8.0 requires PHP 8.0 or later.
If your instance runs Alibaba Cloud Linux 3, install the OpenSSL10 dependencies.
sudo yum install -y compat-openssl10Install PHP.
Alibaba Cloud Linux 3
Run the following command to update the YUM repository:
sudo rpm -Uvh https://mirrors.aliyun.com/remi/enterprise/remi-release-8.rpm --nodepsRun the following command to enable the
php:remi-8.0module stream:sudo yum module enable -y php:remi-8.0Run the following command to install PHP:
sudo yum install -y php php-cli php-fpm php-common php-mysqlnd php-gd php-mbstring php-xml
Alibaba Cloud Linux 2
Run the following command to update the YUM repository:
sudo rpm -Uvh https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpmRun the following command to modify the configuration of the
yum-plugin-releasever-adapterplugin to supportremirepository adaptation for Alibaba Cloud Linux 2:sudo echo ", remi-php54.repo, remi-php71.repo, remi-php73.repo, remi-php80.repo, remi-php82.repo, remi.repo, epel.repo, remi-modular.repo, remi-php70.repo, remi-php72.repo, remi-php74.repo, remi-php81.repo, remi-php83.repo, remi-safe.repo" >> /etc/yum/pluginconf.d/releasever-adapter.confRun the following command to enable the PHP 8.0 repository:
sudo sed -i '1,10s/enabled=0/enabled=1/' /etc/yum.repos.d/remi-php80.repoRun the following command to install PHP:
sudo yum install -y php php-cli php-fpm php-common php-mysqlnd php-gd php-mbstring
CentOS 7.x
Update the YUM repositories.
Run the following commands to install the Extra Packages for Enterprise Linux (EPEL) repository and Remi repository:
sudo yum install -y epel-release sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpmRun the following command to enable the PHP 8.0 repository:
sudo yum install -y 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 view the version of PHP:
php -vThe following command output indicates that PHP is installed:
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 of PHP. It allows you to define and manage the external dependencies required by the project. It can also automatically install, update, and load such dependencies. For more information, visit the official website of Composer.
Install dependencies required by Composer.
sudo yum install -y unzip gitInstall Composer.
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composerView the Composer version.
composer --versionThe following information indicates that Composer is installed.

Install ThinkPHP.
Create a new ThinkPHP application by using Composer.
Run the following command to create the
my-thinkphp-appdirectory in the current directory and download the core files and dependencies of ThinkPHP.composer create-project topthink/think my-thinkphp-appChange directory to the new ThinkPHP application directory and start the ThinkPHP built-in server.
cd my-thinkphp-app php think runThe following information indicates that ThinkPHP is started.

Open your browser and enter
http://<Public IP address of the ECS instance>:8000in the address bar.When the interface can be accessed normally indicates that ThinkPHP is deployed.
Configure the Web server (production environment).
You need to create a web server, such as Apache HTTP Server or NGINX Web Server in a production environment to deploy the ThinkPHP application. You need to properly configure URL rewrite rules of the web server to ensure that framework routing works.
Configuration example of Apache. The mod_rewrite module must be 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>Configuration example of NGINX:
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } }