Ravindra BagaleCourses & study guides

Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)

7.11 Combination 6 — CentOS Stream 9 + Apache

sudo service nginx stop 2>/dev/null
sudo systemctl disable nginx 2>/dev/null
sudo yum install -y httpd
sudo service httpd start
sudo systemctl enable httpd

sudo tee /etc/httpd/conf.d/mysite.conf > /dev/null <<'EOF'
<VirtualHost *:80>
    ServerName mysite.local
    DocumentRoot /var/www/mysite
    <Directory /var/www/mysite>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorDocument 404 /404.html
    ErrorLog  /var/log/httpd/mysite_error.log
    CustomLog /var/log/httpd/mysite_access.log combined
</VirtualHost>
EOF

sudo restorecon -Rv /var/www/mysite
if systemctl is-active --quiet firewalld; then
  sudo firewall-cmd --permanent --add-service=http --add-service=https
  sudo firewall-cmd --reload
fi
sudo apachectl configtest && sudo service httpd reload
curl -s http://localhost | head -5