This topic describes how to install an Apache+MySQL+PHP environment on an Alibaba Cloud Linux 3 system.
Details
Important
Alibaba Cloud reminds you:
If you perform risky operations, such as modifying instances or data, make sure that your instances have disaster recovery and fault tolerance capabilities to protect your data.
If you modify the configurations or data of instances, such as Elastic Compute Service (ECS) and ApsaraDB RDS instances, create snapshots or enable features such as RDS log backup.
If you have granted permissions or submitted security information, such as logon credentials, on the Alibaba Cloud platform, change them promptly.
Connect to the Linux instance using the management terminal. For more information, see the ECS remote connection user guide.
Install the Apache+MySQL+PHP environment
The following resources and versions are used in this example:
Note
The installation steps are the same for other versions of Alibaba Cloud Linux 3.2104. The component versions that are installed depend on the versions available at the time of installation.
When you use Yellowdog Updater, Modified (YUM) to install Apache, MySQL, and PHP, the installed versions depend on the YUM source that is used. The versions may differ from those used in this topic because the YUM source is subject to change.
Step 1: Install Apache
Run the following command to install the Apache service and its extension packages.
yum -y install httpd httpd-manual mod_ssl mod_perl
yum -y install httpd httpd-devel
Run the following command to check the Apache version number.
httpd -v
The following output indicates that the Apache version is 2.4.37.

Run the following commands to start the Apache service and set it to start on boot.
systemctl start httpd
systemctl enable httpd

Verify that the Apache service is installed and running.
Log on to the ECS console.
In the navigation pane on the left, choose Instances & Images > Instances.
On the Instances page, find the target instance and copy its public IP address from the IP Address column.
In the address bar of your browser, enter http://<Public IP address of the ECS instance> and press Enter.
If a page similar to the following figure appears, the Apache service is running.
Note
The Apache service listens on port 80 by default. If you cannot access the Apache service, make sure that you have added a security group rule to allow inbound traffic on port 80 for the ECS instance. For more information, see Add a security group rule.
Step 2: Install MySQL
Run the following command to install MySQL.
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql57-community-release-el7-10.noarch.rpm && yum -y install mysql-community-server --nogpgcheck
Run the following command to check the MySQL version number.
mysql -V
The following output indicates that MySQL is installed.

You can run the following command to start MySQL.
systemctl start mysqld

Run the following command to set the MySQL service to start on boot.
systemctl enable mysqld
systemctl daemon-reload
Step 3: Install and configure PHP
Run the following command to install PHP and its common extensions.
yum -y install php php-fpm php-gd php-mysqlnd php-mbstring php-json php-pecl-zip
Run the following command to check the PHP version.
php-fpm -v

Run the following command to create a test file in the Apache website root directory.
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
In this command, /var/www/html is the website root directory. You can find the path of the website root directory by checking the value of the DocumentRoot parameter in the /etc/httpd/conf/httpd.conf configuration file.

Run the following command to restart the Apache service.
systemctl restart httpd
In the address bar of your browser, enter http://<Public IP address of the instance>/phpinfo.php and press Enter.
If the following page is displayed, the installation is successful.
After you set up the LAMP environment, delete the phpinfo.php test file to prevent data breaches.
rm -rf <website root directory>/phpinfo.php