Search Our Database

Install LAMP on CentOS 7

Last updated on |

Important Note: CentOS 7 reached End of Life (EOL) on June 30, 2024, and is no longer supported by Red Hat. This means CentOS 7 may be vulnerable to security risks and unpatched vulnerabilities. It is strongly recommended to consider upgrading to a supported operating system to ensure continued security and support.

If you still wish to use CentOS 7, you need to import the old repository by running the following commands to access archived packages:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/^#.baseurl=http/baseurl=http/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/CentOS-*.repo sed -i s/^#.baseurl=http/baseurl=http/g /etc/yum.repos.d/CentOS-*.repo sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/^#.baseurl=http/baseurl=http/g /etc/yum.repos.d/CentOS-*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-*.repo

 

Introduction

LAMP is a software stack consisting of Linux, Apache, MySQL (or MariaDB), and PHP, and is widely used for hosting websites and web applications. This combination of technologies allows the server to serve dynamic web content and interact with databases, making it essential for content management systems like WordPress and Joomla.

Here’s a breakdown of the LAMP stack components:

  • Linux: The operating system (e.g., Red Hat, CentOS, Rocky Linux).
  • Apache: The web server application.
  • MySQL/MariaDB: The relational database management system.
  • PHP: A server-side scripting language used for web development.

This guide walks through the steps of installing and configuring each of these components on CentOS 7.

 

Step 1: Install Apache

  1. Install Apache by running the following command:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    yum install httpd
    yum install httpd
    yum install httpd
  2. Start the Apache service:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    systemctl start httpd.service
    systemctl start httpd.service
    systemctl start httpd.service
  3. Disable the firewall for simplicity (not recommended in production environments):
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    systemctl stop firewalld.service
    systemctl stop firewalld.service
    systemctl stop firewalld.service
  4. Open your browser and enter your server’s IP address. If Apache is running, you should see the default Apache test page.
    lamp1
  5. Enable Apache to start at boot:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    systemctl enable httpd.service
    systemctl enable httpd.service
    systemctl enable httpd.service

     

Step 2: Install MariaDB

  • Install MariaDB (used in place of MySQL on CentOS 7):
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    yum install mariadb-server mariadb
    yum install mariadb-server mariadb
    yum install mariadb-server mariadb

     

  • Start and enable MariaDB at boot:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    systemctl start mariadb.service
    systemctl enable mariadb.service
    systemctl start mariadb.service systemctl enable mariadb.service
    systemctl start mariadb.service 
    systemctl enable mariadb.service

     

  • Secure MariaDB installation:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    mysql_secure_installation
    mysql_secure_installation
    mysql_secure_installation

Since we just installed MariaDB there shouldn’t be a root password, press enter then select if you want to add in a password for MariaDB root account. After that, simply enter “y” for the rest of the prompts.

lamp2

  • Access MariaDB as root:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    mysql -u root -p
    mysql -u root -p
    mysql -u root -p

    Enter the root password (if applicable) to proceed. Type exit to log out.

    lamp3

 

Step 3: Install PHP

  • Install PHP and its MySQL extension:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    yum install php php-mysql
    yum install php php-mysql
    yum install php php-mysql
  • Restart Apache to load PHP:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    systemctl restart httpd.service
    systemctl restart httpd.service
    systemctl restart httpd.service
  • Create a PHP info file to verify PHP installation:
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    vi /var/www/html/info.php
    vi /var/www/html/info.php
    vi /var/www/html/info.php

    Add the following:

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <?php
    phpinfo();
    ?>
    <?php phpinfo(); ?>
    <?php 
    phpinfo(); 
    ?>
  • Open your browser and navigate to  
    &lt;your-server-ip&gt;/info.php

     to confirm PHP installation.

lamp4

 

 

Conclusion

By following these steps, you have successfully installed the LAMP stack (Linux, Apache, MariaDB, PHP) on CentOS 7. This setup allows you to host dynamic websites and manage databases on your server. Given CentOS 7’s EOL status, consider migrating to a supported version for long-term security and stability.

Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.

 

Article posted on 14 April 2020 by Louis