Updated on 2026-07-29 GMT+08:00

Manually Deploying LAMP (CentOS 8)

Overview

LAMP is one of the most common web development environments. LAMP is short for Linux, Apache, MySQL, and PHP.

This best practice guides you through the deployment of LAMP on a Linux ECS. The CentOS 8.0 64bit OS is used as an example in this section.

Prerequisites

  • The ECS memory must be greater than or equal to 4 GiB.
  • An EIP has been bound to the ECS. For details, see Binding an EIP.
  • The rules listed in the following table have been added to the security groups that the target ECS belongs to. For details, see Adding a Security Group Rule.
    Table 1 Security group rules

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Resource Planning

Table 2 Resources and costs

Resource

Description

Cost

ECS

  • Billing mode: Pay-per-use
  • AZ: AZ1
  • Flavor: ac9.large.2
  • Image: CentOS 8.0 64bit
  • System disk: 40 GiB
  • EIP: Auto assign
  • EIP type: Dynamic BGP
  • Billed by: Traffic
  • Bandwidth: 5 Mbit/s

The following resources generate costs:

  • ECSs
  • EVS disks
  • EIPs

For billing details, see Billing Mode Overview.

Apache

An open-source web server

Free

MySQL

An open-source relational database software

Free

PHP

An open-source software used for web development

Free

Process

To deploy a LAMP environment on an ECS running CentOS, do as follows:

  1. Install Apache.
  2. Install MySQL.
  3. Install PHP.
  4. Test the LAMP deployment.

Procedure

  1. Log in to the ECS.

    For details, see Login Overview (Linux).

  2. Install Apache.

    1. Run the following command to install Apache:
      sudo dnf install -y httpd
    2. Run the following command to configure automatic startup:
      sudo systemctl enable httpd
    3. Run the following command to start the Apache server:
      sudo systemctl start httpd
    4. Run the following command to check whether the Apache server is successfully installed:
      httpd -v
    5. If information similar to the following is displayed, the installation is successful.

    6. Enter http://server-IP-address in the address bar of the browser to access Apache. If the following page is displayed, Apache has been installed.

  3. Install MySQL.

    1. Run the following command to install MySQL:
      sudo dnf -y install @mysql
    2. Run the following command to check the MySQL version:
      mysql -V

      If information similar to the following is displayed, the installation is successful.

    3. Run the following commands in sequence to start MySQL and enable automatic startup at boot:
      systemctl start mysqld
      systemctl enable mysqld
    4. Run the following command to check the MySQL status:
      systemctl status mysqld.service

      If information similar to the following is displayed, MySQL is running.

    5. Run the following command and follow the prompts to harden MySQL:
      mysql_secure_installation
      Securing the MySQL server deployment.
      
      Connecting to MySQL using a blank password.
      
      VALIDATE PASSWORD COMPONENT can be used to test passwords
      and improve security. It checks the strength of password
      and allows the users to set only those passwords which are
      secure enough. Would you like to setup VALIDATE PASSWORD component?
      
      Press y|Y for Yes, any other key for No: Y    #Press Y to set the password validation policy.
      
      There are three levels of password validation policy:
      
      LOW    Length >= 8
      MEDIUM Length >= 8, numeric, mixed case, and special characters
      STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
      
      Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2       #Enter 2 to select a password validation policy.
      Please set the password for root here.
      
      New password:  #Set a new password for user root.
      
      Re-enter new password:   #Enter the new password again.
      
      Estimated strength of the password: 100
      Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y  #Press Y to confirm the new password.
      By default, a MySQL installation has an anonymous user,
      allowing anyone to log in to MySQL without having to have
      a user account created for them. This is intended only for
      testing, and to make the installation go a bit smoother.
      You should remove them before moving into a production
      environment.
      
      Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   #Press Y to remove anonymous users.
      Success.
      
      
      Normally, root should only be allowed to connect from
      'localhost'. This ensures that someone cannot guess at
      the root password from the network.
      
      Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   #Press Y to disable remote login of user root.
      Success.
      
      By default, MySQL comes with a database named 'test' that
      anyone can access. This is also intended only for testing,
      and should be removed before moving into a production
      environment.
      
      
      Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #Press Y to remove the test database and access permissions to it.
       - Dropping test database...
      Success.
      
       - Removing privileges on test database...
      Success.
      
      Reloading the privilege tables will ensure that all changes
      made so far will take effect immediately.
      
      Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #Press Y to reload privilege tables.
      Success.
      
      All done!

  4. Install PHP.

    1. Run the following commands to install and update the EPEL source:
      sudo dnf -y install epel-release
      sudo dnf -y update epel-release
    2. Run the following commands to start PHP and enable automatic startup at boot:
      systemctl start php-fpm
      systemctl enable php-fpm
    3. Run the following command to install PHP and the required module:
      sudo 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
    4. Run the following command to check the version of the installed PHP:
      php -v
    5. If information similar to the following is displayed, the installation is successful.

  5. Test the LAMP deployment.

    1. Create the info.php test file in /var/www/html/.
      vim /var/www/html/info.php
    2. Press i to enter insert mode.
    3. Modify the info.php file and add the following to the file:
      <?
        php  phpinfo(); 
      ?>
    4. Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
    5. Enter http://server-IP-address/info.php in the address bar. If the following page is displayed, the environment has been set up.

Follow-up Operations

After the LAMP environment is deployed, refer to the following to set up a website or application:

FAQs

  1. Why can't I access the info.php page over an EIP?

    Possible causes: Port 80 is not allowed in security groups, the system firewall is enabled, or port 80 is occupied.

    For details, see Why Am I Unable to Connect to a Port on an ECS?

  2. How do I allow remote access to MySQL?

    Create a non-root user account for remote MySQL access and allow the remote server to use this account to access MySQL. For details, see Deploying MySQL on a Linux ECS.