Updated on 2024-07-31 GMT+08:00

Manually Deploying LAMP (CentOS 7.8 PHP 7.0)

Overview

LAMP is a web application platform consisting of Linux, Apache, MySQL, and PHP.

The best practices for Huawei Cloud ECS guide you through the deployment of LAMP on a Linux ECS. The CentOS 7.8 64bit OS is used as an example in this section.

Prerequisites

  1. The ECS has an EIP bound.
  2. The rule listed in the following table has been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
    Table 1 Security group rule

    Direction

    Protocol/Application

    Port/Range

    Source

    Inbound

    HTTP(80)

    80

    0.0.0.0/0

  3. The image source has been updated to a Huawei Cloud image source. For details, see How Can I Use an Automated Tool to Configure a Huawei Cloud Image Source (x86_64 and Arm)? This facilitates obtaining and updating the system and software.

Resource Planning

Table 2 lists the resource configuration and software versions used in this practice. The commands and parameters may vary according to the hardware specifications or software versions you would use.

Table 2 Resources and costs

Resource

Description

Cost

ECS

  • Billing mode: pay-per-use
  • AZ: AZ1
  • Flavor: c7.large.2
  • Image: CentOS 7.8 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 Modes.

Apache

An open-source web server

Free

MySQL

An open-source relational database software

Download URL:

http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

Free

PHP

An open-source software used for web development

Download URL:

https://mirror.webtatic.com/yum/el7/epel-release.rpm

https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Free

Procedure

  1. Install Apache.

    1. Log in to the ECS.
    2. Run the following commands as user root to update the software package and install Apache:

      yum -y update

      yum -y install httpd

    3. Run the following command to check the version of the installed Apache:

      httpd -v

      Information similar to the following is displayed:

      Server version: Apache/2.4.6 (CentOS)
      Server built:  May 30 2023 14:01:11
    4. Run the following commands in sequence to start Apache and enable it to start automatically upon ECS startup:

      systemctl start httpd

      systemctl enable httpd

    5. 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.

  2. Install MySQL.

    1. Run the following commands in sequence to install MySQL:

      wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

      yum -y install mysql57-community-release-el7-10.noarch.rpm

      yum -y install mysql-community-server --nogpgcheck

    2. Run the following command to check the version of the installed MySQL:

      mysql -V

      Information similar to the following is displayed:

      mysql  Ver 14.14 Distrib 5.7.44, for Linux (x86_64) using  EditLine wrapper
    3. Run the following commands in sequence to start MySQL and enable it to start automatically upon ECS startup:

      systemctl start mysqld

      systemctl enable mysqld

    4. Run the following command to check the MySQL status:

      systemctl status mysqld.service

      [root@ecs-adc3 ~]# systemctl status mysqld.service
      ● mysqld.service - MySQL Server
         Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
         Active: active (running) since Tue 2023-10-31 19:33:40 CST; 36s ago
           Docs: man:mysqld(8)
                 http://dev.mysql.com/doc/refman/en/using-systemd.html
       Main PID: 7916 (mysqld)
         CGroup: /system.slice/mysqld.service
                 └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
      
      Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server...
      Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.
    5. Run the following commands to obtain the root user's password that is automatically set during MySQL installation:

      grep 'temporary password' /var/log/mysqld.log

      Information similar to the following is displayed:
      2023-10-31T11:53:08.691748Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys
    6. Run the following command and follow the prompts to harden MySQL:

      mysql_secure_installation

      Securing the MySQL server deployment.
      
      Enter password for user root:    #Enter the obtained password of user root.
      The existing password for the user account root has expired. Please set a new password.
      
      New password:  #Enter a new password of user root.
      
      Re-enter new password:   #Enter the new password again.
      The 'validate_password' plugin is installed on the server.
      The subsequent steps will run with the existing configuration of the plugin.
      Using existing password for root.
      
      Estimated strength of the password: 100
      Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #Press N.
      
       ... skipping.
      By default, a MySQL installation has an anonymous user,
      allowing anyone to log into 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 disallow remote logins 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 delete the test database and remove access 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!

  3. Install PHP.

    1. Run the following commands to install PHP 7 and required PHP extensions:

      rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

      rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

      yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb

    2. Run the following command to check the version of the installed PHP:

      php -v

      Information similar to the following is displayed:

      PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )
      Copyright (c) 1997-2017 The PHP Group
      Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    3. Run the following commands to start PHP and enable it to start automatically upon ECS startup:

      systemctl start php-fpm

      systemctl enable php-fpm

  4. Test the LAMP deployment.

    1. Create the info.php test file in /var/www/html/.
      1. Run the following command to create and open the info.php test file:

        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.
    2. Run the following command to restart Apache:

      systemctl restart httpd

    3. Enter http://Server IP address/info.php in the address bar. If the following page is displayed, the LAMP environment has been set up.