How to Build a LAMP Stack on CentOS 7: Step-by-Step Guide

This tutorial walks you through installing CentOS 7, configuring the firewall and SELinux, and setting up Apache, MariaDB, and PHP to create a functional LAMP environment, complete with testing and essential configuration tips.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a LAMP Stack on CentOS 7: Step-by-Step Guide

Preparation

Install CentOS 7.2 in VMware (installation steps omitted).

1. Configure firewall

CentOS 7.2 uses firewalld by default; switch to iptables.

1.1 Disable firewalld

1.2 Install iptables

Open ports 80 and 3306. Add the rules below the default SSH (22) rule to avoid firewall startup failure.

2. Disable SELinux

3. Install Apache

After installation, opening the CentOS server IP in a browser shows the Apache default page, confirming success.

4. Install MariaDB

Install MariaDB and set the root password.

2.2 Set root password

Press Enter, then confirm with Y.

Enter the password twice and press Enter.

When prompted [Y/n] type Y.

Continue until the message “Thanks for using MySQL!” appears.

Restart MySQL.

5. Install PHP

Install PHP and the necessary extensions to enable MariaDB support.

Install PHP components for MariaDB support.

6. Configuration

Apache configuration

PHP configuration

7. Test

Open the server IP in a client browser; the classic “hello world!” page appears.

Note: Apache’s default document root is /var/www/html. Set appropriate permissions, e.g., chown apache.apache -R /var/www/html.

The author is a beginner and welcomes feedback.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

firewallPHPApacheCentOSMariaDBLAMP
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.