To install LAMP (Linux, Apache, MySQL/MariaDB, PHP) on CentOS 9 Stream, follow these steps:

 

Step 1: Update System Packages

Ensure your system is up to date:

sudo dnf update -y

 

Step 2: Install Apache (httpd)

sudo dnf install httpd -y

 

Start and enable Apache:

sudo systemctl start httpd

sudo systemctl enable httpd

 

Verify Apache is running:

sudo systemctl status httpd

 

Allow HTTP and HTTPS traffic in the firewall:

sudo firewall-cmd --permanent --add-service=http

sudo firewall-cmd --permanent --add-service=https

sudo firewall-cmd --reload

 

Step 3: Install MariaDB (MySQL alternative)

sudo dnf install mariadb-server -y

 

Start and enable MariaDB:

sudo systemctl start mariadb

sudo systemctl enable mariadb

 

Secure your MariaDB installation:

sudo mysql_secure_installation

 

Follow the prompts to set a root password and secure the database.

 

Step 4: Install PHP

sudo dnf install php php-mysqlnd php-cli php-common php-opcache php-gd php-curl php-mbstring -y

 

Restart Apache to apply changes:

sudo systemctl restart httpd

 

Step 5: Test PHP

Create a test PHP file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

 

Open your web browser and visit:

http://your-server-ip/info.php

 

If PHP info is displayed, PHP is working correctly.

 

Step 6: Adjust SELinux (If Necessary)

If your website faces permission issues, run:

sudo setsebool -P httpd_can_network_connect on

 

Step 7: Enable Services on Boot

sudo systemctl enable httpd

sudo systemctl enable mariadb

 

Step 8: Remove the Test PHP File (for security)

sudo rm -f /var/www/html/info.php

 

Your LAMP stack is now ready on CentOS 9 Stream!

Was this answer helpful? 58 Users Found This Useful (230 Votes)