How to Make Apache HTTPD Service Start Automatically on Server Reboot and Startup?
Last Updated :
20 Jun, 2024
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
Similar Reads
How to Automatically Redirect HTTP to HTTPS on Apache Servers? The Apache server or Apache HTTP servers are an open source web server software which was developed by Apache Software Foundation in the year 1995, it was released under the license of Apache License 2.0 they are the servers that are used for accepting various HTTP directories requests from the user
8 min read
How to install and configure Apache Web Server on Godaddy Server? GoDaddy VPS is a shared server that provides computational services, databases, storage space, automated weekly backups, 99% uptime, and much more. Itâs a cheaper alternative to some other popular cloud-based services such as AWS, GPC, and Azure. Apache HTTP Server is an open-source web server softw
2 min read
How to Control Systemd Services on Remote Linux Server Linux, SysV, and LSB init scripts are compatible with Systemd, a system and service manager. Aggressive parallelization capabilities are offered by Systemd, which also offers on-demand daemon starting and uses Linux cgroups to keep track of processes. Systemd also supports system snapshotting and re
2 min read
How to Start, Stop, or Restart Apache Server on Ubuntu? Apache is a popular software used to run websites on the internet. Many websites, online applications, and AI programs use Apache. Apache is popular because it works well with other software and can handle a lot of users visiting the website at the same time. For people running Apache on Ubuntu comp
3 min read
How to Host Apache HTTP Server on Microsoft Windows? Apache HTTP Server, commonly known as Apache, is a widely used, powerful, and secure web server it is an ideal choice for hosting web applications. Popular deployment options include Apache Lounge, Bitnami WAMP Stack, WampServer, and XAMPP. Each option has its advantages and disadvantages, but in th
3 min read
How to Install Apache Web Server on Linux Cloud Server? Apache is an open-source web server used widely for hosting websites and web applications. It's popular on the internet and supports platforms like Linux, Windows, and macOS. Installing Apache on a Linux-based cloud server is straightforward. Cloud servers offer flexibility and scalability, enabling
5 min read