![]() |
Ensuring that the Apache HTTPD service starts automatically on server reboot and startup is crucial for maintaining the availability and reliability of your web applications. This process involves configuring your server so that the Apache web server launches without manual intervention every time the system reboots. This article provides a comprehensive guide on achieving this goal using various methods, applicable to different Linux distributions. These are the following approaches to Make Apache HTTPD Service Start Automatically on Server Reboot and Startup: Table of Content Using Systemd (For systems with systemd)Most modern Linux distributions, including Ubuntu 16.04 and later, CentOS 7 and later, use systemd for service management. Here are the steps to enable Apache HTTPD to start automatically using systemd. 1. Check if Apache is installed and running: sudo systemctl status httpd # For CentOS/RHEL 2. Enable Apache to start on boot: sudo systemctl enable httpd # For CentOS/RHEL 3. Start the Apache service immediately (if not already running): sudo systemctl start httpd # For CentOS/RHEL 4. Verify the service is enabled and running: sudo systemctl is-enabled httpd # For CentOS/RHEL Using init.d Scripts (For systems with init)Older Linux distributions, such as CentOS 6 or Ubuntu 14.04, use the init system. Here’s how to configure Apache HTTPD to start automatically on boot using init.d scripts. 1. Check if Apache is installed and running: sudo service httpd status # For CentOS/RHEL 2. Enable Apache to start on boot: sudo chkconfig httpd on # For CentOS/RHEL 3. Start the Apache service immediately (if not already running): sudo service httpd start # For CentOS/RHEL 4. Verify the service is enabled and running: sudo chkconfig --list httpd # For CentOS/RHEL Using rc.local File (For older or specific setups)The /etc/rc.local file can be used to execute commands at the end of the multi-user runlevel. This method can be used for older or specific setups where the other methods are not applicable. 1. Edit the rc.local file: sudo nano /etc/rc.local
2. Add the command to start Apache at the end of the file: # For CentOS/RHEL 3. Make sure the rc.local file is executable: sudo chmod +x /etc/rc.local
4. Reboot the system and verify: sudo reboot
5. After reboot, check if Apache is running: sudo systemctl status httpd # For CentOS/RHEL Using Crontab @rebootThe cron daemon can schedule tasks to run at boot time using the @reboot directive. This method works on any Linux system with cron installed. 1. Open the crontab file for editing: sudo crontab -e
2. Add a line to start Apache at reboot: @reboot /usr/sbin/service httpd start # For CentOS/RHEL 3. Save and exit the editor (usually CTRL+X, then Y, then ENTER for nano). 4. Reboot the system and verify: sudo reboot
5. After reboot, check if Apache is running: sudo systemctl status httpd # For CentOS/RHEL |
Reffered: https://www.geeksforgeeks.org
Web Technologies |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |