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 (Ubuntu 18.04)
Copy page
Download PDF
Setting up a LAMP environment (Ubuntu 18.04)
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 an Ubuntu 18.04 instance.​
Software versions​
  • Operating system: In the example provided in this topic, Ubuntu 18.04 is used.​
  • Apache: A web server with stable performance. In the example provided in this topic, Apache 2.4.29 is used.​
  • MySQL/MariaDB: A database management system. In the example provided in this topic, MariaDB 15.1 is used.​
  • PHP: A server-side scripting language embedded in HTML documents. In the example provided in this topic, PHP 7.2.24 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 update the package repository.​
  • ​
    apt update && apt upgrade -y​
    ​
  1. Execute the following command to install Apache. In the example provided in this topic, Apache 2.4.29 is installed.​
  • ​
    apt install -y apache2​
    ​
  1. Execute the following command to view the Apache version.​
  • ​
    apache2 -v​
    ​
  • If the following output is displayed, Apache is installed.​
  • ​
    Server version: Apache/2.4.29 (Ubuntu)​
    Server built: 2022-06-23T12:51:37​
    ​
  1. Execute the following command to specify that the Apache service automatically starts upon instance startup.​
  • ​
    systemctl enable apache2​
    ​
  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​
  1. Execute the following command to install MariaDB.​
  • ​
    apt install -y 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 10.1.48-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2​
    ​
  1. Execute the following command to specify that the MariaDB service automatically starts upon instance startup.​
  • ​
    systemctl enable 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.​
Step 3: Install and configure PHP​
  1. Execute the following command to install PHP.​
  • ​
    apt install -y php php-mysql​
    ​
  1. Execute the following command to view the PHP version.​
  • ​
    php -v​
    ​
  • If the following output is displayed, PHP is installed.​
  • ​
    PHP 7.2.24-0ubuntu0.18.04.13 (cli) (built: Jul 6 2022 12:23:22) ( NTS )​
    Copyright (c) 1997-2018 The PHP Group​
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies​
    with Zend OPcache v7.2.24-0ubuntu0.18.04.13, Copyright (c) 1999-2018, by Zend Technologies​
    ​
By default, PHP starts automatically upon instance startup. You do not need to perform any additional configuration.​
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 apache2​
    ​
  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.​
  • ​alt​​
Last updated: 2025.09.28 10:31:44