You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Building environments
Setting up a LAMP environment (CentOS 8)
Copy page
Download PDF
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​
  1. Remotely connect to and log in to the ECS instance. For more information, see Logging in to Linux instances.​
  1. Execute the following command to install Apache. In the example provided in this topic, Apache 2.4.6 is installed.​
  • ​
    yum install httpd -y​
    ​
  1. Execute the following command to view the Apache version.​
  • ​
    httpd -v​
    ​
  • If the following output is displayed, Apache is installed.​
  • ​
    Server version: Apache/2.4.37 (centos)​
    Server built: Nov 16 2020 16:18:20​
    ​
  1. Execute the following command to start the Apache service.​
  • ​
    systemctl start httpd​
    ​
  1. Execute the following command to specify that the Apache service automatically starts upon instance startup.​
  • ​
    systemctl enable httpd​
    ​
  1. In the local browser, enter http://<ECS instance EIP>/ to access Apache.​
  • If the following output is displayed, Apache is set up successfully.​
  • ​alt​​
Step 2: Install and configure MariaDB/MySQL​
Install and configure MariaDB​
  1. Execute the following command to install MariaDB.​
  • ​
    dnf -y install @mariadb​
    ​
  1. Execute the following command to view the MariaDB version.​
  • ​
    mysql -V​
    ​
  • If the following output is displayed, MariaDB is installed.​
  • ​
    mysql Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1​
    ​
  1. Execute the following command to start the MariaDB service and specify that it automatically starts upon instance startup.​
  • ​
    systemctl enable --now mariadb​
    ​
  1. Execute the following command to check whether the MariaDB service is started.​
  • ​
    systemctl status mariadb​
    ​
  • If Active: active (running) is displayed in the output, the MariaDB service is started.​
  1. Execute the following command to perform MariaDB security operations and specify the password.​
  • ​
    mysql_secure_installation​
    ​
  1. Press the Enter key to confirm the password.​
  1. Enter y and press the Enter key to confirm modification of the database password for the root user.​
  1. Specify the MariaDB password and press the Enter key. The password you enter is not displayed by default.​
  1. 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.​
  1. Enter y and press the Enter key to remove the anonymous user.​
  1. Enter y and press the Enter key to prohibit remote login by the root account.​
  1. Enter y and press the Enter key to delete the test database and its access permission.​
  1. Enter y and press the Enter key to reload the authorization table.​
Install and configure MySQL​
  1. Execute the following command to install MySQL.​
  • ​
    dnf -y install @mysql​
    ​
  1. Execute the following command to view the MySQL version.​
  • ​
    mysql -V​
    ​
  • If the following output is displayed, MySQL is installed.​
  • ​
    mysql Ver 8.0.26 for Linux on x86_64 (Source distribution)​
    ​
  1. Execute the following command to start the MySQL service and specify that it​
  1. automatically starts upon instance startup.​
  • ​
    systemctl enable --now mysqld​
    ​
  1. Execute the following command to check whether the MySQL service is started.​
  • ​
    systemctl status mysqld​
    ​
  • If Active: active (running) is displayed in the output, the MySQL service is started.​
  1. Execute the following command to perform MySQL security operations and specify the password.​
  • ​
    mysql_secure_installation​
    ​
  1. Enter y and press the Enter key to start the relevant configuration.​
  1. 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.​
  1. Specify the new MySQL password and press the Enter key. The password you enter is not displayed by default.​
  1. 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.​
  1. Enter y and press the Enter key to remove the anonymous user.​
  1. 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.​
  1. Enter y and press the Enter key to delete the test database and its access permission.​
  1. Enter y and press the Enter key to reload the authorization table.​
Step 3: Install and configure PHP​
  1. Execute the following command to add and update the EPEL repository.​
  • ​
    dnf -y install epel-release​
    dnf -y update epel-release​
    ​
  1. Execute the following command to delete cached unused packages and update the software repository.​
  • ​
    dnf clean all ​
    dnf makecache​
    ​
  1. Execute the following command to enable the php:7.3 module.​
  • ​
    dnf -y module enable php:7.3​
    ​
  • 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.​
  1. Execute the following command to install the corresponding PHP modules.​
  • ​
    dnf -y install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium​
    ​
  1. Execute the following command to view the PHP version.​
  • ​
    php -v​
    ​
  • If the following output is displayed, PHP is installed.​
  • ​
    PHP 7.3.20 (cli) (built: Jul 7 2020 07:53:49) ( NTS )​
    Copyright (c) 1997-2018 The PHP Group​
    Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies​
    ​
  1. Execute the following command to start the PHP-FPM service.​
  • ​
    systemctl start php-fpm​
    ​
  1. Execute the following command to specify that the PHP-FPM service automatically starts upon instance startup.​
  • ​
    systemctl enable php-fpm​
    ​
Step 4: Access LAMP​
  1. Execute the following command to create a test file.​
  • ​
    vim /var/www/html/phpinfo.php #/var/www/html/为Apache的网站根目录​
    ​
  1. Press the i key to enter edit mode, and then enter the following content.​
  • ​
    <?php echo phpinfo(); ?>​
    ​
  1. Press Esc, enter :wq, and then press the Enter key to save the file and return to the CLI interface.​
  1. Execute the following command to restart the Apache service.​
  • ​
    systemctl restart httpd​
    ​
  1. Enter http://<ECS instance EIP>/phpinfo.php in your local browser to access LAMP.​
​
Last updated: 2026.06.18 17:48:25