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 7)
Copy page
Download PDF
Setting up a LAMP environment (CentOS 7)
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 7.6 instance.​
Software versions​
  • Operating system: In the example provided in this topic, CentOS 7.6 is used. You can also use CentOS 7.9, veLinux 1.0 (CentOS compatible version), or other CentOS 7 series images.​
  • Apache: A web server with stable performance. In the example provided in this topic, Apache 2.4.6 is used.​
  • MySQL/MariaDB: A database management system. In the example provided in this topic, MariaDB 15.1 and MySQL Community Edition 8.4.3 are used.​
  • PHP: A server-side scripting language embedded in HTML documents. In the example provided in this topic, PHP 7.0.33 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.6 (CentOS)​
    Server built: Mar 24 2022 14:57:57​
    ​
  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.​
  • ​image​​
Step 2: Install and configure MariaDB/MySQL​
Install and configure MariaDB​
  1. Execute the following command to install MariaDB.​
  • ​
    yum -y install mariadb-server mariadb-client​
    ​
  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 5.5.68-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 download the RPM package for the MySQL Community Edition repository configuration file.​
  • ​
    wget https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm​
    ​
  1. Execute the following command to install the MySQL 8.4 Community Edition software repository configuration file.​
  • ​
    rpm -Uvh mysql84-community-release-el7-1.noarch.rpm​
    ​
  1. Execute the following command to install MySQL 8.4.​
  • ​
    yum -y install mysql-community-server​
    ​
tip​
If the Failing package is: mysql-community-libs-compat-8.4.3-1.el7.x86_64 error occurs, the GPG key for MySQL is upgraded and needs to be retrieved again. In this case, execute the following commands in sequence: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 and yum -y install mysql-server.​
  1. Execute the following command to view the MySQL version.​
  • ​
    mysql -V​
    ​
  • If the following output is displayed, MySQL is installed.​
  • ​
    mysql Ver 8.4.3 for Linux on x86_64 (MySQL Community Server - GPL)​
    ​
  1. Execute the following command to start the MySQL service and specify that it 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 view the initial password that was automatically specified during MySQL installation.​
  • ​
    grep 'temporary password' /var/log/mysqld.log​
    ​
  • Output similar to the following is displayed. In this example, the initial password is 0zNwvmpr:fOd.​
  • ​
    2021-09-17T09:31:12.142217Z 1 [Note] A temporary password is generated for root@localhost: 0zNwvmpr:fOd​
    ​
  1. Execute the following command to perform MySQL security operations and specify the password.​
  • ​
    mysql_secure_installation​
    ​
  1. Enter the initial password obtained in the previous step and press the Enter key.​
  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. Repeat the preceding steps to specify the new password, and then enter y to confirm the new password.​
  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.​
Step 3: Install and configure PHP​
  1. Execute the following command to add and update the EPEL repository.​
  • ​
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.ivolces.com/repo/epel-7.repo​
    ​
  1. Execute the following command to add the Remi repository.​
  • ​
    rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm​
    ​
  1. Execute the following command to install the yum-config-manager repository management tool.​
  • ​
    yum -y install yum-utils​
    ​
  1. Execute the following command to enable the specified Remi PHP 7.0 repository by using yum-config-manager.​
  • ​
    yum-config-manager --enable remi-php70​
    ​
  1. Execute the following command to install PHP 7.0 and common modules.​
  • ​
    yum -y install php php-mysqlnd php-fpm​
    ​
  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​
    ​
  1. Execute the following command to view the PHP version.​
  • ​
    php -v​
    ​
  • If the following output is displayed, PHP is installed.​
  • ​
    PHP 7.0.33 (cli) (built: Jun 7 2022 14:11:00) ( NTS )​
    Copyright (c) 1997-2017 The PHP Group​
    Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies​
    ​
Step 4: Access LAMP​
  1. Execute the following command to create a test file.​
  • ​
    vim /var/www/html/phpinfo.php​
    ​
tip​
/var/www/html/ is the web root directory for 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 Enter to save the modifications and close the file.​
  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.​
  • If the following output is displayed, LAMP is set up successfully.​
  • ​image​​
Last updated: 2026.06.18 17:48:25