webstorm
+
+
+
pandas
+
+
+
+
+
+
+
+
xgboost
+
graphdb
actix
goland
laravel
spacy
+
c#
quarkus
netlify
neo4j
+
+
stencil
+
py
+
+
+
+
+
+
+
torch
aurelia
+
html
swc
+
+
+
+
+
redhat
+
webpack
rb
json
+
gatsby
+
+
+
scipy
xcode
express
htmx
+
+
graphdb
node
xgboost
sklearn
phoenix
+
+
vue
+
+
aurelia
echo
+
termux
+
mvn
+
wasm
+
โˆ‘
+
+
vb
vite
+
+
Back to Blog
๐Ÿ˜ PHP Installation and Configuration on AlmaLinux: Complete Development Setup
PHP Installation Web Development AlmaLinux PHP

๐Ÿ˜ PHP Installation and Configuration on AlmaLinux: Complete Development Setup

Published Sep 14, 2025

Install and configure PHP 8+ on AlmaLinux with this comprehensive step-by-step guide. Learn Apache/Nginx integration, Composer setup, database connectivity, and performance optimization for web development.

17 min read
0 views
Table of Contents

๐Ÿ˜ PHP Installation and Configuration on AlmaLinux: Complete Development Setup

Ready to power your web applications with the worldโ€™s most popular server-side language? ๐Ÿš€ Today weโ€™ll install and configure PHP 8+ on AlmaLinux - powering over 75% of all websites including WordPress, Facebook, and Wikipedia! Whether youโ€™re building dynamic websites, APIs, or web applications, this guide makes PHP setup simple and powerful! ๐ŸŽฏ

๐Ÿค” Why is PHP on AlmaLinux Important?

PHP on AlmaLinux delivers incredible benefits:

  • ๐Ÿ“Œ Powers 75%+ of websites - Including WordPress, Drupal, and major platforms
  • ๐Ÿ”ง Enterprise reliability - Rock-solid performance with AlmaLinux stability
  • ๐Ÿš€ Free and open source - No licensing costs, massive community support
  • ๐Ÿ” Mature security - Built-in security features and regular updates
  • โญ Perfect integration - Works seamlessly with Apache, Nginx, and MySQL

๐ŸŽฏ What You Need

Before installing PHP on AlmaLinux:

  • โœ… AlmaLinux 9 system (server or desktop)
  • โœ… Root or sudo access
  • โœ… At least 1GB RAM (2GB+ recommended for development)
  • โœ… 3GB+ free disk space
  • โœ… Web server installed (Apache or Nginx - optional but recommended)

๐Ÿ“ Step 1: Install PHP and Essential Modules

Letโ€™s get the latest PHP version installed! ๐Ÿ› ๏ธ

Install PHP from Default Repository

# Update system packages first
sudo dnf update -y

# Install PHP 8+ and common modules
sudo dnf install -y php php-cli php-fpm php-common

# Install essential PHP extensions
sudo dnf install -y php-mysqlnd php-pdo php-gd php-mbstring php-curl \
                    php-xml php-zip php-json php-opcache php-intl

# Install additional useful modules
sudo dnf install -y php-ldap php-soap php-bcmath php-xmlrpc php-tidy

# Verify PHP installation
php --version
# PHP 8.0.30 (cli) (built: Aug  3 2023 17:31:55)

# Check installed PHP modules
php -m

# Display PHP configuration info
php --ini

echo "โœ… PHP and essential modules installed successfully!"

Install PHP from Remi Repository (Latest Version)

# Install EPEL repository (required for Remi)
sudo dnf install -y epel-release

# Install Remi repository
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm

# List available PHP versions
sudo dnf module list php

# Install PHP 8.3 (latest) from Remi
sudo dnf module enable php:remi-8.3 -y
sudo dnf install -y php php-cli php-fpm php-common

# Install essential modules for PHP 8.3
sudo dnf install -y php-mysqlnd php-pdo php-gd php-mbstring php-curl \
                    php-xml php-zip php-json php-opcache php-intl \
                    php-ldap php-soap php-bcmath php-redis

# Verify latest PHP version
php --version

echo "โœ… Latest PHP 8.3 installed from Remi repository!"

๐Ÿ”ง Step 2: Configure PHP with Apache Web Server

Integrate PHP with Apache for dynamic web content:

Configure Apache for PHP

# Install Apache if not already installed
sudo dnf install -y httpd

# Install PHP Apache module (mod_php)
sudo dnf install -y php-apache

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

# Create PHP info page for testing
sudo tee /var/www/html/info.php << 'EOF'
<?php
// PHP Information Page - Remove after testing!
echo "<h1>๐Ÿ˜ PHP on AlmaLinux Server</h1>";
echo "<p><strong>PHP Version:</strong> " . phpversion() . "</p>";
echo "<p><strong>Server:</strong> " . $_SERVER['SERVER_SOFTWARE'] . "</p>";
echo "<p><strong>Document Root:</strong> " . $_SERVER['DOCUMENT_ROOT'] . "</p>";

// Display PHP configuration
phpinfo();
?>
EOF

# Start and enable Apache
sudo systemctl start httpd
sudo systemctl enable httpd

# Restart Apache to load PHP
sudo systemctl restart httpd

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

echo "โœ… PHP integrated with Apache successfully!"
echo "Visit: http://your-server-ip/info.php to see PHP info"
# Install and configure PHP-FPM
sudo systemctl start php-fpm
sudo systemctl enable php-fpm

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

# Configure Apache to use PHP-FPM
sudo tee /etc/httpd/conf.d/php-fpm.conf << 'EOF'
# PHP-FPM Configuration for Apache

# Load required modules
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# Configure PHP-FPM
<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>

# Performance settings
<IfModule mod_proxy_fcgi.c>
    ProxyTimeout 300
</IfModule>
EOF

# Configure PHP-FPM pool
sudo tee /etc/php-fpm.d/www.conf << 'EOF'
[www]
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.owner = apache
listen.group = apache
listen.mode = 0660

# Process management
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.process_idle_timeout = 10s

# Security
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
EOF

# Restart services
sudo systemctl restart php-fpm
sudo systemctl restart httpd

# Test PHP-FPM
curl http://localhost/info.php | grep -i fpm

echo "โœ… PHP-FPM configured for better performance!"

๐ŸŒŸ Step 3: Configure PHP Settings for Development

Optimize PHP configuration for development and production:

Configure php.ini for Development

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

# Configure PHP for development
sudo tee -a /etc/php.d/99-development.ini << 'EOF'
; Development PHP Configuration

; Error reporting and logging
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
error_log = /var/log/php_errors.log

; Memory and execution limits
memory_limit = 256M
max_execution_time = 300
max_input_time = 300

; File upload settings
file_uploads = On
upload_max_filesize = 64M
max_file_uploads = 20
post_max_size = 64M

; Session configuration
session.cookie_httponly = 1
session.cookie_secure = 0
session.use_strict_mode = 1
session.cookie_samesite = "Strict"

; Date and timezone
date.timezone = "America/New_York"

; Security settings
expose_php = Off
allow_url_fopen = Off
allow_url_include = Off

; Performance
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 2
opcache.fast_shutdown = 1
EOF

# Set proper permissions on log file
sudo touch /var/log/php_errors.log
sudo chown apache:apache /var/log/php_errors.log

# Restart services to apply changes
sudo systemctl restart php-fpm
sudo systemctl restart httpd

# Verify configuration
php -i | grep memory_limit
php -i | grep upload_max_filesize

echo "โœ… PHP configured for development environment!"

Create Production-Ready Configuration

# Configure PHP for production
sudo tee /etc/php.d/99-production.ini << 'EOF'
; Production PHP Configuration

; Error handling (hide errors from users)
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php_errors.log

; Performance settings
memory_limit = 512M
max_execution_time = 120
max_input_time = 120
realpath_cache_size = 4096K
realpath_cache_ttl = 600

; File uploads
file_uploads = On
upload_max_filesize = 10M
max_file_uploads = 20
post_max_size = 16M

; Security hardening
expose_php = Off
allow_url_fopen = Off
allow_url_include = Off
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

; Session security
session.cookie_httponly = 1
session.cookie_secure = 1
session.use_strict_mode = 1
session.cookie_samesite = "Strict"
session.name = PHPSESSID_CUSTOM

; OPcache optimization
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 0
opcache.validate_timestamps = 0
opcache.save_comments = 0
opcache.fast_shutdown = 1
EOF

# Note: Use this for production, comment out development config
echo "โš ๏ธ  Production config created - switch by renaming files"
echo "Development: /etc/php.d/99-development.ini"
echo "Production: /etc/php.d/99-production.ini"

โœ… Step 4: Install Composer and Database Support

Set up essential PHP development tools:

Install Composer (PHP Package Manager)

# Download and install Composer
cd /tmp
curl -sS https://getcomposer.org/installer | php

# Move Composer to global location
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

# Verify Composer installation
composer --version
# Composer version 2.6.5

# Create a sample project directory
mkdir -p ~/php-projects/sample-app
cd ~/php-projects/sample-app

# Initialize a new Composer project
composer init --name="myproject/sample-app" --description="Sample PHP application" --author="Your Name <[email protected]>" --no-interaction

# Install popular packages for demonstration
composer require monolog/monolog
composer require vlucas/phpdotenv
composer require guzzlehttp/guzzle

# Create sample PHP script using Composer autoloader
tee index.php << 'EOF'
<?php
// Sample PHP application with Composer
require_once 'vendor/autoload.php';

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// Create logger
$log = new Logger('sample-app');
$log->pushHandler(new StreamHandler('app.log', Logger::WARNING));

// Log a message
$log->warning('This is a sample PHP application on AlmaLinux!');

echo "<h1>๐Ÿ˜ PHP Application on AlmaLinux</h1>";
echo "<p>Composer packages loaded successfully!</p>";
echo "<p>Check app.log for logged messages.</p>";
echo "<p>PHP Version: " . phpversion() . "</p>";
?>
EOF

echo "โœ… Composer installed and sample project created!"

Configure Database Connectivity

# Install MySQL/MariaDB if not already installed
sudo dnf install -y mariadb-server mariadb

# Start and enable MariaDB
sudo systemctl start mariadb
sudo systemctl enable mariadb

# Secure MariaDB installation
sudo mysql_secure_installation

# Create database and user for testing
sudo mysql -u root -p << 'EOF'
CREATE DATABASE php_test_db;
CREATE USER 'php_user'@'localhost' IDENTIFIED BY 'SecurePassword123!';
GRANT ALL PRIVILEGES ON php_test_db.* TO 'php_user'@'localhost';
FLUSH PRIVILEGES;

USE php_test_db;
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]');

SELECT * FROM users;
EXIT;
EOF

# Create PHP database connection test
tee database-test.php << 'EOF'
<?php
// PHP Database Connection Test
$servername = "localhost";
$username = "php_user";
$password = "SecurePassword123!";
$dbname = "php_test_db";

try {
    // Create PDO connection
    $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "<h2>โœ… Database Connection Successful!</h2>";
    
    // Fetch users from database
    $stmt = $pdo->query("SELECT * FROM users");
    $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<h3>Users in Database:</h3>";
    echo "<ul>";
    foreach ($users as $user) {
        echo "<li>{$user['name']} ({$user['email']}) - Created: {$user['created_at']}</li>";
    }
    echo "</ul>";
    
} catch(PDOException $e) {
    echo "<h2>โŒ Connection failed: " . $e->getMessage() . "</h2>";
}
?>
EOF

echo "โœ… Database connectivity configured and tested!"

๐ŸŽฎ Quick Examples

Example 1: Complete LAMP Stack Development Environment ๐Ÿ’ป

# Set up complete LAMP development environment
echo "=== LAMP Stack Development Setup ==="

# Create development workspace
mkdir -p ~/lamp-development/projects
cd ~/lamp-development/projects

# Create sample web application
mkdir sample-webapp
cd sample-webapp

# Create application structure
mkdir -p {public,src,config,logs}

# Create main application file
tee public/index.php << 'EOF'
<?php
// Sample LAMP Application
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LAMP Development on AlmaLinux</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; background: #f8f9fa; }
        .container { max-width: 800px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
        .info-box { background: #e3f2fd; padding: 15px; border-radius: 5px; margin: 15px 0; }
        .success { background: #e8f5e8; border-left: 4px solid #4caf50; }
        .warning { background: #fff3e0; border-left: 4px solid #ff9800; }
    </style>
</head>
<body>
    <div class="container">
        <h1>๐Ÿš€ LAMP Stack on AlmaLinux</h1>
        <p>Congratulations! Your LAMP development environment is working perfectly.</p>
        
        <div class="info-box success">
            <h3>Environment Information</h3>
            <ul>
                <li><strong>OS:</strong> <?= php_uname('s') . ' ' . php_uname('r') ?></li>
                <li><strong>Web Server:</strong> <?= $_SERVER['SERVER_SOFTWARE'] ?></li>
                <li><strong>PHP Version:</strong> <?= phpversion() ?></li>
                <li><strong>Server Time:</strong> <?= date('Y-m-d H:i:s') ?></li>
            </ul>
        </div>
        
        <div class="info-box warning">
            <h3>๐Ÿ”ง Development Features</h3>
            <ul>
                <li>โœ… Apache Web Server Running</li>
                <li>โœ… PHP <?= phpversion() ?> Active</li>
                <li>โœ… Database Extensions Loaded</li>
                <li>โœ… Session Support Enabled</li>
                <li>โœ… File Upload Support</li>
            </ul>
        </div>
        
        <p><strong>Document Root:</strong> <?= $_SERVER['DOCUMENT_ROOT'] ?></p>
        <p>Ready for PHP development on AlmaLinux! ๐ŸŽ‰</p>
    </div>
</body>
</html>
EOF

# Create virtual host for development
sudo tee /etc/httpd/sites-available/lamp-dev.conf << 'EOF'
<VirtualHost *:80>
    ServerName lamp-dev.local
    DocumentRoot /home/$USER/lamp-development/projects/sample-webapp/public
    
    <Directory /home/$USER/lamp-development/projects/sample-webapp/public>
        AllowOverride All
        Require all granted
        Options Indexes FollowSymLinks
        DirectoryIndex index.php index.html
    </Directory>
    
    # PHP settings for development
    php_admin_value error_reporting "E_ALL"
    php_admin_flag display_errors On
    php_admin_value memory_limit "256M"
    
    ErrorLog /var/log/httpd/lamp-dev_error.log
    CustomLog /var/log/httpd/lamp-dev_access.log combined
</VirtualHost>
EOF

# Enable development site
sudo ln -s /etc/httpd/sites-available/lamp-dev.conf /etc/httpd/sites-enabled/
sudo systemctl restart httpd

echo "โœ… LAMP development environment ready!"
echo "Add '127.0.0.1 lamp-dev.local' to /etc/hosts"
echo "Visit: http://lamp-dev.local"

Example 2: WordPress Installation and Configuration ๐ŸŒ

# Install and configure WordPress
echo "=== WordPress Installation on LAMP Stack ==="

# Create WordPress directory
sudo mkdir -p /var/www/wordpress
cd /tmp

# Download WordPress
curl -O https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz

# Move WordPress files
sudo cp -R wordpress/* /var/www/wordpress/

# Set permissions
sudo chown -R apache:apache /var/www/wordpress
sudo chmod -R 755 /var/www/wordpress

# Create WordPress database
sudo mysql -u root -p << 'EOF'
CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'WPSecurePass2024!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
EOF

# Configure WordPress
sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

# Update WordPress configuration (basic setup)
sudo sed -i "s/database_name_here/wordpress_db/" /var/www/wordpress/wp-config.php
sudo sed -i "s/username_here/wp_user/" /var/www/wordpress/wp-config.php
sudo sed -i "s/password_here/WPSecurePass2024!/" /var/www/wordpress/wp-config.php

# Create virtual host for WordPress
sudo tee /etc/httpd/sites-available/wordpress.conf << 'EOF'
<VirtualHost *:80>
    ServerName wordpress.local
    DocumentRoot /var/www/wordpress
    
    <Directory /var/www/wordpress>
        AllowOverride All
        Require all granted
    </Directory>
    
    # WordPress PHP optimizations
    php_admin_value memory_limit "512M"
    php_admin_value max_execution_time "300"
    php_admin_value upload_max_filesize "64M"
    php_admin_value post_max_size "64M"
    
    ErrorLog /var/log/httpd/wordpress_error.log
    CustomLog /var/log/httpd/wordpress_access.log combined
</VirtualHost>
EOF

# Enable WordPress site
sudo ln -s /etc/httpd/sites-available/wordpress.conf /etc/httpd/sites-enabled/
sudo systemctl restart httpd

echo "โœ… WordPress installed and configured!"
echo "Add '127.0.0.1 wordpress.local' to /etc/hosts"
echo "Visit: http://wordpress.local to complete setup"

Example 3: PHP Performance and Security Optimization โšก

# Advanced PHP optimization and security
echo "=== PHP Performance and Security Optimization ==="

# Create optimized PHP configuration
sudo tee /etc/php.d/99-optimized.ini << 'EOF'
; Optimized PHP Configuration for Production

; Memory and execution
memory_limit = 1024M
max_execution_time = 120
max_input_time = 120
max_input_vars = 3000

; OPcache optimization
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 512
opcache.interned_strings_buffer = 64
opcache.max_accelerated_files = 32531
opcache.revalidate_freq = 0
opcache.validate_timestamps = 0
opcache.save_comments = 0
opcache.fast_shutdown = 1
opcache.enable_file_override = 1

; Realpath cache
realpath_cache_size = 4096K
realpath_cache_ttl = 600

; Security hardening
expose_php = Off
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source,file_get_contents,fopen,fread,fwrite,file_put_contents
allow_url_fopen = Off
allow_url_include = Off
enable_dl = Off

; Session security
session.use_strict_mode = 1
session.cookie_httponly = 1
session.cookie_secure = 1
session.cookie_samesite = "Strict"
session.use_only_cookies = 1
session.hash_function = sha512
session.hash_bits_per_character = 6

; File upload security
file_uploads = On
upload_max_filesize = 10M
max_file_uploads = 10
post_max_size = 16M

; Output buffering for performance
output_buffering = 4096
implicit_flush = Off

; Date settings
date.timezone = "UTC"
EOF

# Create PHP security test script
sudo tee /var/www/html/security-test.php << 'EOF'
<?php
// PHP Security and Performance Test

echo "<h1>๐Ÿ”’ PHP Security and Performance Status</h1>";

// Test disabled functions
$disabled = ini_get('disable_functions');
echo "<h3>Disabled Functions (Security):</h3>";
echo "<pre>" . ($disabled ? $disabled : "None - SECURITY RISK!") . "</pre>";

// Test OPcache
if (function_exists('opcache_get_status')) {
    $opcache = opcache_get_status();
    echo "<h3>โœ… OPcache Status:</h3>";
    echo "<p>Enabled: " . ($opcache['opcache_enabled'] ? "Yes" : "No") . "</p>";
    echo "<p>Memory Usage: " . round($opcache['memory_usage']['used_memory']/1024/1024, 2) . " MB</p>";
    echo "<p>Hit Rate: " . round($opcache['opcache_statistics']['opcache_hit_rate'], 2) . "%</p>";
} else {
    echo "<h3>โŒ OPcache: Not Available</h3>";
}

// Security settings
echo "<h3>๐Ÿ” Security Settings:</h3>";
echo "<ul>";
echo "<li>expose_php: " . (ini_get('expose_php') ? 'On (Risk)' : 'Off (Good)') . "</li>";
echo "<li>allow_url_fopen: " . (ini_get('allow_url_fopen') ? 'On (Risk)' : 'Off (Good)') . "</li>";
echo "<li>allow_url_include: " . (ini_get('allow_url_include') ? 'On (Risk)' : 'Off (Good)') . "</li>";
echo "</ul>";

// Performance settings
echo "<h3>โšก Performance Settings:</h3>";
echo "<ul>";
echo "<li>Memory Limit: " . ini_get('memory_limit') . "</li>";
echo "<li>Max Execution Time: " . ini_get('max_execution_time') . "s</li>";
echo "<li>Realpath Cache Size: " . ini_get('realpath_cache_size') . "</li>";
echo "<li>Output Buffering: " . ini_get('output_buffering') . "</li>";
echo "</ul>";

echo "<p><strong>Remove this file after testing for security!</strong></p>";
?>
EOF

# Restart PHP-FPM and Apache
sudo systemctl restart php-fpm
sudo systemctl restart httpd

echo "โœ… PHP optimized for performance and security!"
echo "Test at: http://your-server/security-test.php"
echo "โš ๏ธ  Remove test files after verification!"

๐Ÿšจ Fix Common Problems

Problem 1: PHP Not Working with Apache โŒ

Symptoms:

  • PHP files download instead of executing
  • White screen or 500 errors

Try this:

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

# Install PHP Apache module if missing
sudo dnf install -y php

# Check Apache error logs
sudo tail -f /var/log/httpd/error_log

# Verify PHP configuration
php -t

# Restart Apache
sudo systemctl restart httpd

# Test with simple PHP file
echo '<?php echo "PHP is working!"; ?>' | sudo tee /var/www/html/test.php
curl http://localhost/test.php

Problem 2: PHP Extensions Not Loading โŒ

Try this:

# Check loaded extensions
php -m

# Install missing extensions
sudo dnf search php-*

# Example: Install missing MySQL extension
sudo dnf install -y php-mysqlnd

# Check extension configuration
php --ini

# Verify specific extension
php -m | grep -i mysql

# Restart PHP-FPM if using it
sudo systemctl restart php-fpm

Problem 3: Database Connection Errors โŒ

Check these things:

# Test database connectivity
mysql -u php_user -p

# Check if MySQL/MariaDB is running
sudo systemctl status mariadb

# Verify PHP MySQL extension
php -m | grep -i mysql

# Test with simple connection script
php -r "try { new PDO('mysql:host=localhost', 'php_user', 'password'); echo 'DB OK'; } catch(Exception $e) { echo 'Error: '.$e->getMessage(); }"

# Check database user permissions
sudo mysql -u root -p -e "SHOW GRANTS FOR 'php_user'@'localhost';"

๐Ÿ“‹ Simple Commands Summary

TaskCommand
๐Ÿ”ง Install PHPsudo dnf install php
๐Ÿ“Š Check PHP versionphp --version
๐Ÿงช List PHP modulesphp -m
โš™๏ธ Check PHP configphp --ini
๐Ÿš€ Start PHP-FPMsudo systemctl start php-fpm
๐Ÿ“ View PHP errorssudo tail -f /var/log/php_errors.log
๐ŸŒ Test PHP filephp -l filename.php

๐Ÿ’ก Tips for Success

  1. Use PHP-FPM for production ๐ŸŒŸ - Better performance and security than mod_php
  2. Enable OPcache ๐Ÿ” - Massive performance boost for production sites
  3. Secure your php.ini ๐Ÿš€ - Disable dangerous functions and settings
  4. Use Composer ๐Ÿ“ - Modern PHP package management is essential
  5. Regular updates ๐Ÿ”„ - Keep PHP updated for security and performance

๐Ÿ† What You Learned

Congratulations! Now you can:

  • โœ… Install and configure PHP 8+ on AlmaLinux with all essential modules
  • โœ… Integrate PHP with Apache using both mod_php and PHP-FPM
  • โœ… Set up Composer for modern PHP package management
  • โœ… Configure database connectivity with secure practices
  • โœ… Optimize PHP for both development and production environments

๐ŸŽฏ Why This Matters

Your PHP installation on AlmaLinux provides:

  • ๐Ÿš€ Modern web development platform with PHP 8+ features and performance
  • ๐Ÿ” Secure foundation with proper security hardening and best practices
  • ๐Ÿ“Š Scalable performance optimized for high-traffic applications
  • โšก Professional toolkit with Composer and database connectivity ready

Remember: PHP powers over 75% of all websites on the internet - with proper setup and configuration, your AlmaLinux server is ready to build everything from simple blogs to complex enterprise applications! You now have a professional-grade development environment! โญ

Youโ€™ve successfully mastered PHP installation and configuration on AlmaLinux! Your server is now ready for modern web development with all the tools and optimizations needed for success! ๐Ÿ™Œ