UnixServerAdmin

Server Administration & Management

How to Restart Apache/Httpd

If you have made changes to the Apache configuration file httpd.conf or one of the other included configuration files such as the vhosts.d files, you need to reload/restart the Apache service for the changes to take effect. From the command line you do this with the apachectl command. The exact location of this command varies on the Unix or Linux variant you are using (eg Fedora, OSX, FreeBSD, Slackware, Mandrake, SUSE) and the compile time settings, but typically it is accesible at /usr/sbin/apachectl

Gracefully restarting Apache

# /usr/sbin/apachectl graceful “OR”

# /etc/init.d/httpd graceful

If Apache is not already running it will be started. If it is already running then it will reload with the new changes but will not abort active connections, meaning that anyone who is in the middle of downloading something will continue to be able to download it.

Running a configuration test first

Before restarting the Apache service a check will be done on the configuration files to ensure they are valid. If there is an error in them the error will be displayed and the Apache service will continue running using the old settings. You need to correct your settings before attempting to restart again.

You can also just check the settings without restarting Apache like so:

#  /usr/sbin/apachectl configtest “OR”

# /etc/init.d/httpd configtest

This will check the httpd.conf file and report whether the syntax of the file is valid or not. A list of errors will be displayed including the line numbers if there are any. This makes it easy to isolate any problems.

Available options for the apachectl command

The following are all the available options that can be passed to the apachectl command. This text is from the apachectl man page.

apachectl start: Start the Apache daemon. Gives an error if it is already running.

apachectl stop: Stops the Apache daemon.

apachectl restart: Restarts the Apache daemon by sending it a SIGHUP. If the daemon is not running, it is started. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn’t die.

fullstatus: Displays a full status report from mod_status. For this to work, you need to have mod_status enabled on your server and a text-based browser such as lynx available on your system. The URL used to access the status report can be set by editing the STATUSURL variable in the script.

apachectl status: Displays a brief status report. Similar to the fullstatus option, except that the list of requests currently being served is omitted.

apachectl graceful: Gracefully restarts the Apache daemon by sending it a SIGUSR1. If the daemon is not running, it is started. This differs from a normal restart in that currently open connections are not aborted. A side effect is that old log files will not be closed immediately. This means that if used in a log rotation script, a substantial delay may be necessary to ensure that the old log files are closed before processing them. This command automatically checks the configuration files via configtest before initiating the restart to make sure Apache doesn’t die.

apachectl configtest: Run a configuration file syntax test. It parses the configuration files and either reports Syntax Ok or detailed information about the particular syntax error.

apachectl help: Displays a short help message.

Advertisements

February 20, 2011 - Posted by | Apache, Tips & Tricks | , ,

1 Comment »

  1. yeah nice

    Comment by kyle | March 4, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: