tencent cloud

Feedback

Manual Setup of LAMP

Last updated: 2024-01-06 17:43:10

    Scenario

    LAMP is a common web service architecture run on Linux and consisting of Apache, MySQL/MariaDB, and PHP. This article describes how to set up LAMP on a Linux CVM.
    You should be familiar with common Linux commands, such as Installing Software via YUM in a CentOS Environment, and understand the versions of the installed software.

    Software

    These are the software involved:
    CentOS is a distribution of the Linux operating system. We will use version 7.6 in this article.
    Apache is a web server software. We will use version 2.4.6 in this article.
    MariaDB is a database management system. We will use version 10.4.8 in this article.
    PHP is a scripting language. We will use version 7.0.33 in this article.

    Prerequisites

    You need a Linux CVM. If you have not purchased one yet, see Getting Started with Linux CVMs.

    Instructions

    Step 1: Logging in to a Linux instance

    Log in to a Linux instance using WebShell (recommended). You can also use other login methods that you are comfortable with:

    Step 2: Installing Apache

    1. Run the following command to install Apache.
    yum install httpd -y
    2. Run the following commands to start Apache and set it to start automatically when the system starts.
    systemctl start httpd
    systemctl enable httpd
    3. Open a browser window and visit the following URL to verify that Apache is working properly.
    http://[Public IP address of the CVM instance]
    The following appears if Apache is installed properly:
    
    

    Step 3: Installing MariaDB

    1. Run the following command to check if MariaDB is already installed.
    rpm -qa | grep -i mariadb
    If the following appears, MariaDB is already installed.
    
    If that’s the case, run the following to remove MariaDB to avoid conflicts between different versions.
    yum -y remove [Package name]
    If nothing is returned, MariaDB is not installed. In this case, proceed to the next step.
    2. Run the following command to create a file named MariaDB.repo under /etc/yum.repos.d/.
    vi /etc/yum.repos.d/MariaDB.repo
    3. Press i to switch to edit mode and input the following.
    # MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.4/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    Note:
    For installation information for other versions, visit the MariaDB official website.
    4. Press Esc and input :wq to save the file and go back.
    5. Run the following command to install MariaDB.
    yum -y install MariaDB-client MariaDB-server
    6. Run the following commands to start MariaDB and set it to start automatically when the system starts.
    systemctl start mariadb
    systemctl enable mariadb
    7. Run the following command to verify that MariaDB is successfully installed.
    mysql
    If the following appears, MariaDB is successfully installed.
    
    
    8. Run the following command to exit MariaDB.
    \\q

    Step 4: Installing and configuring PHP

    1. Run the following commands to update the software source of PHP in Yum.
    rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    2. Run the following command to install the packages required for PHP 7.0.33.
    yum -y install php70w php70w-opcache php70w-mbstring php70w-gd php70w-xml php70w-pear php70w-fpm php70w-mysql php70w-pdo
    3. Run the following command to edit the Apache configuration file.
    vi /etc/httpd/conf/httpd.conf
    4. Press i to enter edit mode and make the following changes:
    
    
    
    
    
    
    
    
    4.1 Find ServerName www.example.com:80 and start a new line below it. Input the following:
    ServerName localhost:80
    4.2 Find Require all denied in <Directory> and change it to Require all granted.
    4.3 Find <IfModule dir_module> and change the content to DirectoryIndex index.php index.html.
    4.4 Start a new line below AddType application/x-gzip .gz .tgz and input the following:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    5. Press Esc and input :wq to save the file and go back.
    6. Run the following command to restart Apache.
    systemctl restart httpd

    Verifying the Environment Configuration

    1. Run the following command to create a test file.
    echo "<?php phpinfo(); ?>" >> /var/www/html/index.php
    2. Open a browser window on your local machine and visit the following URL to check whether the environment configuration is successful.
    http://CVM Public IP/index.php
    If the following appears, the LAMP environment is configured successfully.
    
    

    Relevant Operations

    After the LAMP environment is built, you can manually set up Drupal website.

    FAQ

    If you encounter a problem when using CVM, refer to the following documents for troubleshooting based on your actual situation.
    For issues regarding CVM login, see Password Login and SSH Key Login and Login and Remote Access.
    For issues regarding the CVM network, see IP Addresses and Ports and Security Groups.
    For issues regarding CVM disks, see System and Data Disks.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support