Red Hat Certified System Administrator RHCSA · Free Practice Question Medium
Question 14
Create a Bash script that configures the Apache web server (httpd) to start automatically upon system boot in Red Hat Enterprise Linux 9. Your script should ensure that Apache is properly enabled to initiate during the boot process.
Show model answer
In RHEL 9, use the systemctl command to enable Apache to start at boot. The script should be as follows:
- #!/bin/bash
- # Check if Apache is installed
- if ! rpm -q httpd >/dev/null 2>&1; then
- echo "Apache is not installed."
- exit 1
- fi
- # Enable Apache to start on boot
- sudo systemctl enable httpd
- # Optional: Start Apache immediately
- # sudo systemctl start httpd
This script first checks if Apache (httpd) is installed. If installed, it uses systemctl enable to configure Apache to start automatically at boot. Optionally, it can also start Apache immediately.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
