Manually install an Apache+MySQL+PHP environment on Alibaba Cloud Linux 3

更新时间:
复制 MD 格式

This topic describes how to install an Apache+MySQL+PHP environment on an Alibaba Cloud Linux 3 system.

Details

Important

Alibaba Cloud reminds you:

  • If you perform risky operations, such as modifying instances or data, make sure that your instances have disaster recovery and fault tolerance capabilities to protect your data.

  • If you modify the configurations or data of instances, such as Elastic Compute Service (ECS) and ApsaraDB RDS instances, create snapshots or enable features such as RDS log backup.

  • If you have granted permissions or submitted security information, such as logon credentials, on the Alibaba Cloud platform, change them promptly.

Connect to the Linux instance using the management terminal. For more information, see the ECS remote connection user guide.

Install the Apache+MySQL+PHP environment

The following resources and versions are used in this example:

  • Operating system: Alibaba Cloud Linux 3.2104 LTS 64-bit on an ECS instance

  • Apache version: 2.4.37

  • MySQL version: 5.7.41

  • PHP version: 7.4.19

Note
  • The installation steps are the same for other versions of Alibaba Cloud Linux 3.2104. The component versions that are installed depend on the versions available at the time of installation.

  • When you use Yellowdog Updater, Modified (YUM) to install Apache, MySQL, and PHP, the installed versions depend on the YUM source that is used. The versions may differ from those used in this topic because the YUM source is subject to change.

Step 1: Install Apache

  1. Run the following command to install the Apache service and its extension packages.

    yum -y install httpd httpd-manual mod_ssl mod_perl
    yum -y install httpd httpd-devel
  2. Run the following command to check the Apache version number.

    httpd -v

    The following output indicates that the Apache version is 2.4.37.

    20230206104730

  3. Run the following commands to start the Apache service and set it to start on boot.

    systemctl start httpd
    systemctl enable httpd

    20230206105021

  4. Verify that the Apache service is installed and running.

    1. Log on to the ECS console.

    2. In the navigation pane on the left, choose Instances & Images > Instances.

    3. On the Instances page, find the target instance and copy its public IP address from the IP Address column.

    4. In the address bar of your browser, enter http://<Public IP address of the ECS instance> and press Enter.

      If a page similar to the following figure appears, the Apache service is running.

      Note

      The Apache service listens on port 80 by default. If you cannot access the Apache service, make sure that you have added a security group rule to allow inbound traffic on port 80 for the ECS instance. For more information, see Add a security group rule.

Step 2: Install MySQL

  1. Run the following command to install MySQL.

    wget 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 MySQL version number.

    mysql -V

    The following output indicates that MySQL is installed.

    20230206105737

  3. You can run the following command to start MySQL.

    systemctl start mysqld

    20230206105938

  4. Run the following command to set the MySQL service to start on boot.

    systemctl enable mysqld
    systemctl daemon-reload

Step 3: Install and configure PHP

  1. Run the following command to install PHP and its common extensions.

    yum -y install php php-fpm php-gd php-mysqlnd php-mbstring php-json php-pecl-zip
  2. Run the following command to check the PHP version.

    php-fpm -v

    20230206121008

  3. Run the following command to create a test file in the Apache website root directory.

    echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

    In this command, /var/www/html is the website root directory. You can find the path of the website root directory by checking the value of the DocumentRoot parameter in the /etc/httpd/conf/httpd.conf configuration file.

    20230206133149

  4. Run the following command to restart the Apache service.

    systemctl restart httpd
  5. In the address bar of your browser, enter http://<Public IP address of the instance>/phpinfo.php and press Enter.

    If the following page is displayed, the installation is successful.

  6. After you set up the LAMP environment, delete the phpinfo.php test file to prevent data breaches.

    rm -rf <website root directory>/phpinfo.php