- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
Self-service website creation
Building environments
Setting up a LAMP environment (CentOS 8)
Building environments
Setting up a LAMP environment (CentOS 8)
Setting up a LAMP environment (CentOS 8)
A LAMP environment refers to a web application platform built on a Linux system, consisting of Linux, Apache, MySQL or MariaDB, and PHP. This topic describes how to deploy a LAMP environment on a CentOS 8.3 instance.
Software versions
- Operating system: In the example provided in this topic, CentOS 8.3 is used.
- Apache: A web server with stable performance. In the example provided in this topic, Apache 2.4.37 is used.
- MySQL/MariaDB: A database management system. In the example provided in this topic, MariaDB 15.1 and MySQL 8.0.26 are used.
- PHP: A server-side scripting language embedded in HTML documents. In the example provided in this topic, PHP 7.3.20 is used.
Prerequisites
- An EIP is associated with the Linux instance, enabling the instance to connect to the Internet. For information about how to associate an EIP with an ECS instance, see Associating EIPs.
Step 1: Install and configure Apache
- Execute the following command to install Apache. In the example provided in this topic, Apache 2.4.6 is installed.
- Execute the following command to view the Apache version.
- If the following output is displayed, Apache is installed.
- Execute the following command to start the Apache service.
- Execute the following command to specify that the Apache service automatically starts upon instance startup.
- In the local browser, enter http://<ECS instance EIP>/ to access Apache.
- If the following output is displayed, Apache is set up successfully.
-
Step 2: Install and configure MariaDB/MySQL
Install and configure MariaDB
- Execute the following command to install MariaDB.
- Execute the following command to view the MariaDB version.
- If the following output is displayed, MariaDB is installed.
- Execute the following command to start the MariaDB service and specify that it automatically starts upon instance startup.
- Execute the following command to check whether the MariaDB service is started.
- If Active: active (running) is displayed in the output, the MariaDB service is started.
- Execute the following command to perform MariaDB security operations and specify the password.
- Press the Enter key to confirm the password.
- Enter y and press the Enter key to confirm modification of the database password for the root user.
- Specify the MariaDB password and press the Enter key. The password you enter is not displayed by default.
- Enter the new password again and press the Enter key to confirm your new password.
tip
Enter a password that meets the strength requirements of the password verification policy.
- Enter y and press the Enter key to remove the anonymous user.
- Enter y and press the Enter key to prohibit remote login by the root account.
- Enter y and press the Enter key to delete the test database and its access permission.
- Enter y and press the Enter key to reload the authorization table.
Install and configure MySQL
- Execute the following command to install MySQL.
- Execute the following command to view the MySQL version.
- If the following output is displayed, MySQL is installed.
- Execute the following command to start the MySQL service and specify that it
- automatically starts upon instance startup.
- Execute the following command to check whether the MySQL service is started.
- If Active: active (running) is displayed in the output, the MySQL service is started.
- Execute the following command to perform MySQL security operations and specify the password.
- Enter y and press the Enter key to start the relevant configuration.
- Select the password verification policy strength, and enter 2 and press the Enter key. We recommend that you select a high-strength verification policy. A value of 0 specifies low strength, 1 specifies medium strength, and 2 specifies high strength.
- Specify the new MySQL password and press the Enter key. The password you enter is not displayed by default.
- Enter the new password again and press y to confirm your new password.
tip
Enter a password that meets the strength requirements of the password verification policy.
- Enter y and press the Enter key to remove the anonymous user.
- Specify whether to allow remote connections to MySQL:
- To prohibit remote connections: Enter y and press the Enter key.
- To allow remote connections: Enter n and press the Enter key.
- Enter y and press the Enter key to delete the test database and its access permission.
- Enter y and press the Enter key to reload the authorization table.
Step 3: Install and configure PHP
- Execute the following command to add and update the EPEL repository.
- Execute the following command to delete cached unused packages and update the software repository.
- Execute the following command to enable the php:7.3 module.
- In the example provided in this topic, php:7.3 is used. If you want to use php:7.4, you need to first install the Remi repository and then start the PHP module. Command for installing the Remi repository: dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm.
- Execute the following command to install the corresponding PHP modules.
- Execute the following command to view the PHP version.
- If the following output is displayed, PHP is installed.
- Execute the following command to start the PHP-FPM service.
- Execute the following command to specify that the PHP-FPM service automatically starts upon instance startup.
Step 4: Access LAMP
- Execute the following command to create a test file.
- Press the i key to enter edit mode, and then enter the following content.
- Press Esc, enter :wq, and then press the Enter key to save the file and return to the CLI interface.
- Execute the following command to restart the Apache service.
- Enter http://<ECS instance EIP>/phpinfo.php in your local browser to access LAMP.
Last updated: 2026.06.18 17:48:25