cdn
http
koa
stencil
โ‰ˆ
+
js
+
+
pnpm
+
sqlite
+
+
gradle
strapi
//
===
+
+
+
+
+
+
+
+
+
+
+
hack
vscode
strapi
_
+
https
solid
+
+
+
cdn
git
โˆ‘
couchdb
+
+
+
+
stencil
<-
termux
svelte
+
mocha
go
cypress
+
+
mongo
+
+
+
+
ts
xcode
hack
vscode
ionic
+
fedora
+
+
jquery
+
deno
rider
laravel
!==
py
+
choo
+
chef
redis
โˆž
โˆˆ
notepad++
koa
pascal
+
Back to Blog
AlmaLinux LAMP Stack Apache

๐ŸŒ Building a Complete LAMP Stack on AlmaLinux: Your Gateway to Web Development Excellence

Published Aug 22, 2025

Master the art of setting up a complete LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) on AlmaLinux with this beginner-friendly guide. Learn installation, configuration, security, and optimization techniques!

5 min read
0 views
Table of Contents

๐ŸŒ Building a Complete LAMP Stack on AlmaLinux: Your Gateway to Web Development Excellence

Hey there, future web developer! ๐Ÿš€ Ready to set up your very own web development environment? You know that feeling when you want to build amazing websites but donโ€™t know where to start? Well, today weโ€™re going to build a complete LAMP stack on AlmaLinux - and trust me, itโ€™s going to be much easier than you think!

I remember when I first heard about LAMP stack - it sounded like something from a hardware store! ๐Ÿ˜„ But itโ€™s actually one of the most powerful and popular web development platforms in the world. By the end of this guide, youโ€™ll have your own professional web server running, ready to host your awesome projects!

๐Ÿค” Why is LAMP Stack Important?

Building a LAMP stack opens up incredible opportunities! ๐ŸŒŸ Let me share why this is such a game-changer:

The Power of LAMP:

  • ๐Ÿ—๏ธ Complete Development Environment - Everything you need in one place
  • ๐Ÿ’ฐ 100% Free and Open Source - No licensing fees, ever!
  • ๐ŸŒ Industry Standard - Powers millions of websites worldwide
  • ๐Ÿš€ Scalable Solution - From personal blogs to enterprise applications
  • ๐Ÿ“š Massive Community - Tons of resources and help available
  • ๐Ÿ”ง Highly Customizable - Tweak everything to your needs
  • ๐Ÿ›ก๏ธ Battle-Tested Security - Proven in production environments
  • ๐Ÿ’ก Learning Platform - Perfect for mastering web development

๐ŸŽฏ What You Need

Before we dive in, letโ€™s make sure youโ€™re ready! ๐ŸŽฏ Hereโ€™s your checklist:

Prerequisites:

  • โœ… AlmaLinux 8 or 9 installed and running
  • โœ… Root or sudo access (weโ€™ll need admin powers!)
  • โœ… Basic terminal knowledge (you can type commands)
  • โœ… Internet connection (for downloading packages)
  • โœ… About 30 minutes of your time
  • โœ… A cup of coffee โ˜• (optional but recommended!)
  • โœ… Excitement to learn something awesome! ๐ŸŽ‰

๐Ÿ“ Step 1: Preparing Your System

Letโ€™s start by getting your system ready! ๐ŸŽฏ This is like preparing your workspace before cooking a great meal.

Update Your System:

# First, update all existing packages - always start fresh!
sudo dnf update -y

# Check your AlmaLinux version
cat /etc/redhat-release
# Output: AlmaLinux release 9.x

# Clean up package cache to free space
sudo dnf clean all

# Check available disk space
df -h
# Make sure you have at least 2GB free

Set Up Firewall Rules:

# Enable firewall if not already active
sudo systemctl enable --now firewalld

# Check firewall status
sudo firewall-cmd --state
# Output: running

# Add HTTP service (port 80)
sudo firewall-cmd --permanent --add-service=http

# Add HTTPS service (port 443)
sudo firewall-cmd --permanent --add-service=https

# Add MySQL service (port 3306) - optional for remote access
sudo firewall-cmd --permanent --add-service=mysql

# Reload firewall to apply changes
sudo firewall-cmd --reload

# Verify services are added
sudo firewall-cmd --list-services
# Output: cockpit dhcpv6-client http https mysql ssh

๐Ÿ”ง Step 2: Installing Apache Web Server

Time to install Apache - the โ€˜Aโ€™ in LAMP! ๐ŸŒ Apache is like the foundation of your house.

Install and Configure Apache:

# Install Apache web server
sudo dnf install httpd -y

# Enable Apache to start automatically
sudo systemctl enable httpd

# Start Apache service
sudo systemctl start httpd

# Check Apache status
sudo systemctl status httpd
# Output: Active (running) - Great! ๐ŸŽ‰

# Get your server's IP address
ip addr show | grep inet
# Note your IP address (like 192.168.1.100)

Test Apache Installation:

# Create a test page
echo "<h1>๐ŸŽ‰ Apache is Working!</h1>" | sudo tee /var/www/html/test.html

# Set proper permissions
sudo chown apache:apache /var/www/html/test.html

# Test locally
curl http://localhost/test.html
# Output: <h1>๐ŸŽ‰ Apache is Working!</h1>

Now open your browser and visit: http://YOUR_SERVER_IP/test.html - You should see your message! ๐ŸŽŠ

๐ŸŒŸ Step 3: Installing MySQL/MariaDB Database

Letโ€™s install MariaDB (MySQLโ€™s cousin) - the โ€˜Mโ€™ in LAMP! ๐Ÿ’พ This is where all your data will live.

Install MariaDB:

# Install MariaDB server and client
sudo dnf install mariadb-server mariadb -y

# Enable MariaDB to start automatically
sudo systemctl enable mariadb

# Start MariaDB service
sudo systemctl start mariadb

# Check MariaDB status
sudo systemctl status mariadb
# Output: Active (running) - Perfect! ๐Ÿ’ช

Secure MariaDB Installation:

# Run security script
sudo mysql_secure_installation

# You'll see prompts - here's what to answer:
# Enter current password for root: [Press Enter - no password yet]
# Set root password? [Y/n]: Y
# New password: [Enter a strong password]
# Re-enter password: [Confirm password]
# Remove anonymous users? [Y/n]: Y
# Disallow root login remotely? [Y/n]: Y
# Remove test database? [Y/n]: Y
# Reload privilege tables? [Y/n]: Y

Test Database Connection:

# Connect to MariaDB
sudo mysql -u root -p
# Enter your root password

# Once connected, run these commands:
MariaDB [(none)]> SELECT VERSION();
# Shows MariaDB version

MariaDB [(none)]> SHOW DATABASES;
# Lists all databases

MariaDB [(none)]> CREATE DATABASE test_lamp;
# Creates a test database

MariaDB [(none)]> EXIT;
# Exit MariaDB

โœ… Step 4: Installing PHP

Time for PHP - the โ€˜Pโ€™ in LAMP! ๐Ÿ˜ This is what makes your websites dynamic and interactive.

Install PHP and Extensions:

# Install PHP and common extensions
sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring -y

# Install additional useful PHP extensions
sudo dnf install php-json php-zip php-curl php-intl -y

# Check PHP version
php -v
# Output: PHP 8.x.x - Awesome! ๐ŸŽฏ

# Restart Apache to load PHP
sudo systemctl restart httpd

Create PHP Info Page:

# Create a PHP info file
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

# Set proper ownership
sudo chown apache:apache /var/www/html/info.php

# Test PHP from command line
php -r "echo 'PHP is working! ๐ŸŽ‰';"
# Output: PHP is working! ๐ŸŽ‰

Visit http://YOUR_SERVER_IP/info.php in your browser - youโ€™ll see detailed PHP information! ๐Ÿ”

๐ŸŽฎ Quick Examples

Letโ€™s create some real-world examples to test your LAMP stack! ๐Ÿš€

Example 1: Simple Database Connection Test

# Create a database connection test
sudo tee /var/www/html/db-test.php << 'EOF'
<?php
$servername = "localhost";
$username = "root";
$password = "YOUR_PASSWORD"; // Replace with your password

try {
    $conn = new PDO("mysql:host=$servername", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "<h1>โœ… Database Connection Successful!</h1>";
    echo "<p>Your LAMP stack is working perfectly! ๐ŸŽ‰</p>";
} catch(PDOException $e) {
    echo "<h1>โŒ Connection failed</h1>";
    echo "<p>Error: " . $e->getMessage() . "</p>";
}
?>
EOF

# Set permissions
sudo chown apache:apache /var/www/html/db-test.php

Example 2: Create a Simple Contact Form

# Create a contact form
sudo tee /var/www/html/contact.php << 'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>Contact Form ๐Ÿ“ง</title>
    <style>
        body { font-family: Arial; max-width: 500px; margin: 50px auto; }
        input, textarea { width: 100%; padding: 10px; margin: 10px 0; }
        button { background: #4CAF50; color: white; padding: 10px 20px; border: none; cursor: pointer; }
    </style>
</head>
<body>
    <h1>๐Ÿ“ง Contact Us</h1>
    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $name = htmlspecialchars($_POST['name']);
        $email = htmlspecialchars($_POST['email']);
        $message = htmlspecialchars($_POST['message']);
        echo "<div style='background: #d4edda; padding: 15px; border-radius: 5px;'>";
        echo "<h2>โœ… Thank you, $name!</h2>";
        echo "<p>We received your message and will contact you at $email</p>";
        echo "</div>";
    }
    ?>
    <form method="post">
        <input type="text" name="name" placeholder="Your Name" required>
        <input type="email" name="email" placeholder="Your Email" required>
        <textarea name="message" placeholder="Your Message" rows="5" required></textarea>
        <button type="submit">Send Message ๐Ÿš€</button>
    </form>
</body>
</html>
EOF

# Set permissions
sudo chown apache:apache /var/www/html/contact.php

Example 3: Create a Simple Blog Database

# Connect to MariaDB and create blog structure
sudo mysql -u root -p << 'EOF'
CREATE DATABASE IF NOT EXISTS simple_blog;
USE simple_blog;

CREATE TABLE posts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    content TEXT,
    author VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO posts (title, content, author) VALUES
('Welcome to LAMP! ๐ŸŽ‰', 'Your LAMP stack is now ready for amazing projects!', 'Admin'),
('PHP is Awesome! ๐Ÿ˜', 'PHP powers millions of websites worldwide.', 'Developer'),
('Database Magic! ๐Ÿ’พ', 'MariaDB stores all your important data securely.', 'DBA');

SELECT * FROM posts;
EOF

๐Ÿšจ Fix Common Problems

Donโ€™t worry if something doesnโ€™t work right away! Here are solutions to common issues:

Problem 1: Apache Wonโ€™t Start

# Check for errors
sudo journalctl -xe | grep httpd

# Common fix: Check if port 80 is in use
sudo netstat -tulpn | grep :80

# If another service is using port 80, stop it
sudo systemctl stop nginx  # Example if nginx is running

# Fix permission issues
sudo semanage port -a -t http_port_t -p tcp 80  # SELinux fix

# Restart Apache
sudo systemctl restart httpd

Problem 2: PHP Not Working

# Check if PHP module is loaded
httpd -M | grep php

# If not loaded, install PHP module
sudo dnf reinstall php

# Check PHP configuration
php --ini

# Fix PHP-FPM if needed
sudo systemctl restart php-fpm

# Always restart Apache after PHP changes
sudo systemctl restart httpd

Problem 3: Canโ€™t Connect to Database

# Check if MariaDB is running
sudo systemctl status mariadb

# If not running, start it
sudo systemctl start mariadb

# Reset root password if forgotten
sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables &
mysql -u root
# Then in MySQL:
# UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
# FLUSH PRIVILEGES;
# EXIT;

# Kill the mysqld_safe process and restart normally
sudo pkill mysqld
sudo systemctl start mariadb

๐Ÿ“‹ Simple Commands Summary

Hereโ€™s your quick reference guide! ๐Ÿ“š Keep this handy:

TaskCommandWhat It Does
Start Apachesudo systemctl start httpdStarts web server ๐ŸŒ
Stop Apachesudo systemctl stop httpdStops web server ๐Ÿ›‘
Restart Apachesudo systemctl restart httpdRestarts web server ๐Ÿ”„
Apache Statussudo systemctl status httpdCheck if running โœ…
Start MariaDBsudo systemctl start mariadbStarts database ๐Ÿ’พ
Connect to DBmysql -u root -pAccess database ๐Ÿ”
PHP Versionphp -vShows PHP version ๐Ÿ˜
Test PHPphp -r "echo 'test';"Quick PHP test ๐Ÿงช
Apache Logssudo tail -f /var/log/httpd/error_logView errors ๐Ÿ“
PHP Configphp --iniPHP settings location ๐Ÿ”ง
List Databasesmysql -u root -p -e "SHOW DATABASES;"View all databases ๐Ÿ“Š
Apache Configsudo nano /etc/httpd/conf/httpd.confEdit Apache settings โš™๏ธ

๐Ÿ’ก Tips for Success

Here are my pro tips for managing your LAMP stack like a boss! ๐ŸŽฏ

Security Best Practices:

  • ๐Ÿ” Always use strong passwords - Mix letters, numbers, symbols
  • ๐Ÿ›ก๏ธ Keep everything updated - Run sudo dnf update weekly
  • ๐Ÿ”’ Disable root login - Use sudo for admin tasks
  • ๐Ÿ“ Monitor logs regularly - Check for unusual activity
  • ๐ŸŽฏ Use HTTPS - Install SSL certificates for production
  • ๐Ÿšซ Remove test files - Delete info.php after testing
  • ๐Ÿ”ง Configure SELinux - Donโ€™t disable it, learn it!
  • ๐Ÿ“Š Regular backups - Backup databases and files daily

Performance Optimization:

  • โšก Enable caching - Use PHP OPcache for speed
  • ๐Ÿš€ Optimize databases - Regular maintenance improves performance
  • ๐Ÿ“ˆ Monitor resources - Use htop to watch system load
  • ๐ŸŽฏ Tune Apache - Adjust MaxClients based on RAM
  • ๐Ÿ’พ Use indexes - Speed up database queries
  • ๐Ÿ”„ Enable compression - Reduce bandwidth usage

๐Ÿ† What You Learned

Congratulations! Look at everything youโ€™ve accomplished! ๐ŸŽŠ

Your Achievements:

  • โœ… Installed and configured Apache web server
  • โœ… Set up MariaDB database server
  • โœ… Installed PHP with essential extensions
  • โœ… Configured firewall for web services
  • โœ… Secured your database installation
  • โœ… Created test pages and forms
  • โœ… Tested database connectivity
  • โœ… Learned troubleshooting techniques
  • โœ… Built a complete development environment
  • โœ… Mastered LAMP stack basics!

๐ŸŽฏ Why This Matters

Your new LAMP stack isnโ€™t just a bunch of software - itโ€™s your gateway to unlimited possibilities! ๐Ÿš€

With this setup, you can now:

  • ๐ŸŒ Build dynamic websites - From blogs to e-commerce
  • ๐Ÿ’ผ Develop web applications - Create the next big thing
  • ๐Ÿ“š Learn web development - Practice with real tools
  • ๐Ÿข Host client projects - Start your web dev business
  • ๐Ÿ”ง Experiment freely - Try new frameworks and CMSs
  • ๐ŸŽฏ Deploy WordPress - Or any PHP application
  • ๐Ÿ’ก Create APIs - Build backend services
  • ๐Ÿš€ Scale your skills - From hobby to professional

Remember when we started and LAMP seemed complicated? Look at you now - youโ€™ve built a complete web development stack from scratch! Thatโ€™s absolutely incredible! ๐ŸŒŸ

Keep exploring, keep building, and most importantly, have fun with your new LAMP stack! The web development world is now your playground! ๐ŸŽฎ

Happy coding, and welcome to the amazing world of LAMP development! ๐Ÿ™Œ


P.S. - Donโ€™t forget to bookmark this guide for future reference. Youโ€™ve got this! โญ