#!/bin/bash
# Update the system
echo "Updating the system..."
sudo pacman -Syu --noconfirm
# Install Apache
echo "Installing Apache..."
sudo pacman -S apache --noconfirm
sudo systemctl start httpd
sudo systemctl enable httpd
echo "Apache installed and started."
# Install MariaDB
echo "Installing MariaDB..."
sudo pacman -S mariadb --noconfirm
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl start mariadb
sudo systemctl enable mariadb
echo "MariaDB installed and started."
# Secure MariaDB
echo "Securing MariaDB..."
sudo mysql_secure_installation
# Install PHP
echo "Installing PHP..."
sudo pacman -S php php-apache --noconfirm
# Configure Apache for PHP
echo "Configuring Apache to work with PHP..."
sudo sed -i '/#LoadModule php_module/s/^#//' /etc/httpd/conf/httpd.conf
sudo sed -i '/<IfModule dir_module>/a\
AddHandler php-script .php\
Include conf/extra/php_module.conf' /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
echo "PHP installed and configured with Apache."
# Create a test PHP file
echo "Creating a test PHP file..."
echo "<?php phpinfo(); ?>" | sudo tee /srv/http/test.php
echo "Visit http://localhost/test.php to confirm PHP is working."
# Install phpMyAdmin (Optional)
read -p "Do you want to install phpMyAdmin? (y/n): " install_pma
if [[ "$install_pma" == "y" || "$install_pma" == "Y" ]]; then
echo "Installing phpMyAdmin..."
sudo pacman -S phpmyadmin --noconfirm
echo "phpMyAdmin installed. Configure Apache if necessary."
fi
# Allow HTTP/HTTPS traffic in the firewall (Optional)
read -p "Do you want to configure the firewall for HTTP and HTTPS? (y/n): " configure_firewall
if [[ "$configure_firewall" == "y" || "$configure_firewall" == "Y" ]]; then
echo "Allowing HTTP and HTTPS traffic in the firewall..."
sudo ufw allow 80
sudo ufw allow 443
echo "Firewall rules updated."
fi
echo "LAMP stack installation completed!"
Install LAMP Stack on Endeavour OS