# service < name_of_script > < option >
For example, you can use service
with httpd
and any option discussed in the previous section, like so:
# service httpd restart
This restarts Apache if it's running or starts the server if it isn't running.
Controlling Apache with Fedora's chkconfig
Command
The chkconfig
command provides a command-line-based interface to Fedora's service scripts. The command can be used to list and control which software services are started, restarted, and stopped for a specific system state (such as when booting up, restarting, or shutting down) and runlevel (such as single-user mode, networking with multitasking, or graphical login with X).
For example, to view your system's current settings, take a look at Fedora's default runlevel as defined in the system initialization table /etc/inittab
using the grep
command:
# grep id: /etc/inittab
id:3:initdefault:
This example shows that this Fedora system boots to a text-based login without running X11. You can then use the chkconfig
command to look at the behavior of Apache for that runlevel:
# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Here you can see that Apache is turned off for runlevels 3 and 5 (the only two practical runlevels in a default Fedora system, although you could create a custom runlevel 4 for Apache). Use --level
, httpd
, and the control keyword on
to set Apache to automatically start when booting to runlevel 3:
# chkconfig --level 3 httpd on
You can then again use chkconfig
to verify this setting:
# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
To have Apache also start when your system is booted to a graphical login, again use level, httpd
, and the control keyword on
, but this time, specify runlevel 5 like so:
# chkconfig --level 5 httpd on
Again, to verify your system settings, use the following:
# chkconfig --list | grep httpd
httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Use the off
keyword to stop Apache from starting at a particular runlevel.
Graphic Interface Configuration of Apache
Some of Apache's basic behavior can be configured with Red Hat's system-config-httpd
, a GUI tool for the X Window System. This is an easy way to configure settings, such as Apache's user and group name, the location of PID and process lock files, or performance settings (such as the maximum number of connections), without manually editing configuration files.
CAUTION
If you use system-config-httpd
, you shouldn't try to manually edit the httpd.conf
file. Manual changes are overwritten by the GUI client if you again use system-config-httpd
!
Launch this client by using your X desktop panel's Server Settings' HTTP Server menu item or from the command line of an X terminal window, like this:
$ system-config-httpd &
After you press Enter, you're asked to type the root
password. You then see the main client window shown in Figure 17.1.
FIGURE 17.1 The system-config-httpd main dialog box provides access to basic configuration of the Apache web server.
In the Main tab, you can set the server name, indicate where to send email addressed to the webmaster, and set the port that Apache uses. If you want, you can also configure specific virtual hosts to listen on different ports.
Configuring Virtual Host Properties
In the Virtual Hosts tab, you can configure the properties of each virtual host. The Name list box contains a list of all virtual hosts operating in Apache. Edit a virtual host by opening the Virtual Hosts Properties dialog box, shown in Figure 17.2. You do this by highlighting the name of a virtual host in the Name list box of the Virtual Hosts tab and clicking the Edit button at the right of the tab. Use the General Options item in the Virtual Hosts Properties dialog box to configure basic virtual host settings.
FIGURE 17.2 system-config-httpd
's Virtual Host Properties dialog box gives you access to numerous options for configuring the properties of an Apache virtual host.
Click the Site Configuration listing in the General Options list of this dialog box to set defaults, such as which files are loaded by default when no files are specified (the default is index.*
) in the URL.
The SSL listing in the General Options pane gives you access to settings used to enable or disable SSL, specify certificate settings, and define the SSL log filename and location. Select the Logging listing to access options for configuring where the error messages are logged, as well as where the transfer log file is kept and how much information is put in it.
Use the Environment Variables options to configure settings for the env_mod
module, used to pass environment directives to CGI programs. The Directories section configures the directory options (such as whether CGI programs are allowed to run) as well as the order entries mentioned in the httpd.conf
section.
The Server tab, shown in Figure 17.3, enables you to configure things such as where the lock file and the PID file are kept. In both cases, you should use the defaults. You can also configure the directory where any potential core dumps will be placed.
FIGURE 17.3 system-config-httpd's Server configuration tab.
Finally, you can set which user and group Apache is to run as. As mentioned in a previous note, for security reasons, you should run Apache as the user named apache and as a member of the group apache.
Configuring Apache for Peak Performance
Use the options in the Performance Tuning tab to configure Apache to provide peak performance in your system. Options in this tab set the maximum number of connections, connection timeouts, and number of requests per connection. When setting this number, keep in mind that for each connection to your server, another instance of the httpd
program might be run, depending on how Apache is built. Each instance takes resources such as CPU time and memory. You can also configure details about each connection such as how long, in seconds, before a connection times out and how many requests each connection can make to the server. More tips on tuning Apache can be found in Chapter 31, "Performance Tuning."
Runtime Server Configuration Settings
At this point, the Apache server runs, but perhaps you want to change a behavior, such as the default location of your website's files. This section talks about the basics of configuring the server to work the way you want it to work.
Runtime configurations are stored in just one file — httpd.conf
, which is found under the /etc/httpd/conf
directory. This configuration file can be used to control the default behavior of Apache, such as the web server's base configuration directory ( /etc/httpd
), the name of the server's process identification (PID) file ( /etc/httpd/run/httpd.pid
), or its response timeout (300 seconds). Apache reads the data from the configuration file when started (or restarted). You can also cause Apache to reload configuration information with the command /etc/rc.d/init.d/httpd reload
, which is necessary after making changes to its configuration file. (You learned how to accomplish this in the earlier section, "Starting and Stopping Apache.")
Читать дальше