+
webstorm
micronaut
+
pascal
+
redis
+
prometheus
stimulus
+
oauth
+
+
gatsby
+
+
node
+
+
cassandra
nim
+
+
cargo
+
+
remix
lit
==
โˆ‘
+
+
โŠ‚
+
prometheus
atom
+
haskell
~
adonis
+
+
+
ionic
gitlab
haskell
cassandra
+
+
junit
redis
+
junit
goland
+
+
===
tf
sinatra
+
+
+
sinatra
+=
fedora
+
+
fiber
โˆ‚
css
|>
lisp
rest
+
+
+
+
+
prometheus
+
+
0b
+
+
wsl
+
windows
+
Back to Blog
๐ŸŒ LAMP Stack Setup (Apache, MySQL, PHP) on AlmaLinux
lamp apache mysql

๐ŸŒ LAMP Stack Setup (Apache, MySQL, PHP) on AlmaLinux

Published Sep 14, 2025

Master LAMP stack installation on AlmaLinux! Complete guide to setup Apache, MySQL, and PHP for web development. Perfect for developers building dynamic websites and web applications.

19 min read
0 views
Table of Contents

๐ŸŒ LAMP Stack Setup (Apache, MySQL, PHP) on AlmaLinux

Ready to build powerful web applications? ๐Ÿš€ The LAMP stack (Linux, Apache, MySQL, PHP) is the classic foundation that powers millions of websites worldwide! In this comprehensive guide, weโ€™ll install and configure a complete LAMP stack on AlmaLinux. From simple websites to complex web applications, youโ€™ll have everything you need! โœจ

๐Ÿค” Why is LAMP Stack Important?

LAMP is the legendary web development stack that changed the internet! ๐ŸŒ Hereโ€™s why developers and businesses love it:

  • ๐Ÿ† Proven Technology: Powers WordPress, Facebook, Wikipedia, and millions more
  • ๐Ÿ’ฐ Cost Effective: All components are free and open-source
  • ๐Ÿš€ High Performance: Optimized for speed and reliability
  • ๐Ÿ”ง Easy Development: Simple to learn and quick to deploy
  • ๐Ÿ“š Huge Community: Millions of developers, endless resources
  • ๐Ÿ›ก๏ธ Enterprise Ready: Scales from small blogs to massive applications
  • ๐Ÿ”„ Flexible: Mix and match components based on your needs
  • ๐ŸŒŸ Career Boost: LAMP skills are always in demand

Think of LAMP as the Swiss Army knife of web development - versatile, reliable, and essential! ๐Ÿ› ๏ธ

๐ŸŽฏ What You Need

Letโ€™s make sure youโ€™re ready for LAMP stack mastery! โœ…

  • โœ… AlmaLinux 8 or 9 server with internet connection
  • โœ… At least 2GB RAM (4GB recommended for development)
  • โœ… 10GB free disk space for applications and databases
  • โœ… sudo privileges on your system
  • โœ… Basic understanding of Linux command line
  • โœ… Text editor skills (weโ€™ll use nano and vim)
  • โœ… Web browser for testing your applications
  • โœ… 25 minutes of focused time and enthusiasm! ๐ŸŽ‰

Donโ€™t worry if youโ€™re new to web development - weโ€™ll guide you step by step! ๐ŸŒŸ

๐Ÿ“ Step 1: Update Your System

First, letโ€™s prepare your AlmaLinux system for the LAMP stack! ๐ŸŽฏ

# Update all system packages
sudo dnf update -y

# Install essential development tools
sudo dnf groupinstall -y "Development Tools"

# Install useful utilities
sudo dnf install -y wget curl vim nano htop

Perfect! ๐ŸŽ‰ Your system is now ready for LAMP installation.

๐Ÿ”ง Step 2: Install Apache Web Server

Apache is the โ€œAโ€ in LAMP - letโ€™s install the worldโ€™s most popular web server! ๐ŸŒ

# Install Apache HTTP Server
sudo dnf install -y httpd

# Start Apache service
sudo systemctl start httpd

# Enable Apache to start automatically on boot
sudo systemctl enable httpd

# Check Apache status
sudo systemctl status httpd

Expected Output:

โ— httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Mon 2025-09-14 10:00:00 UTC

Configure Firewall for Apache

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

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

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

# Verify firewall rules
sudo firewall-cmd --list-services

Test Apache Installation

# Test Apache locally
curl http://localhost

# Check from web browser
echo "๐ŸŒ Open your browser and visit: http://your-server-ip"
echo "You should see the Apache welcome page!"

Excellent! ๐Ÿš€ Apache is running and serving web pages!

๐ŸŒŸ Step 3: Install MySQL Database Server

MySQL is the โ€œMโ€ in LAMP - letโ€™s install the powerful database system! ๐Ÿ—„๏ธ

# Install MySQL server
sudo dnf install -y mysql-server

# Start MySQL service
sudo systemctl start mysqld

# Enable MySQL to start automatically on boot
sudo systemctl enable mysqld

# Check MySQL status
sudo systemctl status mysqld

Secure MySQL Installation

# Run MySQL security script
sudo mysql_secure_installation

# Follow these prompts:
# - Set root password: YES (choose a strong password)
# - Remove anonymous users: YES
# - Disallow root login remotely: YES
# - Remove test database: YES
# - Reload privilege tables: YES

Test MySQL Connection

# Connect to MySQL as root
sudo mysql -u root -p

# Inside MySQL prompt, run these commands:
# SHOW DATABASES;
# CREATE DATABASE testdb;
# SHOW DATABASES;
# EXIT;

Expected Output:

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+

Amazing! ๐ŸŽฏ MySQL is running and ready for your applications!

โœ… Step 4: Install PHP

PHP is the โ€œPโ€ in LAMP - letโ€™s install the dynamic scripting language! ๐Ÿ˜

# Install PHP and essential modules
sudo dnf install -y php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-json php-curl

# Install additional useful PHP modules
sudo dnf install -y php-zip php-intl php-ldap php-soap

# Check PHP version
php -v

# Start PHP-FPM service
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Expected Output:

PHP 8.0.30 (cli) (built: Aug  3 2023 18:02:36) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies

Configure Apache for PHP

# Restart Apache to load PHP module
sudo systemctl restart httpd

# Create a PHP info test file
sudo bash -c 'cat > /var/www/html/info.php << EOF
<?php
phpinfo();
?>
EOF'

# Test PHP installation
curl http://localhost/info.php | grep "PHP Version"

# Or visit in browser: http://your-server-ip/info.php

Perfect! โœ… PHP is integrated with Apache and working!

๐Ÿ”ง Step 5: Configure LAMP Stack

Letโ€™s optimize our LAMP stack configuration for better performance! โšก

Apache Configuration

# Edit Apache main configuration
sudo nano /etc/httpd/conf/httpd.conf

# Key settings to verify/adjust:
# ServerName your-domain.com:80
# DirectoryIndex index.html index.php
# AllowOverride All (for .htaccess support)

# Create custom Apache configuration
sudo bash -c 'cat > /etc/httpd/conf.d/lamp.conf << EOF
# Custom LAMP Configuration
<Directory /var/www/html>
    AllowOverride All
    Require all granted
</Directory>

# Security headers
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"
EOF'

PHP Configuration

# Backup original PHP configuration
sudo cp /etc/php.ini /etc/php.ini.backup

# Edit PHP configuration for better performance
sudo nano /etc/php.ini

# Key settings to adjust (search for these directives):
# memory_limit = 256M
# upload_max_filesize = 64M
# post_max_size = 64M
# max_execution_time = 300
# max_input_vars = 3000
# date.timezone = America/New_York (set your timezone)

MySQL Configuration

# Edit MySQL configuration for better performance
sudo nano /etc/my.cnf.d/mysql-server.cnf

# Add these settings under [mysqld] section:
# innodb_buffer_pool_size = 1G
# max_connections = 200
# query_cache_type = 1
# query_cache_size = 64M

Restart All Services

# Restart all LAMP services to apply configurations
sudo systemctl restart httpd
sudo systemctl restart mysqld
sudo systemctl restart php-fpm

# Verify all services are running
sudo systemctl status httpd mysqld php-fpm

Fantastic! ๐ŸŽ‰ Your LAMP stack is optimized and ready!

๐ŸŒŸ Step 6: Create Your First Web Application

Letโ€™s build a real web application to test our LAMP stack! ๐ŸŽฎ

Create Database and User

# Connect to MySQL
sudo mysql -u root -p

# Create database and user for our application
# Inside MySQL prompt:
CREATE DATABASE webapp;
CREATE USER 'webuser'@'localhost' IDENTIFIED BY 'webpass123';
GRANT ALL PRIVILEGES ON webapp.* TO 'webuser'@'localhost';
FLUSH PRIVILEGES;

USE webapp;
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) NOT NULL UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (name, email) VALUES 
('John Doe', '[email protected]'),
('Jane Smith', '[email protected]'),
('Bob Wilson', '[email protected]');

EXIT;

Create PHP Application

# Create application directory
sudo mkdir -p /var/www/html/myapp

# Create database connection file
sudo bash -c 'cat > /var/www/html/myapp/config.php << EOF
<?php
$servername = "localhost";
$username = "webuser";
$password = "webpass123";
$dbname = "webapp";

try {
    $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}
?>
EOF'

# Create main application file
sudo bash -c 'cat > /var/www/html/myapp/index.php << EOF
<?php
require_once "config.php";

// Handle form submission
if ($_POST["action"] == "add" && !empty($_POST["name"]) && !empty($_POST["email"])) {
    $stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
    $stmt->execute([$_POST["name"], $_POST["email"]]);
    $message = "User added successfully!";
}

// Fetch all users
$stmt = $pdo->query("SELECT * FROM users ORDER BY created_at DESC");
$users = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
    <title>๐Ÿš€ My LAMP Application</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
        table { width: 100%; border-collapse: collapse; margin: 20px 0; }
        th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
        th { background-color: #f2f2f2; }
        .form-group { margin: 10px 0; }
        input[type="text"], input[type="email"] { width: 200px; padding: 5px; }
        button { background: #007cba; color: white; padding: 10px 20px; border: none; cursor: pointer; }
        .success { color: green; font-weight: bold; }
    </style>
</head>
<body>
    <h1>๐ŸŒ LAMP Stack Application</h1>
    <p>Welcome to your first LAMP application running on AlmaLinux!</p>
    
    <?php if (isset($message)): ?>
        <div class="success"><?= $message ?></div>
    <?php endif; ?>
    
    <h2>๐Ÿ“ Add New User</h2>
    <form method="post">
        <div class="form-group">
            <label>Name:</label><br>
            <input type="text" name="name" required>
        </div>
        <div class="form-group">
            <label>Email:</label><br>
            <input type="email" name="email" required>
        </div>
        <button type="submit" name="action" value="add">Add User</button>
    </form>
    
    <h2>๐Ÿ‘ฅ Users List</h2>
    <table>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Created At</th>
        </tr>
        <?php foreach ($users as $user): ?>
        <tr>
            <td><?= $user["id"] ?></td>
            <td><?= htmlspecialchars($user["name"]) ?></td>
            <td><?= htmlspecialchars($user["email"]) ?></td>
            <td><?= $user["created_at"] ?></td>
        </tr>
        <?php endforeach; ?>
    </table>
    
    <h2>๐Ÿ“Š System Information</h2>
    <p><strong>Server:</strong> <?= $_SERVER["SERVER_SOFTWARE"] ?></p>
    <p><strong>PHP Version:</strong> <?= PHP_VERSION ?></p>
    <p><strong>Database:</strong> MySQL Connected โœ…</p>
    <p><strong>Document Root:</strong> <?= $_SERVER["DOCUMENT_ROOT"] ?></p>
</body>
</html>
EOF'

# Set proper permissions
sudo chown -R apache:apache /var/www/html/myapp
sudo chmod -R 755 /var/www/html/myapp

# Test the application
echo "๐ŸŽ‰ Visit your application at: http://your-server-ip/myapp"

Incredible! ๐Ÿš€ Youโ€™ve built a complete web application with LAMP!

๐ŸŽฎ Quick Examples

Letโ€™s create more practical LAMP applications! ๐ŸŽฏ

Example 1: Simple Blog System

# Create blog directory
sudo mkdir -p /var/www/html/blog

# Create blog database
sudo mysql -u root -p << 'EOF'
CREATE DATABASE blog;
USE blog;
CREATE TABLE posts (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(200) NOT NULL,
    content TEXT NOT NULL,
    author VARCHAR(100) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO posts (title, content, author) VALUES 
('Welcome to My Blog', 'This is my first blog post using LAMP stack!', 'Admin'),
('LAMP is Awesome', 'Building web applications has never been easier.', 'Developer');
EXIT;
EOF

# Create simple blog application
sudo bash -c 'cat > /var/www/html/blog/index.php << EOF
<?php
$pdo = new PDO("mysql:host=localhost;dbname=blog", "webuser", "webpass123");
$posts = $pdo->query("SELECT * FROM posts ORDER BY created_at DESC")->fetchAll();
?>
<!DOCTYPE html>
<html>
<head><title>๐Ÿ“ My LAMP Blog</title></head>
<body style="font-family: Arial; max-width: 800px; margin: 0 auto; padding: 20px;">
    <h1>๐Ÿ“ My LAMP Blog</h1>
    <?php foreach ($posts as $post): ?>
        <article style="border-bottom: 1px solid #ccc; margin: 20px 0; padding: 20px 0;">
            <h2><?= htmlspecialchars($post["title"]) ?></h2>
            <p><em>By <?= htmlspecialchars($post["author"]) ?> on <?= $post["created_at"] ?></em></p>
            <p><?= htmlspecialchars($post["content"]) ?></p>
        </article>
    <?php endforeach; ?>
</body>
</html>
EOF'

Example 2: REST API with PHP

# Create API directory
sudo mkdir -p /var/www/html/api

# Create simple REST API
sudo bash -c 'cat > /var/www/html/api/users.php << EOF
<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");

$pdo = new PDO("mysql:host=localhost;dbname=webapp", "webuser", "webpass123");

$method = $_SERVER["REQUEST_METHOD"];
$path = explode("/", trim($_SERVER["PATH_INFO"], "/"));

switch ($method) {
    case "GET":
        $stmt = $pdo->query("SELECT * FROM users");
        echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
        break;
        
    case "POST":
        $data = json_decode(file_get_contents("php://input"), true);
        $stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
        $stmt->execute([$data["name"], $data["email"]]);
        echo json_encode(["status" => "success", "id" => $pdo->lastInsertId()]);
        break;
        
    default:
        http_response_code(405);
        echo json_encode(["error" => "Method not allowed"]);
}
?>
EOF'

# Test the API
curl -X GET http://localhost/api/users.php

Example 3: File Upload System

# Create upload directory
sudo mkdir -p /var/www/html/upload
sudo mkdir -p /var/www/html/upload/files
sudo chown -R apache:apache /var/www/html/upload

# Create upload application
sudo bash -c 'cat > /var/www/html/upload/index.php << EOF
<?php
$message = "";
if ($_POST["action"] == "upload" && !empty($_FILES["file"]["name"])) {
    $target_dir = "files/";
    $target_file = $target_dir . basename($_FILES["file"]["name"]);
    
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
        $message = "File uploaded successfully!";
    } else {
        $message = "Upload failed!";
    }
}

$files = glob("files/*");
?>
<!DOCTYPE html>
<html>
<head><title>๐Ÿ“ File Upload System</title></head>
<body style="font-family: Arial; max-width: 600px; margin: 0 auto; padding: 20px;">
    <h1>๐Ÿ“ File Upload System</h1>
    
    <?php if ($message): ?>
        <p style="color: green; font-weight: bold;"><?= $message ?></p>
    <?php endif; ?>
    
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="file" required>
        <button type="submit" name="action" value="upload">Upload File</button>
    </form>
    
    <h2>๐Ÿ“‹ Uploaded Files</h2>
    <ul>
        <?php foreach ($files as $file): ?>
            <li><a href="<?= $file ?>"><?= basename($file) ?></a></li>
        <?php endforeach; ?>
    </ul>
</body>
</html>
EOF'

๐Ÿšจ Fix Common Problems

LAMP stack issues? Letโ€™s troubleshoot together! ๐Ÿ”ง

Problem 1: Apache Wonโ€™t Start

Symptoms: httpd service fails to start

Solution:

# Check Apache configuration syntax
sudo httpd -t

# Check for port conflicts
sudo netstat -tlnp | grep :80

# View detailed error logs
sudo tail -f /var/log/httpd/error_log

# Fix common issues
sudo setsebool -P httpd_can_network_connect 1
sudo systemctl restart httpd

Problem 2: PHP Not Working

Symptoms: PHP files download instead of executing

Solution:

# Verify PHP module is loaded
sudo httpd -M | grep php

# Check PHP-FPM status
sudo systemctl status php-fpm

# Reinstall PHP integration
sudo dnf reinstall php php-fpm

# Restart services
sudo systemctl restart httpd php-fpm

Problem 3: MySQL Connection Errors

Symptoms: โ€œAccess deniedโ€ or โ€œCanโ€™t connect to MySQLโ€

Solution:

# Reset MySQL root password
sudo systemctl stop mysqld
sudo mysqld_safe --skip-grant-tables &
mysql -u root

# In MySQL prompt:
# UPDATE mysql.user SET authentication_string = PASSWORD('newpassword') WHERE User = 'root';
# FLUSH PRIVILEGES;
# EXIT;

sudo systemctl restart mysqld

Problem 4: Permission Denied Errors

Symptoms: 403 Forbidden or file permission errors

Solution:

# Fix web directory permissions
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html

# Fix SELinux contexts
sudo setsebool -P httpd_can_network_connect 1
sudo restorecon -R /var/www/html

# Check SELinux status
sudo getenforce

๐Ÿ“‹ Simple Commands Summary

Your LAMP stack command cheat sheet! ๐Ÿ“š

TaskCommandPurpose
Restart Apachesudo systemctl restart httpdReload Apache configuration
Check Apache Statussudo systemctl status httpdView Apache service status
Apache Error Logssudo tail -f /var/log/httpd/error_logMonitor Apache errors
Test PHPphp -vCheck PHP version
MySQL Loginmysql -u root -pConnect to MySQL database
Check Servicessudo systemctl status httpd mysqld php-fpmView all LAMP services
Reload PHP Configsudo systemctl restart php-fpmApply PHP changes
Test Apache Configsudo httpd -tValidate Apache configuration
Check Portssudo netstat -tlnp | grep :80View port usage
Fix Permissionssudo chown -R apache:apache /var/www/htmlFix web directory ownership

๐Ÿ’ก Tips for Success

Master LAMP development with these expert tips! ๐ŸŒŸ

  • ๐Ÿ”’ Security First: Always validate user input and use prepared statements
  • ๐Ÿ“ Version Control: Use Git to track your web application changes
  • ๐Ÿงช Test Locally: Develop on local LAMP stack before deploying
  • ๐Ÿ“Š Monitor Performance: Use tools like htop and MySQL slow query log
  • ๐Ÿ”„ Regular Backups: Backup databases and web files frequently
  • ๐Ÿ“š Documentation: Comment your PHP code and document database schema
  • ๐Ÿš€ Optimize Images: Compress images for faster page loading
  • ๐Ÿ”ง Use Frameworks: Consider Laravel, CodeIgniter, or Symfony for complex apps
  • ๐Ÿ“ฑ Mobile Responsive: Make your applications mobile-friendly
  • ๐ŸŒ SSL Certificates: Implement HTTPS for production websites

๐Ÿ† What You Learned

Look at your amazing LAMP stack achievements! ๐ŸŽ‰

  • โœ… Installed complete LAMP stack with Apache, MySQL, and PHP
  • โœ… Configured all services for optimal performance and security
  • โœ… Built real web applications with database integration
  • โœ… Created REST APIs for modern web development
  • โœ… Implemented file uploads and user management systems
  • โœ… Mastered troubleshooting techniques for common LAMP issues
  • โœ… Learned security best practices for web applications
  • โœ… Gained database skills with MySQL operations
  • โœ… Built responsive web interfaces with HTML, CSS, and PHP
  • โœ… Acquired full-stack skills that power millions of websites

Youโ€™re now a LAMP stack web developer! ๐ŸŒŸ

๐ŸŽฏ Why This Matters

Your LAMP skills unlock incredible opportunities! ๐Ÿš€

For Your Career:

  • ๐Ÿ’ผ Web developers with LAMP skills earn $60-80k+ annually
  • ๐ŸŽฏ LAMP powers 40% of all websites - massive job market
  • ๐ŸŒŸ Foundation for learning modern frameworks like Laravel
  • ๐Ÿค Essential for freelance web development projects

For Your Projects:

  • ๐ŸŒ Build anything from blogs to e-commerce platforms
  • โšก Rapid prototyping and deployment capabilities
  • ๐Ÿ’ฐ Cost-effective hosting on any Linux server
  • ๐Ÿ“ˆ Scale from hobby projects to enterprise applications

For Your Business:

  • ๐Ÿ›’ Create custom business applications and websites
  • ๐Ÿ’ก Prototype ideas quickly and cost-effectively
  • ๐ŸŽฏ Full control over your web infrastructure
  • ๐Ÿ”ง Customize solutions to exact business requirements

Real-World Impact:

  • ๐ŸŒ WordPress (LAMP-based) powers 40% of all websites
  • ๐Ÿ›’ Many e-commerce platforms built on LAMP architecture
  • ๐Ÿ“ฐ News sites and blogs rely on LAMP for content management
  • ๐Ÿข Enterprise applications often use LAMP for internal tools

Youโ€™ve just learned the stack that literally built the modern web! ๐Ÿ†

Remember, LAMP isnโ€™t just about technology - itโ€™s about empowerment. You now have the power to turn any idea into a working web application. From simple personal websites to complex business systems, you have the foundation to build anything you can imagine! โญ

Happy coding! ๐Ÿ™Œ