By default we compile the source code to install Apache, it is not possible to use the service this command to start, usually we start the command is:
[[email protected] httpd-2.2.16]#/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/in the Apachectl is actually a startup script, we copy him to/etc/init.d/, and renamed to Apache2 (this name casually, you can easily do)
[Email protected] httpd-2.2.16]# cp/usr/local/apache2/bin/apachectl/etc/init.d/apache2
Then modify 2 places to let him support service and Chkconfig commands
[Email protected] httpd-2.2.16]# vim/etc/init.d/apache2
Add these 2 lines anywhere in the previous large comment:
# chkconfig:35 20 80
# Description:apache2
The 3 numbers that follow the first line are the following: the operating level at which you start Apache (3,5), the start Sequence number (S20), and the close ordinal (K80).
3 and 5 means that Apache is started by default at the third boot level and the fifth boot level
20 refers to the system up when there are a lot of services need to start, and this program is ranked in the 20th bit start, and so on
80 means that when the system shuts down, the order of service is closed in 80th place.
Note: These 2 lines are indispensable, #号不能省略, must have
Then save the exit so we can start and close Apache with the service
Like what:
[[Email protected] httpd-2.2.16]# service apache2 start
[Email protected] httpd-2.2.16]# NETSTAT-ANTP |grep 80
TCP 0 0::: +:::* LISTEN 13410/httpd
If you want Apache to follow the system to boot, that is, boot from the boot, then add to Chkconfig can
[Email protected] httpd-2.2.16]# Chkconfig–add apache2
[Email protected] httpd-2.2.16]# chkconfig apache2 on
Apache Boot script settings