Horje
How to Make Apache HTTPD Service Start Automatically on Server Reboot and Startup?

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:

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
sudo systemctl status apache2 # For Ubuntu/Debian

2. Enable Apache to start on boot:

sudo systemctl enable httpd  # For CentOS/RHEL
sudo systemctl enable apache2 # For Ubuntu/Debian

3. Start the Apache service immediately (if not already running):

sudo systemctl start httpd  # For CentOS/RHEL
sudo systemctl start apache2 # For Ubuntu/Debian

4. Verify the service is enabled and running:

sudo systemctl is-enabled httpd  # For CentOS/RHEL
sudo systemctl is-enabled apache2 # For Ubuntu/Debian
sudo systemctl status httpd # For CentOS/RHEL
sudo systemctl status apache2 # For Ubuntu/Debian

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
sudo service apache2 status # For Ubuntu/Debian

2. Enable Apache to start on boot:

sudo chkconfig httpd on  # For CentOS/RHEL
sudo update-rc.d apache2 defaults # For Ubuntu/Debian

3. Start the Apache service immediately (if not already running):

sudo service httpd start  # For CentOS/RHEL
sudo service apache2 start # For Ubuntu/Debian

4. Verify the service is enabled and running:

sudo chkconfig --list httpd  # For CentOS/RHEL
sudo service httpd status # For CentOS/RHEL
sudo service apache2 status # For Ubuntu/Debian

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
/usr/sbin/service httpd start
# For Ubuntu/Debian
/usr/sbin/service apache2 start

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
sudo systemctl status apache2 # For Ubuntu/Debian

Using Crontab @reboot

The 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
@reboot /usr/sbin/service apache2 start # For Ubuntu/Debian

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
sudo systemctl status apache2 # For Ubuntu/Debian



Reffered: https://www.geeksforgeeks.org


Web Technologies

Related
How to Hide Apache Server Signatures? How to Hide Apache Server Signatures?
How to Add Menu in WordPress? How to Add Menu in WordPress?
How to Enable or Disable Apache Modules? How to Enable or Disable Apache Modules?
How to Change Author in WordPress Post? How to Change Author in WordPress Post?
How To Make Your WordPress Site Mobile Friendly? How To Make Your WordPress Site Mobile Friendly?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14