All Products
Search
Document Center

Simple Application Server:Build a LAMP development environment

Last Updated:Mar 14, 2024

LAMP is a popular environment for building web applications. LAMP is an acronym made up of the names of its four base components: the Linux operating system, Apache HTTP Server, MySQL relational database management system, and PHP programming language. This topic describes how to use a LAMP application image provided by Simple Application Server to build a development environment.

Background information

In the examples, the LAMP 7.4 application image is used to create a simple application server. The image contains the following operating system and software versions:

  • Operating system: CentOS 7.9

  • Apache: Apache 2.4

  • MySQL: MySQL 5.7

  • PHP: PHP 7.4

Step 1: Create a simple application server

  1. Log on to the Simple Application Server console.

  2. In the left-side navigation pane, click Servers.

  3. In the upper-left corner of the page, click Create Server.

  4. Click Create Server in the upper-right corner of the Servers page. On the buy page of simple application servers, configure parameters to create a simple application server.

    For more information about how to create a simple application server, see Build a WordPress blog.

    In the Image section, select the LAMP 7.4 application image on the Apps Image tab.

Step 2: View application information

  1. Click the card of the LAMP server.

  2. Click the Application Details tab.

  3. View the usernames and passwords of the software preset in the LAMP application image.

    1. In the LAMP Information section, click Connect.

    2. In the command line window that appears, run the following command to view application information:

      sudo cat /credentials/password.txt

      The application information is slightly different based on the tag of the LAMP application image. The LAMP 7.4 application image is used in this example. You can find the administrator password of the database that is preset in the image.

      [admin@iZj6cfztoffl5xdjtax**** ~]$ sudo cat /credentials/password.txt
      mysql administrator username:root
      mysql administrator password:w1gnxHCyKKB****
      
      ---
    3. Select and right-click the application information. Select Copy to copy the information and paste it to your on-premises computer to facilitate subsequent website deployment.

      Keep the password confidential.

  4. (Optional) View the PHP configuration details.

    If you want to use the phpinfo function to view the PHP configuration details or check whether the server is running as expected, perform this step.

    Note

    By default, LAMP images do not contain the phpinfo.php file. Before you can view the PHP configuration details, you must perform the following steps to create the phpinfo.php file and add the phpinfo function to the file:

    1. Run the following command to create the phpinfo.php file in the website root directory. This file is used to store the code of the phpinfo function.

      • LAMP 7.4:

        sudo vim /data/wwwroot/example/phpinfo.php
      • LAMP 6.1.0:

        su root
        sudo vim /home/www/htdocs/phpinfo.php
    2. Press the I key to enter the edit mode. Add the following code to the file:

      <?php
      phpinfo();
      ?>
    3. Press the Esc key, enter :wq, and then press the Enter key to save and close the file.

    4. Enter http://Public IP address of the simple application server/phpinfo.php in the browser on your on-premises computer.

      If a domain name is bound to the simple application server, you can enter Domain name/phpinfo.php in the browser.

      In this example, http://Public IP address of the simple application server/phpinfo.php is used to view the PHP configuration details. If information similar to the following figure is displayed, the LAMP server runs as expected. adada

Step 3: Test access to a website

Before you perform test access to a website, you need to upload the web project file that you want to deploy to the website root directory on the LAMP server, and change the owner of the web project file. In this example, FileZilla is used to upload the test.html file that is only for test purposes to the website root directory on the LAMP 7.4 server. The file contains the following content:

<html>
<head>
<meta charset="utf-8">
<title>Test Environment</title>
</head>

<body>
Test123456789
</body>

</html>

Perform the following operations:

  1. Upload the website code stored on your on-premises computer to the website root directory on the LAMP server.

    1. Add a firewall rule on the LAMP server to allow traffic on port 21 and ports in the range of 20000 to 30000.

      Port 21 is the default FTP port. Ports in the range of 20000 to 30000 may be used by FTP in passive mode on the LAMP server. For more information about how to add a firewall rule, see Manage a firewall.

    2. Use the stored FTP username and password to connect to the LAMP server. Then, use FileZilla to upload the test.html file to the /data/wwwroot/example directory of the LAMP server.

      For more information, see Build an FTP server (Linux).

  2. In the command line window of remote connection, run the following command to change the owner of the test file.

    In this example, the LAMP 7.4 server is connected. The website root directory is /data/wwwroot/example. The test file is named test.html. Run the following command to change the owner of the file:

    sudo chmod 777 -R /data/wwwroot/example
    sudo chown -R apache:apache /data/wwwroot/example/test.html
  3. Enter http://Public IP address of the simple application server/test.html in the browser on your on-premises computer.

    If a domain name is bound to the server, you can enter <Domain name>/test.html in the browser.

    A page similar to the following figure indicates that the website is accessed. 网站测试